Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/src/legacy.c # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / src / legacy.c` 141 lines ยท 4531 bytes Raw Blame History 1 /* 2 ** 2001 September 15 3 ** 4 ** The author disclaims copyright to this source code. In place of 5 ** a legal notice, here is a blessing: 6 ** 7 ** May you do good and not evil. 8 ** May you find forgiveness for yourself and forgive others. 9 ** May you share freely, never taking more than you give. 10 ** 11 ************************************************************************* 12 ** Main file for the SQLite library. The routines in this file 13 ** implement the programmer interface to the library. Routines in 14 ** other files are for internal use by SQLite and should not be 15 ** accessed by users of the library. 16 */ 17 18 #include "sqliteInt.h" 19 20 /* 21 ** Execute SQL code. Return one of the SQLITE_ success/failure 22 ** codes. Also write an error message into memory obtained from 23 ** malloc() and make *pzErrMsg point to that message. 24 ** 25 ** If the SQL is a query, then for each row in the query result 26 ** the xCallback() function is called. pArg becomes the first 27 ** argument to xCallback(). If xCallback=NULL then no callback 28 ** is invoked, even for queries. 29 */ 30 int sqlite3_exec( 31 sqlite3 *db, /* The database on which the SQL executes */ 32 const char *zSql, /* The SQL to be executed */ 33 sqlite3_callback xCallback, /* Invoke this callback routine */ 34 void *pArg, /* First argument to xCallback() */ 35 char **pzErrMsg /* Write error messages here */ 36 ){ 37 int rc = SQLITE_OK; /* Return code */ 38 const char *zLeftover; /* Tail of unprocessed SQL */ 39 sqlite3_stmt *pStmt = 0; /* The current SQL statement */ 40 char **azCols = 0; /* Names of result columns */ 41 int callbackIsInit; /* True if callback data is initialized */ 42 43 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; 44 if( zSql==0 ) zSql = ""; 45 46 sqlite3_mutex_enter(db->mutex); 47 sqlite3Error(db, SQLITE_OK); 48 while( rc==SQLITE_OK && zSql[0] ){ 49 int nCol = 0; 50 char **azVals = 0; 51 52 pStmt = 0; 53 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover); 54 assert( rc==SQLITE_OK || pStmt==0 ); 55 if( rc!=SQLITE_OK ){ 56 continue; 57 } 58 if( !pStmt ){ 59 /* this happens for a comment or white-space */ 60 zSql = zLeftover; 61 continue; 62 } 63 callbackIsInit = 0; 64 65 while( 1 ){ 66 int i; 67 rc = sqlite3_step(pStmt); 68 69 /* Invoke the callback function if required */ 70 if( xCallback && (SQLITE_ROW==rc || 71 (SQLITE_DONE==rc && !callbackIsInit 72 && db->flags&SQLITE_NullCallback)) ){ 73 if( !callbackIsInit ){ 74 nCol = sqlite3_column_count(pStmt); 75 azCols = sqlite3DbMallocRaw(db, (2*nCol+1)*sizeof(const char*)); 76 if( azCols==0 ){ 77 goto exec_out; 78 } 79 for(i=0; ierrMask)==rc ); 139 sqlite3_mutex_leave(db->mutex); 140 return rc; 141 }