OLD | NEW |
1 /* | 1 /* |
2 ** 2001 September 15 | 2 ** 2001 September 15 |
3 ** | 3 ** |
4 ** The author disclaims copyright to this source code. In place of | 4 ** The author disclaims copyright to this source code. In place of |
5 ** a legal notice, here is a blessing: | 5 ** a legal notice, here is a blessing: |
6 ** | 6 ** |
7 ** May you do good and not evil. | 7 ** May you do good and not evil. |
8 ** May you find forgiveness for yourself and forgive others. | 8 ** May you find forgiveness for yourself and forgive others. |
9 ** May you share freely, never taking more than you give. | 9 ** May you share freely, never taking more than you give. |
10 ** | 10 ** |
(...skipping 20 matching lines...) Expand all Loading... |
31 sqlite3 *db, /* The database on which the SQL executes */ | 31 sqlite3 *db, /* The database on which the SQL executes */ |
32 const char *zSql, /* The SQL to be executed */ | 32 const char *zSql, /* The SQL to be executed */ |
33 sqlite3_callback xCallback, /* Invoke this callback routine */ | 33 sqlite3_callback xCallback, /* Invoke this callback routine */ |
34 void *pArg, /* First argument to xCallback() */ | 34 void *pArg, /* First argument to xCallback() */ |
35 char **pzErrMsg /* Write error messages here */ | 35 char **pzErrMsg /* Write error messages here */ |
36 ){ | 36 ){ |
37 int rc = SQLITE_OK; /* Return code */ | 37 int rc = SQLITE_OK; /* Return code */ |
38 const char *zLeftover; /* Tail of unprocessed SQL */ | 38 const char *zLeftover; /* Tail of unprocessed SQL */ |
39 sqlite3_stmt *pStmt = 0; /* The current SQL statement */ | 39 sqlite3_stmt *pStmt = 0; /* The current SQL statement */ |
40 char **azCols = 0; /* Names of result columns */ | 40 char **azCols = 0; /* Names of result columns */ |
41 int nRetry = 0; /* Number of retry attempts */ | |
42 int callbackIsInit; /* True if callback data is initialized */ | 41 int callbackIsInit; /* True if callback data is initialized */ |
43 | 42 |
44 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; | 43 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; |
45 if( zSql==0 ) zSql = ""; | 44 if( zSql==0 ) zSql = ""; |
46 | 45 |
47 sqlite3_mutex_enter(db->mutex); | 46 sqlite3_mutex_enter(db->mutex); |
48 sqlite3Error(db, SQLITE_OK, 0); | 47 sqlite3Error(db, SQLITE_OK); |
49 while( (rc==SQLITE_OK || (rc==SQLITE_SCHEMA && (++nRetry)<2)) && zSql[0] ){ | 48 while( rc==SQLITE_OK && zSql[0] ){ |
50 int nCol; | 49 int nCol; |
51 char **azVals = 0; | 50 char **azVals = 0; |
52 | 51 |
53 pStmt = 0; | 52 pStmt = 0; |
54 rc = sqlite3_prepare(db, zSql, -1, &pStmt, &zLeftover); | 53 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover); |
55 assert( rc==SQLITE_OK || pStmt==0 ); | 54 assert( rc==SQLITE_OK || pStmt==0 ); |
56 if( rc!=SQLITE_OK ){ | 55 if( rc!=SQLITE_OK ){ |
57 continue; | 56 continue; |
58 } | 57 } |
59 if( !pStmt ){ | 58 if( !pStmt ){ |
60 /* this happens for a comment or white-space */ | 59 /* this happens for a comment or white-space */ |
61 zSql = zLeftover; | 60 zSql = zLeftover; |
62 continue; | 61 continue; |
63 } | 62 } |
64 | 63 |
(...skipping 25 matching lines...) Expand all Loading... |
90 azVals = &azCols[nCol]; | 89 azVals = &azCols[nCol]; |
91 for(i=0; i<nCol; i++){ | 90 for(i=0; i<nCol; i++){ |
92 azVals[i] = (char *)sqlite3_column_text(pStmt, i); | 91 azVals[i] = (char *)sqlite3_column_text(pStmt, i); |
93 if( !azVals[i] && sqlite3_column_type(pStmt, i)!=SQLITE_NULL ){ | 92 if( !azVals[i] && sqlite3_column_type(pStmt, i)!=SQLITE_NULL ){ |
94 db->mallocFailed = 1; | 93 db->mallocFailed = 1; |
95 goto exec_out; | 94 goto exec_out; |
96 } | 95 } |
97 } | 96 } |
98 } | 97 } |
99 if( xCallback(pArg, nCol, azVals, azCols) ){ | 98 if( xCallback(pArg, nCol, azVals, azCols) ){ |
| 99 /* EVIDENCE-OF: R-38229-40159 If the callback function to |
| 100 ** sqlite3_exec() returns non-zero, then sqlite3_exec() will |
| 101 ** return SQLITE_ABORT. */ |
100 rc = SQLITE_ABORT; | 102 rc = SQLITE_ABORT; |
101 sqlite3VdbeFinalize((Vdbe *)pStmt); | 103 sqlite3VdbeFinalize((Vdbe *)pStmt); |
102 pStmt = 0; | 104 pStmt = 0; |
103 sqlite3Error(db, SQLITE_ABORT, 0); | 105 sqlite3Error(db, SQLITE_ABORT); |
104 goto exec_out; | 106 goto exec_out; |
105 } | 107 } |
106 } | 108 } |
107 | 109 |
108 if( rc!=SQLITE_ROW ){ | 110 if( rc!=SQLITE_ROW ){ |
109 rc = sqlite3VdbeFinalize((Vdbe *)pStmt); | 111 rc = sqlite3VdbeFinalize((Vdbe *)pStmt); |
110 pStmt = 0; | 112 pStmt = 0; |
111 if( rc!=SQLITE_SCHEMA ){ | 113 zSql = zLeftover; |
112 nRetry = 0; | 114 while( sqlite3Isspace(zSql[0]) ) zSql++; |
113 zSql = zLeftover; | |
114 while( sqlite3Isspace(zSql[0]) ) zSql++; | |
115 } | |
116 break; | 115 break; |
117 } | 116 } |
118 } | 117 } |
119 | 118 |
120 sqlite3DbFree(db, azCols); | 119 sqlite3DbFree(db, azCols); |
121 azCols = 0; | 120 azCols = 0; |
122 } | 121 } |
123 | 122 |
124 exec_out: | 123 exec_out: |
125 if( pStmt ) sqlite3VdbeFinalize((Vdbe *)pStmt); | 124 if( pStmt ) sqlite3VdbeFinalize((Vdbe *)pStmt); |
126 sqlite3DbFree(db, azCols); | 125 sqlite3DbFree(db, azCols); |
127 | 126 |
128 rc = sqlite3ApiExit(db, rc); | 127 rc = sqlite3ApiExit(db, rc); |
129 if( rc!=SQLITE_OK && ALWAYS(rc==sqlite3_errcode(db)) && pzErrMsg ){ | 128 if( rc!=SQLITE_OK && pzErrMsg ){ |
130 int nErrMsg = 1 + sqlite3Strlen30(sqlite3_errmsg(db)); | 129 int nErrMsg = 1 + sqlite3Strlen30(sqlite3_errmsg(db)); |
131 *pzErrMsg = sqlite3Malloc(nErrMsg); | 130 *pzErrMsg = sqlite3Malloc(nErrMsg); |
132 if( *pzErrMsg ){ | 131 if( *pzErrMsg ){ |
133 memcpy(*pzErrMsg, sqlite3_errmsg(db), nErrMsg); | 132 memcpy(*pzErrMsg, sqlite3_errmsg(db), nErrMsg); |
134 }else{ | 133 }else{ |
135 rc = SQLITE_NOMEM; | 134 rc = SQLITE_NOMEM; |
136 sqlite3Error(db, SQLITE_NOMEM, 0); | 135 sqlite3Error(db, SQLITE_NOMEM); |
137 } | 136 } |
138 }else if( pzErrMsg ){ | 137 }else if( pzErrMsg ){ |
139 *pzErrMsg = 0; | 138 *pzErrMsg = 0; |
140 } | 139 } |
141 | 140 |
142 assert( (rc&db->errMask)==rc ); | 141 assert( (rc&db->errMask)==rc ); |
143 sqlite3_mutex_leave(db->mutex); | 142 sqlite3_mutex_leave(db->mutex); |
144 return rc; | 143 return rc; |
145 } | 144 } |
OLD | NEW |