annotate sqlite/legacy.c @ 1695:3cf80d8a6d8d trunk

[svn] - Removed .cpp.o target since we don't have any .cpp files anymore. - A test build then revealed that we still had two .cpp files in Plugins/Input/musepack, fixed that. - Moved nenolod's fix from init.mk to objective.mk. - Removed call to ldconfig in Makefile and replaced it with a hint to call ldconfig manually, since ldconfig without parameters breaks some systems (mainly OpenBSD). - I hope I did not forget to list a change I did ;)
author js
date Fri, 15 Sep 2006 06:36:26 -0700
parents b6b61becdf4e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1434
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2 ** 2001 September 15
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4 ** The author disclaims copyright to this source code. In place of
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
5 ** a legal notice, here is a blessing:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
6 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
7 ** May you do good and not evil.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
8 ** May you find forgiveness for yourself and forgive others.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
9 ** May you share freely, never taking more than you give.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
10 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
11 *************************************************************************
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
12 ** Main file for the SQLite library. The routines in this file
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
13 ** implement the programmer interface to the library. Routines in
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
14 ** other files are for internal use by SQLite and should not be
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
15 ** accessed by users of the library.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
16 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
17 ** $Id: legacy.c,v 1.14 2006/03/06 20:55:46 drh Exp $
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
18 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
19
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
20 #include "sqliteInt.h"
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
21 #include "os.h"
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
22 #include <ctype.h>
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
23
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
24 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
25 ** Execute SQL code. Return one of the SQLITE_ success/failure
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
26 ** codes. Also write an error message into memory obtained from
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
27 ** malloc() and make *pzErrMsg point to that message.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
28 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
29 ** If the SQL is a query, then for each row in the query result
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
30 ** the xCallback() function is called. pArg becomes the first
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
31 ** argument to xCallback(). If xCallback=NULL then no callback
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
32 ** is invoked, even for queries.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
33 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
34 int sqlite3_exec(
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
35 sqlite3 *db, /* The database on which the SQL executes */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
36 const char *zSql, /* The SQL to be executed */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
37 sqlite3_callback xCallback, /* Invoke this callback routine */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
38 void *pArg, /* First argument to xCallback() */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
39 char **pzErrMsg /* Write error messages here */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
40 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
41 int rc = SQLITE_OK;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
42 const char *zLeftover;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
43 sqlite3_stmt *pStmt = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
44 char **azCols = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
45
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
46 int nRetry = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
47 int nChange = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
48 int nCallback;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
49
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
50 if( zSql==0 ) return SQLITE_OK;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
51 while( (rc==SQLITE_OK || (rc==SQLITE_SCHEMA && (++nRetry)<2)) && zSql[0] ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
52 int nCol;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
53 char **azVals = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
54
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
55 pStmt = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
56 rc = sqlite3_prepare(db, zSql, -1, &pStmt, &zLeftover);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
57 assert( rc==SQLITE_OK || pStmt==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
58 if( rc!=SQLITE_OK ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
59 continue;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
60 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
61 if( !pStmt ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
62 /* this happens for a comment or white-space */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
63 zSql = zLeftover;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
64 continue;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
65 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
66
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
67 db->nChange += nChange;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
68 nCallback = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
69
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
70 nCol = sqlite3_column_count(pStmt);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
71 azCols = sqliteMalloc(2*nCol*sizeof(const char *) + 1);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
72 if( azCols==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
73 goto exec_out;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
74 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
75
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
76 while( 1 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
77 int i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
78 rc = sqlite3_step(pStmt);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
79
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
80 /* Invoke the callback function if required */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
81 if( xCallback && (SQLITE_ROW==rc ||
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
82 (SQLITE_DONE==rc && !nCallback && db->flags&SQLITE_NullCallback)) ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
83 if( 0==nCallback ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
84 for(i=0; i<nCol; i++){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
85 azCols[i] = (char *)sqlite3_column_name(pStmt, i);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
86 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
87 nCallback++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
88 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
89 if( rc==SQLITE_ROW ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
90 azVals = &azCols[nCol];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
91 for(i=0; i<nCol; i++){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
92 azVals[i] = (char *)sqlite3_column_text(pStmt, i);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
93 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
94 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
95 if( xCallback(pArg, nCol, azVals, azCols) ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
96 rc = SQLITE_ABORT;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
97 goto exec_out;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
98 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
99 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
100
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
101 if( rc!=SQLITE_ROW ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
102 rc = sqlite3_finalize(pStmt);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
103 pStmt = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
104 if( db->pVdbe==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
105 nChange = db->nChange;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
106 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
107 if( rc!=SQLITE_SCHEMA ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
108 nRetry = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
109 zSql = zLeftover;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
110 while( isspace((unsigned char)zSql[0]) ) zSql++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
111 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
112 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
113 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
114 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
115
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
116 sqliteFree(azCols);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
117 azCols = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
118 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
119
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
120 exec_out:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
121 if( pStmt ) sqlite3_finalize(pStmt);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
122 if( azCols ) sqliteFree(azCols);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
123
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
124 rc = sqlite3ApiExit(0, rc);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
125 if( rc!=SQLITE_OK && rc==sqlite3_errcode(db) && pzErrMsg ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
126 *pzErrMsg = malloc(1+strlen(sqlite3_errmsg(db)));
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
127 if( *pzErrMsg ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
128 strcpy(*pzErrMsg, sqlite3_errmsg(db));
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
129 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
130 }else if( pzErrMsg ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
131 *pzErrMsg = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
132 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
133
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
134 return rc;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
135 }