From: danielk1977 Date: Wed, 19 May 2004 10:36:43 +0000 (+0000) Subject: Tests for text encoding conversion functions. Also new sqlite3_bindXX APIs. (CVS... X-Git-Tag: version-3.6.10~4671 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=54db47e3dac2af1d1af7601bac05309ab73e242d;p=thirdparty%2Fsqlite.git Tests for text encoding conversion functions. Also new sqlite3_bindXX APIs. (CVS 1403) FossilOrigin-Name: f71844bc27c9fc799af3337daf2a212370d4a724 --- diff --git a/manifest b/manifest index 47dd327dfe..d4fe030db3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Tests\sfor\stext\sencoding\sconversion\sfunctions.\sAlso\snew\ssqlite3_bindXX\sAPIs.\s(CVS\s1402) -D 2004-05-19T10:35:01 +C Tests\sfor\stext\sencoding\sconversion\sfunctions.\sAlso\snew\ssqlite3_bindXX\sAPIs.\s(CVS\s1403) +D 2004-05-19T10:36:44 F Makefile.in ab7b0d5118e2da97bac66be8684a1034e3500f5a F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd @@ -65,8 +65,8 @@ F src/util.c b72f775a6c3fa404d70250382f63d708e17bc332 F src/vacuum.c c134702e023db8778e6be59ac0ea7b02315b5476 F src/vdbe.c f5451f1f71e46acebe0be797a138302b4b7ead43 F src/vdbe.h 314e9c07db73a42a6ba91ab7539e27652fc88870 -F src/vdbeInt.h 5bac5f0f468205f6e43a4ba86a807abff4953abb -F src/vdbeaux.c 95f5a9ff770794f5165d5827d2343eb2d83d7a6d +F src/vdbeInt.h 2097f78f8dd0e2abcd1b986ac3e8af484dc5a1e1 +F src/vdbeaux.c 1e1aed6b07a02bf0768c9bf9eae06c9b488c560a F src/where.c 5f480219a943b0fed1f6922d2fdbfba8616a9148 F test/all.test 569a92a8ee88f5300c057cc4a8f50fbbc69a3242 F test/attach.test cb9b884344e6cfa5e165965d5b1adea679a24c83 @@ -193,7 +193,7 @@ F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604 F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1 F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4 -P 33293ae1849dcb4587b8463466bdde2dd9336b82 -R 334bdded4c677d317efa922d114eed4d +P a0f3f6ed2327992036267627cf663e5ca56bd3ae +R 2fe56592f6dc9245a3872afd301b1853 U danielk1977 -Z 22f80ed70ef1691b06f8a2a81cde2071 +Z 72c11613022fdf4360d5afb7ad04e0c8 diff --git a/manifest.uuid b/manifest.uuid index 7df4f24aa4..b9b49a84d5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a0f3f6ed2327992036267627cf663e5ca56bd3ae \ No newline at end of file +f71844bc27c9fc799af3337daf2a212370d4a724 \ No newline at end of file diff --git a/src/vdbeInt.h b/src/vdbeInt.h index 87c479462f..4328d22928 100644 --- a/src/vdbeInt.h +++ b/src/vdbeInt.h @@ -272,9 +272,7 @@ struct Vdbe { int nField; /* Number of file fields */ char **azField; /* Data for each file field */ int nVar; /* Number of entries in azVariable[] */ - char **azVar; /* Values for the OP_Variable opcode */ - int *anVar; /* Length of each value in azVariable[] */ - u8 *abVar; /* TRUE if azVariable[i] needs to be sqliteFree()ed */ + Mem *azVar; /* Values for the OP_Variable opcode. */ char *zLine; /* A single line from the input file */ int nLineAlloc; /* Number of spaces allocated for zLine */ int magic; /* Magic number for sanity checking */ diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 8485a73ad5..c2022f9c63 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -616,13 +616,14 @@ void sqlite3VdbeMakeReady( n = isExplain ? 10 : p->nOp; p->aStack = sqliteMalloc( n*(sizeof(p->aStack[0]) + 2*sizeof(char*)) /* aStack and zArgv */ - + p->nVar*(sizeof(char*)+sizeof(int)+1) /* azVar, anVar, abVar */ + + p->nVar*sizeof(Mem) /* azVar */ ); p->zArgv = (char**)&p->aStack[n]; p->azColName = (char**)&p->zArgv[n]; - p->azVar = (char**)&p->azColName[n]; - p->anVar = (int*)&p->azVar[p->nVar]; - p->abVar = (u8*)&p->anVar[p->nVar]; + p->azVar = (Mem *)&p->azColName[n]; + for(n=0; nnVar; n++){ + p->azVar[n].flags = MEM_Null; + } } sqlite3HashInit(&p->agg.hash, SQLITE_HASH_BINARY, 0); @@ -942,15 +943,11 @@ int sqlite3VdbeFinalize(Vdbe *p, char **pzErrMsg){ } /* -** Set the values of all variables. Variable $1 in the original SQL will -** be the string azValue[0]. $2 will have the value azValue[1]. And -** so forth. If a value is out of range (for example $3 when nValue==2) -** then its value will be NULL. -** -** This routine overrides any prior call. +** Unbind the value bound to variable $i in virtual machine p. This is the +** the same as binding a NULL value to the column. */ -int sqlite3_bind(sqlite_vm *pVm, int i, const char *zVal, int len, int copy){ - Vdbe *p = (Vdbe*)pVm; +static int vdbeUnbind(Vdbe *p, int i){ + Mem *pVar; if( p->magic!=VDBE_MAGIC_RUN || p->pc!=0 ){ return SQLITE_MISUSE; } @@ -958,27 +955,138 @@ int sqlite3_bind(sqlite_vm *pVm, int i, const char *zVal, int len, int copy){ return SQLITE_RANGE; } i--; - if( p->abVar[i] ){ - sqliteFree(p->azVar[i]); + pVar = &p->azVar[i]; + if( pVar->flags&MEM_Dyn ){ + sqliteFree(pVar->z); } - if( zVal==0 ){ - copy = 0; - len = 0; + pVar->flags = MEM_Null; + return SQLITE_OK; +} + +/* +** This routine is used to bind text or blob data to an SQL variable (a ?). +** It may also be used to bind a NULL value, by setting zVal to 0. +*/ +static int vdbeBindBlob( + Vdbe *p, /* Virtual machine */ + int i, /* Var number to bind (numbered from 1 upward) */ + const char *zVal, /* Pointer to blob of data */ + int bytes, /* Number of bytes to copy */ + int copy, /* True to copy the memory, false to copy a pointer */ + int flags /* Valid combination of MEM_Blob, MEM_Str, MEM_UtfXX */ +){ + Mem *pVar; + + vdbeUnbind(p, i); + pVar = &p->azVar[i-1]; + + if( zVal ){ + pVar->n = bytes; + pVar->flags = flags; + if( !copy ){ + pVar->z = (char *)zVal; + pVar->flags |= MEM_Static; + }else{ + if( bytes>NBFS ){ + pVar->z = (char *)sqliteMalloc(bytes); + if( !pVar->z ){ + return SQLITE_NOMEM; + } + pVar->flags |= MEM_Dyn; + }else{ + pVar->z = pVar->zShort; + pVar->flags |= MEM_Short; + } + memcpy(pVar->z, zVal, bytes); + } } - if( len<0 ){ - len = strlen(zVal)+1; + + return SQLITE_OK; +} + +int sqlite3_bind_int64(sqlite3_stmt *p, int i, long long int iValue){ + int rc; + Vdbe *v = (Vdbe *)p; + rc = vdbeUnbind(v, i); + if( rc==SQLITE_OK ){ + Mem *pVar = &v->azVar[i-1]; + pVar->flags = MEM_Int; + pVar->i = iValue; } - if( copy ){ - p->azVar[i] = sqliteMalloc( len ); - if( p->azVar[i] ) memcpy(p->azVar[i], zVal, len); - }else{ - p->azVar[i] = (char*)zVal; + return SQLITE_OK; +} + +int sqlite3_bind_int32(sqlite3_stmt *p, int i, int iValue){ + return sqlite3_bind_int64(p, i, (long long int)iValue); +} + +int sqlite3_bind_double(sqlite3_stmt *p, int i, double iValue){ + int rc; + Vdbe *v = (Vdbe *)p; + rc = vdbeUnbind(v, i); + if( rc==SQLITE_OK ){ + Mem *pVar = &v->azVar[i-1]; + pVar->flags = MEM_Real; + pVar->r = iValue; } - p->abVar[i] = copy; - p->anVar[i] = len; return SQLITE_OK; } +int sqlite3_bind_null(sqlite3_stmt* p, int i){ + return vdbeUnbind((Vdbe *)p, i); +} + +int sqlite3_bind_text( + sqlite3_stmt *p, + int i, + const char *zData, + int nData, + int eCopy +){ + if( zData && nData<0 ){ + nData = strlen(zData)+1; + } + return vdbeBindBlob((Vdbe *)p, i, zData, nData, eCopy, MEM_Str|MEM_Utf8); +} + +int sqlite3_bind_text16( + sqlite3_stmt *p, + int i, + const void *zData, + int nData, + int eCopy +){ + if( zData && nData<0 ){ + char *z = (char *)zData; + while( (*z)!=0 && (*(z+1))!=0 ) z+=2; + nData = (z - (char *)zData) + 2; + } + + /* FIX ME - MEM_Utf16le? */ + return vdbeBindBlob((Vdbe *)p, i, zData, nData, eCopy, MEM_Str|MEM_Utf16le); +} + +int sqlite3_bind_blob( + sqlite3_stmt *p, + int i, + const void *zData, + int nData, + int eCopy +){ + return vdbeBindBlob((Vdbe *)p, i, zData, nData, eCopy, MEM_Blob); +} + +/* +** Set the values of all variables. Variable $1 in the original SQL will +** be the string azValue[0]. $2 will have the value azValue[1]. And +** so forth. If a value is out of range (for example $3 when nValue==2) +** then its value will be NULL. +** +** This routine overrides any prior call. +*/ +int sqlite3_bind(sqlite_vm *pVm, int i, const char *zVal, int len, int copy){ + return sqlite3_bind_text(pVm, i, zVal, len, copy); +} /* ** Delete an entire VDBE. @@ -1007,7 +1115,9 @@ void sqlite3VdbeDelete(Vdbe *p){ } } for(i=0; inVar; i++){ - if( p->abVar[i] ) sqliteFree(p->azVar[i]); + if( p->azVar[i].flags&MEM_Dyn ){ + sqliteFree(p->azVar[i].z); + } } sqliteFree(p->aOp); sqliteFree(p->aLabel);