mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-05 04:30:38 +03:00
Tests for text encoding conversion functions. Also new sqlite3_bindXX APIs. (CVS 1403)
FossilOrigin-Name: f71844bc27c9fc799af3337daf2a212370d4a724
This commit is contained in:
14
manifest
14
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
|
||||
|
||||
@@ -1 +1 @@
|
||||
a0f3f6ed2327992036267627cf663e5ca56bd3ae
|
||||
f71844bc27c9fc799af3337daf2a212370d4a724
|
||||
@@ -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 */
|
||||
|
||||
176
src/vdbeaux.c
176
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; n<p->nVar; n++){
|
||||
p->azVar[n].flags = MEM_Null;
|
||||
}
|
||||
}
|
||||
|
||||
sqlite3HashInit(&p->agg.hash, SQLITE_HASH_BINARY, 0);
|
||||
@@ -941,6 +942,140 @@ int sqlite3VdbeFinalize(Vdbe *p, char **pzErrMsg){
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Unbind the value bound to variable $i in virtual machine p. This is the
|
||||
** the same as binding a NULL value to the column.
|
||||
*/
|
||||
static int vdbeUnbind(Vdbe *p, int i){
|
||||
Mem *pVar;
|
||||
if( p->magic!=VDBE_MAGIC_RUN || p->pc!=0 ){
|
||||
return SQLITE_MISUSE;
|
||||
}
|
||||
if( i<1 || i>p->nVar ){
|
||||
return SQLITE_RANGE;
|
||||
}
|
||||
i--;
|
||||
pVar = &p->azVar[i];
|
||||
if( pVar->flags&MEM_Dyn ){
|
||||
sqliteFree(pVar->z);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
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
|
||||
@@ -950,35 +1085,8 @@ int sqlite3VdbeFinalize(Vdbe *p, char **pzErrMsg){
|
||||
** This routine overrides any prior call.
|
||||
*/
|
||||
int sqlite3_bind(sqlite_vm *pVm, int i, const char *zVal, int len, int copy){
|
||||
Vdbe *p = (Vdbe*)pVm;
|
||||
if( p->magic!=VDBE_MAGIC_RUN || p->pc!=0 ){
|
||||
return SQLITE_MISUSE;
|
||||
return sqlite3_bind_text(pVm, i, zVal, len, copy);
|
||||
}
|
||||
if( i<1 || i>p->nVar ){
|
||||
return SQLITE_RANGE;
|
||||
}
|
||||
i--;
|
||||
if( p->abVar[i] ){
|
||||
sqliteFree(p->azVar[i]);
|
||||
}
|
||||
if( zVal==0 ){
|
||||
copy = 0;
|
||||
len = 0;
|
||||
}
|
||||
if( len<0 ){
|
||||
len = strlen(zVal)+1;
|
||||
}
|
||||
if( copy ){
|
||||
p->azVar[i] = sqliteMalloc( len );
|
||||
if( p->azVar[i] ) memcpy(p->azVar[i], zVal, len);
|
||||
}else{
|
||||
p->azVar[i] = (char*)zVal;
|
||||
}
|
||||
p->abVar[i] = copy;
|
||||
p->anVar[i] = len;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Delete an entire VDBE.
|
||||
@@ -1007,7 +1115,9 @@ void sqlite3VdbeDelete(Vdbe *p){
|
||||
}
|
||||
}
|
||||
for(i=0; i<p->nVar; 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);
|
||||
|
||||
Reference in New Issue
Block a user