Add file legacy.c with old APIs. (CVS 1456)

FossilOrigin-Name: ae18fcb7ad91096f8029605b54d71ec225f31f32
This commit is contained in:
danielk1977 2004-05-26 00:01:35 +00:00
parent 22322fd42b
commit 98d30677b0
3 changed files with 144 additions and 6 deletions

View File

@ -1,5 +1,5 @@
C Move\sthe\ssqlite3_exec()\sfunction\sto\slegacy.c.\s(CVS\s1455)
D 2004-05-25T23:35:18
C Add\sfile\slegacy.c\swith\sold\sAPIs.\s(CVS\s1456)
D 2004-05-26T00:01:35
F Makefile.in ab7b0d5118e2da97bac66be8684a1034e3500f5a
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@ -36,6 +36,7 @@ F src/func.c e67a36ae28ee3495d02261f74989a7bb192658fd
F src/hash.c 440c2f8cb373ee1b4e13a0988489c7cd95d55b6f
F src/hash.h 762d95f1e567664d1eafc1687de755626be962fb
F src/insert.c 48bb15bff280767684a0f9ee4ae5973c9504f880
F src/legacy.c 706484c32e86b95d65aeb31f661c0e4a3649b862
F src/main.c 843361d68f275bc9dd3494897a105b34ad80e019
F src/md5.c 32ec4d879e9b34d6a597ae8bda684d8e395003f4
F src/os.h ab42f4a7c4c716f26b988e759b6e12085a3bfc67
@ -202,7 +203,7 @@ F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604
F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da
F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1
F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
P 8f6b20c2938ded7ab9e400494c02370ecf7e9311
R d7e2aba31e181ad39960b2f1be066f14
P 9385ad5ca82c82d9ef699102ca0b53661d02a052
R c7261e32f74427f74b17e0e0b0e6d6f2
U danielk1977
Z 651dbe0e74604e5a9ec8c254d6d50b80
Z db7575fd9fa9fef8fcd2c82fe508a21b

View File

@ -1 +1 @@
9385ad5ca82c82d9ef699102ca0b53661d02a052
ae18fcb7ad91096f8029605b54d71ec225f31f32

137
src/legacy.c Normal file
View File

@ -0,0 +1,137 @@
/*
** 2001 September 15
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** Main file for the SQLite library. The routines in this file
** implement the programmer interface to the library. Routines in
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: legacy.c,v 1.1 2004/05/26 00:01:35 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>
/*
** Execute SQL code. Return one of the SQLITE_ success/failure
** codes. Also write an error message into memory obtained from
** malloc() and make *pzErrMsg point to that message.
**
** If the SQL is a query, then for each row in the query result
** the xCallback() function is called. pArg becomes the first
** argument to xCallback(). If xCallback=NULL then no callback
** is invoked, even for queries.
*/
int sqlite3_exec(
sqlite *db, /* The database on which the SQL executes */
const char *zSql, /* The SQL to be executed */
sqlite_callback xCallback, /* Invoke this callback routine */
void *pArg, /* First argument to xCallback() */
char **pzErrMsg /* Write error messages here */
){
int rc = SQLITE_OK;
const char *zLeftover;
sqlite3_stmt *pStmt = 0;
char **azCols = 0;
int nRetry = 0;
int nChange = 0;
int nCallback;
if( zSql==0 ) return SQLITE_OK;
while( (rc==SQLITE_OK || (rc==SQLITE_SCHEMA && (++nRetry)<2)) && zSql[0] ){
int nCol;
char **azVals = 0;
pStmt = 0;
rc = sqlite3_prepare(db, zSql, -1, &pStmt, &zLeftover);
if( rc!=SQLITE_OK ){
if( pStmt ) sqlite3_finalize_new(pStmt);
continue;
}
if( !pStmt ){
/* this happens for a comment or white-space */
zSql = zLeftover;
continue;
}
db->nChange += nChange;
nCallback = 0;
nCol = sqlite3_column_count(pStmt);
azCols = sqliteMalloc(2*nCol*sizeof(const char *));
if( nCol && !azCols ){
rc = SQLITE_NOMEM;
goto exec_out;
}
while( 1 ){
int i;
rc = sqlite3_step(pStmt);
/* Invoke the callback function if required */
if( xCallback && (SQLITE_ROW==rc ||
(SQLITE_DONE==rc && !nCallback && db->flags&SQLITE_NullCallback)) ){
if( 0==nCallback ){
for(i=0; i<nCol; i++){
azCols[i] = (char *)sqlite3_column_name(pStmt, i);
}
nCallback++;
}
if( rc==SQLITE_ROW ){
azVals = &azCols[nCol];
for(i=0; i<nCol; i++){
azVals[i] = (char *)sqlite3_column_data(pStmt, i);
}
}
if( xCallback(pArg, nCol, azVals, azCols) ){
rc = SQLITE_ABORT;
goto exec_out;
}
}
if( rc!=SQLITE_ROW ){
rc = sqlite3_finalize_new(pStmt);
pStmt = 0;
if( db->pVdbe==0 ){
nChange = db->nChange;
}
if( rc!=SQLITE_SCHEMA ){
nRetry = 0;
zSql = zLeftover;
while( isspace(zSql[0]) ) zSql++;
}
break;
}
}
sqliteFree(azCols);
azCols = 0;
}
exec_out:
if( pStmt ) sqlite3_finalize_new(pStmt);
if( azCols ) sqliteFree(azCols);
if( rc!=SQLITE_OK && rc==sqlite3_errcode(db) && pzErrMsg ){
*pzErrMsg = malloc(1+strlen(sqlite3_errmsg(db)));
if( *pzErrMsg ){
strcpy(*pzErrMsg, sqlite3_errmsg(db));
}
}else if( pzErrMsg ){
*pzErrMsg = 0;
}
return rc;
}