From 18f4189055e6def9bab0c080ffec154b237e32aa Mon Sep 17 00:00:00 2001 From: danielk1977 Date: Sat, 22 May 2004 07:27:46 +0000 Subject: [PATCH] A few bugfixes related to UTF-16 databases. sqlite3_open() still assumes a UTF-8 database, and sqlite3_open16() still assumes a UTF-16 db. (CVS 1434) FossilOrigin-Name: b3581d2796c8cb6581b7156774698a05fc8f800e --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/vdbe.c | 28 +++++++++++++++++++--------- src/vdbeaux.c | 46 ++++++++++++++++++++++++++++++++++------------ 4 files changed, 61 insertions(+), 29 deletions(-) diff --git a/manifest b/manifest index 35b0645214..53c98d8a15 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Steps\stowards\sUTF-16\sdatabases.\sSome\stests\sare\sfailing\sbecause\sof\sthis\ncommit.\s(CVS\s1433) -D 2004-05-22T03:05:34 +C A\sfew\sbugfixes\srelated\sto\sUTF-16\sdatabases.\ssqlite3_open()\sstill\sassumes\sa\nUTF-8\sdatabase,\sand\ssqlite3_open16()\sstill\sassumes\sa\sUTF-16\sdb.\s(CVS\s1434) +D 2004-05-22T07:27:46 F Makefile.in ab7b0d5118e2da97bac66be8684a1034e3500f5a F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd @@ -64,10 +64,10 @@ F src/update.c 1a5e9182596f3ea8c7a141e308a3d2a7e5689fee F src/utf.c 537e1c98cddc623628d44497ec02c2246cf66dea F src/util.c 5cbeb452da09cfc7248de9948c15b14d840723f7 F src/vacuum.c c134702e023db8778e6be59ac0ea7b02315b5476 -F src/vdbe.c 91e6663c690f5208fadca0bd06b4878aed61f239 +F src/vdbe.c 3ce76c80887e5a5a0a850b2cb7ea1e353c113e36 F src/vdbe.h 391d5642a83af686f35c228fcd36cb4456d68f44 F src/vdbeInt.h f40e8048d644c8389cda16f46479376f763d56e6 -F src/vdbeaux.c 8e993bfd0f943163548ce3e09797ce5503d2366f +F src/vdbeaux.c d3dfb6d40eb1fdf2626896e8b13fe7b50134ff12 F src/where.c efe5d25fe18cd7381722457898cd863e84097a0c F test/all.test 569a92a8ee88f5300c057cc4a8f50fbbc69a3242 F test/attach.test cb9b884344e6cfa5e165965d5b1adea679a24c83 @@ -195,7 +195,7 @@ F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604 F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1 F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4 -P 8069caca82bc4d40d8ac95bafdd91a18a70ab1e0 -R f44ee6ced05cfe974110947781c41eee +P c4a8246864eee7cb993ab7b703324d92c284d72a +R 92babf97adb0222e27f8107a93f8fb2a U danielk1977 -Z 35da3b16c198243de8a20489bd428c37 +Z c69763de411eab46b3116a06db08807c diff --git a/manifest.uuid b/manifest.uuid index c813f79140..c21b7a4ae9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c4a8246864eee7cb993ab7b703324d92c284d72a \ No newline at end of file +b3581d2796c8cb6581b7156774698a05fc8f800e \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 174c14aeed..b4e429f185 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -43,7 +43,7 @@ ** in this file for details. If in doubt, do not deviate from existing ** commenting and indentation practices when changing or adding code. ** -** $Id: vdbe.c,v 1.316 2004/05/22 03:05:34 danielk1977 Exp $ +** $Id: vdbe.c,v 1.317 2004/05/22 07:27:46 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -523,7 +523,7 @@ const unsigned char *sqlite3_column_data(sqlite3_stmt *pStmt, int i){ return 0; } - if( !pVal->flags&MEM_Blob ){ + if( !(pVal->flags&MEM_Blob) ){ Stringify(pVal); SetEncoding(pVal, MEM_Utf8|MEM_Term); } @@ -1336,7 +1336,7 @@ case OP_Integer: { pTos->flags = MEM_Int; if( pOp->p3 ){ pTos->z = pOp->p3; - pTos->flags |= MEM_Utf8 | MEM_Str | MEM_Static; + pTos->flags |= MEM_Utf8 | MEM_Str | MEM_Static | MEM_Term; pTos->n = strlen(pOp->p3)+1; if( pTos->i==0 ){ sqlite3GetInt64(pTos->z, &pTos->i); @@ -1377,7 +1377,7 @@ case OP_Real: { pTos->r = sqlite3AtoF(z, 0); pTos->z = z; pTos->n = strlen(z)+1; - pTos->flags = MEM_Real|MEM_Str|MEM_Static|MEM_Utf8; + pTos->flags = MEM_Real|MEM_Str|MEM_Static|MEM_Utf8|MEM_Term; break; } @@ -1484,8 +1484,8 @@ case OP_Pull: { Deephemeralize(pTos); for(i=0; ip1; i++, pFrom++){ Deephemeralize(&pFrom[1]); - *pFrom = pFrom[1]; assert( (pFrom->flags & MEM_Ephem)==0 ); + *pFrom = pFrom[1]; if( pFrom->flags & MEM_Short ){ assert( pFrom->flags & (MEM_Str|MEM_Blob) ); assert( pFrom->z==pFrom[1].zShort ); @@ -2326,7 +2326,7 @@ case OP_Class: { }; Release(pTos); - pTos->flags = MEM_Str|MEM_Static|MEM_Utf8; + pTos->flags = MEM_Str|MEM_Static|MEM_Utf8|MEM_Term; for(i=0; i<5; i++){ if( classes[i].mask&flags ){ @@ -2335,6 +2335,7 @@ case OP_Class: { } } assert( i<5 ); + pTos->n = strlen(classes[i].zClass); break; } @@ -2399,7 +2400,12 @@ case OP_Column: { u64 colType; /* The serial type of the value being read. */ assert( &pTos[i-1]>=p->aStack ); - assert( pTos[i].flags & MEM_Blob ); + + /* FIX ME: I don't understand this either. How is it related to + ** OP_SortNext? (I thought it would be the commented out assert()) + */ + /* assert( pTos[i].flags & MEM_Blob ); */ + assert( pTos[i].flags & (MEM_Blob|MEM_Str) ); assert( pTos[i-1].flags & MEM_Int ); if( pTos[i].n==0 ){ @@ -4755,7 +4761,11 @@ case OP_SortNext: { pTos++; pTos->z = pSorter->pData; pTos->n = pSorter->nData; - pTos->flags = MEM_Blob|MEM_Dyn; + /* FIX ME: I don't understand this. What does the sorter return? + ** I thought it would be the commented out flags. + */ + /* pTos->flags = MEM_Blob|MEM_Dyn; */ + pTos->flags = MEM_Str|MEM_Dyn|MEM_Utf8|MEM_Term; sqliteFree(pSorter->zKey); sqliteFree(pSorter); }else{ @@ -4934,7 +4944,7 @@ case OP_FileColumn: { if( z ){ pTos->n = strlen(z) + 1; pTos->z = z; - pTos->flags = MEM_Utf8 | MEM_Str | MEM_Ephem; + pTos->flags = MEM_Utf8 | MEM_Str | MEM_Ephem | MEM_Term; }else{ pTos->flags = MEM_Null; } diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 9c6aa264b6..c91d7a70a3 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -641,12 +641,25 @@ int sqlite3VdbeList( 0 }; - assert( p->popStack==0 ); assert( p->explain ); + + /* Even though this opcode does not put dynamic strings onto the + ** the stack, they may become dynamic if the user calls + ** sqlite3_column_data16(), causing a translation to UTF-16 encoding. + */ + if( p->pTos==&p->aStack[4] ){ + for(i=0; i<5; i++){ + if( p->aStack[i].flags & MEM_Dyn ){ + sqliteFree(p->aStack[i].z); + } + p->aStack[i].flags = 0; + } + } + p->azColName = azColumnNames; - p->azResColumn = p->zArgv; - for(i=0; i<5; i++) p->zArgv[i] = p->aStack[i].zShort; - i = p->pc; + p->resOnStack = 0; + + i = p->pc++; if( i>=p->nOp ){ p->rc = SQLITE_OK; rc = SQLITE_DONE; @@ -661,16 +674,25 @@ int sqlite3VdbeList( sqlite3SetString(&p->zErrMsg, sqlite3_error_string(p->rc), (char*)0); }else{ Op *pOp = &p->aOp[i]; - sprintf(p->zArgv[0],"%d",i); - sprintf(p->zArgv[2],"%d", pOp->p1); - sprintf(p->zArgv[3],"%d", pOp->p2); - p->zArgv[4] = - displayP3(pOp, p->aStack[4].zShort, sizeof(p->aStack[4].zShort)); - p->zArgv[1] = sqlite3OpcodeNames[pOp->opcode]; - p->pc = i+1; - p->azResColumn = p->zArgv; + p->aStack[0].flags = MEM_Int; + p->aStack[0].i = i; /* Program counter */ + p->aStack[1].flags = MEM_Static|MEM_Str|MEM_Utf8|MEM_Term; + p->aStack[1].z = sqlite3OpcodeNames[pOp->opcode]; /* Opcode */ + p->aStack[2].flags = MEM_Int; + p->aStack[2].i = pOp->p1; /* P1 */ + p->aStack[3].flags = MEM_Int; + p->aStack[3].i = pOp->p2; /* P2 */ + p->aStack[4].flags = MEM_Str|MEM_Utf8|MEM_Term; /* P3 */ + p->aStack[4].z = displayP3(pOp, p->aStack[4].zShort, NBFS); + if( p->aStack[4].z==p->aStack[4].zShort ){ + p->aStack[4].flags |= MEM_Short; + }else{ + p->aStack[4].flags |= MEM_Static; + } p->nResColumn = 5; + p->pTos = &p->aStack[4]; p->rc = SQLITE_OK; + p->resOnStack = 1; rc = SQLITE_ROW; } return rc;