Optimisation for unicode encoding conversion routines. (CVS 1614)
FossilOrigin-Name: 39a415eaa65964742e40b7ea4d471fa04007c6c9
This commit is contained in:
+16
-7
@@ -23,7 +23,7 @@
|
||||
** ROLLBACK
|
||||
** PRAGMA
|
||||
**
|
||||
** $Id: build.c,v 1.220 2004/06/17 06:13:34 danielk1977 Exp $
|
||||
** $Id: build.c,v 1.221 2004/06/18 04:24:54 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
@@ -959,15 +959,12 @@ static void callCollNeeded(sqlite *db, const char *zName, int nName){
|
||||
db->xCollNeeded(db->pCollNeededArg, db, (int)db->enc, zExternal);
|
||||
}
|
||||
if( db->xCollNeeded16 ){
|
||||
if( SQLITE_BIGENDIAN ){
|
||||
zExternal = sqlite3utf8to16be(zName, nName);
|
||||
}else{
|
||||
zExternal = sqlite3utf8to16le(zName, nName);
|
||||
}
|
||||
sqlite3_value *pTmp = sqlite3GetTransientValue(db);
|
||||
sqlite3ValueSetStr(pTmp, -1, zName, SQLITE_UTF8, SQLITE_STATIC);
|
||||
zExternal = sqlite3ValueText(pTmp, SQLITE_UTF16NATIVE);
|
||||
if( !zExternal ) return;
|
||||
db->xCollNeeded16(db->pCollNeededArg, db, (int)db->enc, zExternal);
|
||||
}
|
||||
if( zExternal ) sqliteFree(zExternal);
|
||||
}
|
||||
|
||||
static int synthCollSeq(Parse *pParse, CollSeq *pColl){
|
||||
@@ -2627,3 +2624,15 @@ void sqlite3EndWriteOperation(Parse *pParse){
|
||||
/* Delete me! */
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the transient sqlite3_value object used for encoding conversions
|
||||
** during SQL compilation.
|
||||
*/
|
||||
sqlite3_value *sqlite3GetTransientValue(sqlite *db){
|
||||
if( !db->pValue ){
|
||||
db->pValue = sqlite3ValueNew();
|
||||
}
|
||||
return db->pValue;
|
||||
}
|
||||
|
||||
|
||||
+67
-58
@@ -14,7 +14,7 @@
|
||||
** other files are for internal use by SQLite and should not be
|
||||
** accessed by users of the library.
|
||||
**
|
||||
** $Id: main.c,v 1.224 2004/06/16 12:00:56 danielk1977 Exp $
|
||||
** $Id: main.c,v 1.225 2004/06/18 04:24:54 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
@@ -515,6 +515,12 @@ void sqlite3_close(sqlite *db){
|
||||
|
||||
sqlite3HashClear(&db->aFunc);
|
||||
sqlite3Error(db, SQLITE_OK, 0); /* Deallocates any cached error strings. */
|
||||
if( db->pValue ){
|
||||
sqlite3ValueFree(db->pValue);
|
||||
}
|
||||
if( db->pErr ){
|
||||
sqlite3ValueFree(db->pErr);
|
||||
}
|
||||
sqliteFree(db);
|
||||
}
|
||||
|
||||
@@ -749,14 +755,17 @@ int sqlite3_create_function16(
|
||||
void (*xFinal)(sqlite3_context*)
|
||||
){
|
||||
int rc;
|
||||
char *zFunctionName8;
|
||||
zFunctionName8 = sqlite3utf16to8(zFunctionName, -1, SQLITE_BIGENDIAN);
|
||||
if( !zFunctionName8 ){
|
||||
char const *zFunc8;
|
||||
|
||||
sqlite3_value *pTmp = sqlite3GetTransientValue(db);
|
||||
sqlite3ValueSetStr(pTmp, -1, zFunctionName, SQLITE_UTF16NATIVE,SQLITE_STATIC);
|
||||
zFunc8 = sqlite3ValueText(pTmp, SQLITE_UTF8);
|
||||
|
||||
if( !zFunc8 ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
rc = sqlite3_create_function(db, zFunctionName8, nArg, eTextRep,
|
||||
rc = sqlite3_create_function(db, zFunc8, nArg, eTextRep,
|
||||
iCollateArg, pUserData, xFunc, xStep, xFinal);
|
||||
sqliteFree(zFunctionName8);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -844,16 +853,16 @@ int sqlite3BtreeFactory(
|
||||
** error.
|
||||
*/
|
||||
const char *sqlite3_errmsg(sqlite3 *db){
|
||||
if( !db ){
|
||||
if( !db || !db->pErr ){
|
||||
/* If db is NULL, then assume that a malloc() failed during an
|
||||
** sqlite3_open() call.
|
||||
*/
|
||||
return sqlite3ErrStr(SQLITE_NOMEM);
|
||||
}
|
||||
if( db->zErrMsg ){
|
||||
return db->zErrMsg;
|
||||
if( !sqlite3_value_text(db->pErr) ){
|
||||
return sqlite3ErrStr(db->errCode);
|
||||
}
|
||||
return sqlite3ErrStr(db->errCode);
|
||||
return sqlite3_value_text(db->pErr);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -861,38 +870,32 @@ const char *sqlite3_errmsg(sqlite3 *db){
|
||||
** error.
|
||||
*/
|
||||
const void *sqlite3_errmsg16(sqlite3 *db){
|
||||
if( !db ){
|
||||
/* If db is NULL, then assume that a malloc() failed during an
|
||||
** sqlite3_open() call. We have a static version of the string
|
||||
** "out of memory" encoded using UTF-16 just for this purpose.
|
||||
**
|
||||
** Because all the characters in the string are in the unicode
|
||||
** range 0x00-0xFF, if we pad the big-endian string with a
|
||||
** zero byte, we can obtain the little-endian string with
|
||||
** &big_endian[1].
|
||||
*/
|
||||
static char outOfMemBe[] = {
|
||||
0, 'o', 0, 'u', 0, 't', 0, ' ',
|
||||
0, 'o', 0, 'f', 0, ' ',
|
||||
0, 'm', 0, 'e', 0, 'm', 0, 'o', 0, 'r', 0, 'y', 0, 0, 0
|
||||
};
|
||||
static char *outOfMemLe = &outOfMemBe[1];
|
||||
/* Because all the characters in the string are in the unicode
|
||||
** range 0x00-0xFF, if we pad the big-endian string with a
|
||||
** zero byte, we can obtain the little-endian string with
|
||||
** &big_endian[1].
|
||||
*/
|
||||
static char outOfMemBe[] = {
|
||||
0, 'o', 0, 'u', 0, 't', 0, ' ',
|
||||
0, 'o', 0, 'f', 0, ' ',
|
||||
0, 'm', 0, 'e', 0, 'm', 0, 'o', 0, 'r', 0, 'y', 0, 0, 0
|
||||
};
|
||||
|
||||
if( SQLITE_BIGENDIAN ){
|
||||
return (void *)outOfMemBe;
|
||||
}else{
|
||||
return (void *)outOfMemLe;
|
||||
if( db && db->pErr ){
|
||||
if( !sqlite3_value_text16(db->pErr) ){
|
||||
sqlite3ValueSetStr(db->pErr, -1, sqlite3ErrStr(db->errCode),
|
||||
SQLITE_UTF8, SQLITE_STATIC);
|
||||
}
|
||||
}
|
||||
if( !db->zErrMsg16 ){
|
||||
char const *zErr8 = sqlite3_errmsg(db);
|
||||
if( SQLITE_BIGENDIAN ){
|
||||
db->zErrMsg16 = sqlite3utf8to16be(zErr8, -1);
|
||||
}else{
|
||||
db->zErrMsg16 = sqlite3utf8to16le(zErr8, -1);
|
||||
if( sqlite3_value_text16(db->pErr) ){
|
||||
return sqlite3_value_text16(db->pErr);
|
||||
}
|
||||
}
|
||||
return db->zErrMsg16;
|
||||
}
|
||||
|
||||
/* If db is NULL, then assume that a malloc() failed during an
|
||||
** sqlite3_open() call. We have a static version of the string
|
||||
** "out of memory" encoded using UTF-16 just for this purpose.
|
||||
*/
|
||||
return (void *)(&outOfMemBe[SQLITE_UTF16NATIVE==SQLITE_UTF16LE?1:0]);
|
||||
}
|
||||
|
||||
int sqlite3_errcode(sqlite3 *db){
|
||||
@@ -1047,11 +1050,14 @@ int sqlite3_prepare16(
|
||||
** encoded string to UTF-8, then invoking sqlite3_prepare(). The
|
||||
** tricky bit is figuring out the pointer to return in *pzTail.
|
||||
*/
|
||||
char *zSql8 = 0;
|
||||
char const *zSql8 = 0;
|
||||
char const *zTail8 = 0;
|
||||
int rc;
|
||||
sqlite3_value *pTmp;
|
||||
|
||||
zSql8 = sqlite3utf16to8(zSql, nBytes, SQLITE_BIGENDIAN);
|
||||
pTmp = sqlite3GetTransientValue(db);
|
||||
sqlite3ValueSetStr(pTmp, -1, zSql, SQLITE_UTF16NATIVE, SQLITE_STATIC);
|
||||
zSql8 = sqlite3ValueText(pTmp, SQLITE_UTF8);
|
||||
if( !zSql8 ){
|
||||
sqlite3Error(db, SQLITE_NOMEM, 0);
|
||||
return SQLITE_NOMEM;
|
||||
@@ -1067,7 +1073,6 @@ int sqlite3_prepare16(
|
||||
int chars_parsed = sqlite3utf8CharLen(zSql8, zTail8-zSql8);
|
||||
*pzTail = (u8 *)zSql + sqlite3utf16ByteLen(zSql, chars_parsed);
|
||||
}
|
||||
sqliteFree(zSql8);
|
||||
|
||||
return rc;
|
||||
}
|
||||
@@ -1134,7 +1139,6 @@ static int openDatabase(
|
||||
}
|
||||
rc = sqlite3BtreeFactory(db, zFilename, 0, MAX_PAGES, &db->aDb[0].pBt);
|
||||
if( rc!=SQLITE_OK ){
|
||||
/* FIX ME: sqlite3BtreeFactory() should call sqlite3Error(). */
|
||||
sqlite3Error(db, rc, 0);
|
||||
db->magic = SQLITE_MAGIC_CLOSED;
|
||||
goto opendb_out;
|
||||
@@ -1148,6 +1152,7 @@ static int openDatabase(
|
||||
*/
|
||||
sqlite3RegisterBuiltinFunctions(db);
|
||||
if( rc==SQLITE_OK ){
|
||||
sqlite3Error(db, SQLITE_OK, 0);
|
||||
db->magic = SQLITE_MAGIC_OPEN;
|
||||
}else{
|
||||
sqlite3Error(db, rc, "%s", zErrMsg, 0);
|
||||
@@ -1177,21 +1182,24 @@ int sqlite3_open16(
|
||||
const void *zFilename,
|
||||
sqlite3 **ppDb
|
||||
){
|
||||
char *zFilename8; /* zFilename encoded in UTF-8 instead of UTF-16 */
|
||||
int rc;
|
||||
char const *zFilename8; /* zFilename encoded in UTF-8 instead of UTF-16 */
|
||||
int rc = SQLITE_NOMEM;
|
||||
sqlite3_value *pVal;
|
||||
|
||||
assert( ppDb );
|
||||
|
||||
zFilename8 = sqlite3utf16to8(zFilename, -1, SQLITE_BIGENDIAN);
|
||||
if( !zFilename8 ){
|
||||
*ppDb = 0;
|
||||
return SQLITE_NOMEM;
|
||||
*ppDb = 0;
|
||||
pVal = sqlite3ValueNew();
|
||||
sqlite3ValueSetStr(pVal, -1, zFilename, SQLITE_UTF16NATIVE, SQLITE_STATIC);
|
||||
zFilename8 = sqlite3ValueText(pVal, SQLITE_UTF8);
|
||||
if( zFilename8 ){
|
||||
rc = openDatabase(zFilename8, ppDb);
|
||||
if( rc==SQLITE_OK && *ppDb ){
|
||||
sqlite3_exec(*ppDb, "PRAGMA encoding = 'UTF-16'", 0, 0, 0);
|
||||
}
|
||||
}
|
||||
rc = openDatabase(zFilename8, ppDb);
|
||||
if( rc==SQLITE_OK && *ppDb ){
|
||||
sqlite3_exec(*ppDb, "PRAGMA encoding = 'UTF-16'", 0, 0, 0);
|
||||
if( pVal ){
|
||||
sqlite3ValueFree(pVal);
|
||||
}
|
||||
sqliteFree(zFilename8);
|
||||
|
||||
return rc;
|
||||
}
|
||||
@@ -1273,10 +1281,11 @@ int sqlite3_create_collation16(
|
||||
int(*xCompare)(void*,int,const void*,int,const void*)
|
||||
){
|
||||
int rc;
|
||||
char *zName8 = sqlite3utf16to8(zName, -1, SQLITE_BIGENDIAN);
|
||||
rc = sqlite3_create_collation(db, zName8, enc, pCtx, xCompare);
|
||||
sqliteFree(zName8);
|
||||
return rc;
|
||||
char const *zName8;
|
||||
sqlite3_value *pTmp = sqlite3GetTransientValue(db);
|
||||
sqlite3ValueSetStr(pTmp, -1, zName, SQLITE_UTF16NATIVE, SQLITE_STATIC);
|
||||
zName8 = sqlite3ValueText(pTmp, SQLITE_UTF8);
|
||||
return sqlite3_create_collation(db, zName8, enc, pCtx, xCompare);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+10
-11
@@ -11,7 +11,7 @@
|
||||
*************************************************************************
|
||||
** Internal interface definitions for SQLite.
|
||||
**
|
||||
** @(#) $Id: sqliteInt.h,v 1.286 2004/06/17 05:36:44 danielk1977 Exp $
|
||||
** @(#) $Id: sqliteInt.h,v 1.287 2004/06/18 04:24:54 danielk1977 Exp $
|
||||
*/
|
||||
#include "config.h"
|
||||
#include "sqlite3.h"
|
||||
@@ -194,6 +194,7 @@ extern const int sqlite3one;
|
||||
# define sqliteStrNDup(X,Y) sqlite3StrNDup_(X,Y,__FILE__,__LINE__)
|
||||
void sqlite3StrRealloc(char**);
|
||||
#else
|
||||
# define sqlite3FreeX sqliteFree
|
||||
# define sqlite3Realloc_(X,Y) sqliteRealloc(X,Y)
|
||||
# define sqlite3StrRealloc(X)
|
||||
#endif
|
||||
@@ -422,14 +423,17 @@ struct sqlite {
|
||||
#endif
|
||||
|
||||
int errCode; /* Most recent error code (SQLITE_*) */
|
||||
char *zErrMsg; /* Most recent error message (UTF-8 encoded) */
|
||||
void *zErrMsg16; /* Most recent error message (UTF-16 encoded) */
|
||||
u8 enc; /* Text encoding for this database. */
|
||||
u8 autoCommit; /* The auto-commit flag. */
|
||||
int nMaster; /* Length of master journal name. -1=unknown */
|
||||
void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*);
|
||||
void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*);
|
||||
void *pCollNeededArg;
|
||||
sqlite3_value *pValue; /* Value used for transient conversions */
|
||||
sqlite3_value *pErr; /* Most recent error message */
|
||||
|
||||
char *zErrMsg; /* Most recent error message (UTF-8 encoded) */
|
||||
char *zErrMsg16; /* Most recent error message (UTF-8 encoded) */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -1213,6 +1217,7 @@ void sqlite3RealToSortable(double r, char *);
|
||||
char *sqlite3StrDup_(const char*,char*,int);
|
||||
char *sqlite3StrNDup_(const char*, int,char*,int);
|
||||
void sqlite3CheckMemory(void*,int);
|
||||
void sqlite3FreeX(void *p);
|
||||
#else
|
||||
void *sqliteMalloc(int);
|
||||
void *sqliteMallocRaw(int);
|
||||
@@ -1375,11 +1380,6 @@ char *sqlite3_snprintf(int,char*,const char*,...);
|
||||
int sqlite3GetInt32(const char *, int*);
|
||||
int sqlite3GetInt64(const char *, i64*);
|
||||
int sqlite3FitsIn64Bits(const char *);
|
||||
unsigned char *sqlite3utf16to8(const void *pData, int N, int big_endian);
|
||||
void *sqlite3utf8to16be(const unsigned char *pIn, int N);
|
||||
void *sqlite3utf8to16le(const unsigned char *pIn, int N);
|
||||
void sqlite3utf16to16le(void *pData, int N);
|
||||
void sqlite3utf16to16be(void *pData, int N);
|
||||
int sqlite3utf16ByteLen(const void *pData, int nChar);
|
||||
int sqlite3utf8CharLen(const char *pData, int nByte);
|
||||
int sqlite3utf8LikeCompare(const unsigned char*, const unsigned char*);
|
||||
@@ -1396,8 +1396,6 @@ int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
|
||||
char sqlite3ExprAffinity(Expr *pExpr);
|
||||
int sqlite3atoi64(const char*, i64*);
|
||||
void sqlite3Error(sqlite *, int, const char*,...);
|
||||
int sqlite3utfTranslate(const void *, int , u8 , void **, int *, u8);
|
||||
u8 sqlite3UtfReadBom(const void *zData, int nData);
|
||||
void *sqlite3HexToBlob(const char *z);
|
||||
int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
|
||||
const char *sqlite3ErrStr(int);
|
||||
@@ -1412,6 +1410,7 @@ int sqlite3CheckObjectName(Parse *, const char *);
|
||||
|
||||
const void *sqlite3ValueText(sqlite3_value*, u8);
|
||||
int sqlite3ValueBytes(sqlite3_value*, u8);
|
||||
void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8);
|
||||
void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, void(*)(void*));
|
||||
void sqlite3ValueFree(sqlite3_value*);
|
||||
sqlite3_value *sqlite3ValueNew();
|
||||
sqlite3_value *sqlite3GetTransientValue(sqlite *db);
|
||||
|
||||
+3
-3
@@ -13,7 +13,7 @@
|
||||
** is not included in the SQLite library. It is used for automated
|
||||
** testing of the SQLite library.
|
||||
**
|
||||
** $Id: test1.c,v 1.77 2004/06/15 02:44:19 danielk1977 Exp $
|
||||
** $Id: test1.c,v 1.78 2004/06/18 04:24:55 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "tcl.h"
|
||||
@@ -940,9 +940,9 @@ static int test_collate_func(
|
||||
}
|
||||
|
||||
pVal = sqlite3ValueNew();
|
||||
sqlite3ValueSetStr(pVal, nA, zA, encin);
|
||||
sqlite3ValueSetStr(pVal, nA, zA, encin, SQLITE_STATIC);
|
||||
Tcl_ListObjAppendElement(i,pX,Tcl_NewStringObj(sqlite3_value_text(pVal),-1));
|
||||
sqlite3ValueSetStr(pVal, nB, zB, encin);
|
||||
sqlite3ValueSetStr(pVal, nB, zB, encin, SQLITE_STATIC);
|
||||
Tcl_ListObjAppendElement(i,pX,Tcl_NewStringObj(sqlite3_value_text(pVal),-1));
|
||||
sqlite3ValueFree(pVal);
|
||||
|
||||
|
||||
+89
-195
@@ -15,7 +15,7 @@
|
||||
** is used for testing the SQLite routines for converting between
|
||||
** the various supported unicode encodings.
|
||||
**
|
||||
** $Id: test5.c,v 1.10 2004/06/12 00:42:35 danielk1977 Exp $
|
||||
** $Id: test5.c,v 1.11 2004/06/18 04:24:55 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "vdbeInt.h"
|
||||
@@ -24,195 +24,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
** Return the number of bytes up to and including the first pair of
|
||||
** 0x00 bytes in *pStr.
|
||||
*/
|
||||
static int utf16_length(const unsigned char *pZ){
|
||||
const unsigned char *pC1 = pZ;
|
||||
const unsigned char *pC2 = pZ+1;
|
||||
while( *pC1 || *pC2 ){
|
||||
pC1 += 2;
|
||||
pC2 += 2;
|
||||
}
|
||||
return (pC1-pZ)+2;
|
||||
}
|
||||
|
||||
/*
|
||||
** tclcmd: sqlite_utf8to16le STRING
|
||||
** title: Convert STRING from utf-8 to utf-16le
|
||||
**
|
||||
** Return the utf-16le encoded string
|
||||
*/
|
||||
static int sqlite_utf8to16le(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
unsigned char *out;
|
||||
unsigned char *in;
|
||||
Tcl_Obj *res;
|
||||
|
||||
if( objc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
||||
Tcl_GetStringFromObj(objv[0], 0), "<utf-8 encoded-string>", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
in = Tcl_GetString(objv[1]);
|
||||
out = (unsigned char *)sqlite3utf8to16le(in, -1);
|
||||
res = Tcl_NewByteArrayObj(out, utf16_length(out));
|
||||
sqliteFree(out);
|
||||
|
||||
Tcl_SetObjResult(interp, res);
|
||||
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** tclcmd: sqlite_utf8to16be STRING
|
||||
** title: Convert STRING from utf-8 to utf-16be
|
||||
**
|
||||
** Return the utf-16be encoded string
|
||||
*/
|
||||
static int sqlite_utf8to16be(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
unsigned char *out;
|
||||
unsigned char *in;
|
||||
Tcl_Obj *res;
|
||||
|
||||
if( objc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
||||
Tcl_GetStringFromObj(objv[0], 0), "<utf-8 encoded-string>", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
in = Tcl_GetByteArrayFromObj(objv[1], 0);
|
||||
in = Tcl_GetString(objv[1]);
|
||||
out = (unsigned char *)sqlite3utf8to16be(in, -1);
|
||||
res = Tcl_NewByteArrayObj(out, utf16_length(out));
|
||||
sqliteFree(out);
|
||||
|
||||
Tcl_SetObjResult(interp, res);
|
||||
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** tclcmd: sqlite_utf16to16le STRING
|
||||
** title: Convert STRING from utf-16 in native byte order to utf-16le
|
||||
**
|
||||
** Return the utf-16le encoded string. If the input string contains
|
||||
** a byte-order mark, then the byte order mark should override the
|
||||
** native byte order.
|
||||
*/
|
||||
static int sqlite_utf16to16le(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
unsigned char *out;
|
||||
unsigned char *in;
|
||||
int in_len;
|
||||
Tcl_Obj *res;
|
||||
|
||||
if( objc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
||||
Tcl_GetStringFromObj(objv[0], 0), "<utf-16 encoded-string>", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
in = Tcl_GetByteArrayFromObj(objv[1], &in_len);
|
||||
out = (unsigned char *)sqliteMalloc(in_len);
|
||||
memcpy(out, in, in_len);
|
||||
|
||||
sqlite3utf16to16le(out, -1);
|
||||
res = Tcl_NewByteArrayObj(out, utf16_length(out));
|
||||
sqliteFree(out);
|
||||
|
||||
Tcl_SetObjResult(interp, res);
|
||||
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** tclcmd: sqlite_utf16to16be STRING
|
||||
** title: Convert STRING from utf-16 in native byte order to utf-16be
|
||||
**
|
||||
** Return the utf-16be encoded string. If the input string contains
|
||||
** a byte-order mark, then the byte order mark should override the
|
||||
** native byte order.
|
||||
*/
|
||||
static int sqlite_utf16to16be(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
unsigned char *out;
|
||||
unsigned char *in;
|
||||
int in_len;
|
||||
Tcl_Obj *res;
|
||||
|
||||
if( objc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
||||
Tcl_GetStringFromObj(objv[0], 0), "<utf-16 encoded-string>", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
in = Tcl_GetByteArrayFromObj(objv[1], &in_len);
|
||||
out = (unsigned char *)sqliteMalloc(in_len);
|
||||
memcpy(out, in, in_len);
|
||||
|
||||
sqlite3utf16to16be(out, -1);
|
||||
res = Tcl_NewByteArrayObj(out, utf16_length(out));
|
||||
sqliteFree(out);
|
||||
|
||||
Tcl_SetObjResult(interp, res);
|
||||
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** tclcmd: sqlite_utf16to8 STRING
|
||||
** title: Convert STRING from utf-16 in native byte order to utf-8
|
||||
**
|
||||
** Return the utf-8 encoded string. If the input string contains
|
||||
** a byte-order mark, then the byte order mark should override the
|
||||
** native byte order.
|
||||
*/
|
||||
static int sqlite_utf16to8(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
unsigned char *out;
|
||||
unsigned char *in;
|
||||
Tcl_Obj *res;
|
||||
|
||||
if( objc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
||||
Tcl_GetStringFromObj(objv[0], 0), " <utf-16 encoded-string>", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
in = Tcl_GetByteArrayFromObj(objv[1], 0);
|
||||
out = sqlite3utf16to8(in, -1, SQLITE_BIGENDIAN);
|
||||
res = Tcl_NewByteArrayObj(out, strlen(out)+1);
|
||||
sqliteFree(out);
|
||||
|
||||
Tcl_SetObjResult(interp, res);
|
||||
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** The first argument is a TCL UTF-8 string. Return the byte array
|
||||
** object with the encoded representation of the string, including
|
||||
@@ -281,6 +92,92 @@ static int test_value_overhead(
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
static u8 name_to_enc(Tcl_Interp *interp, Tcl_Obj *pObj){
|
||||
struct EncName {
|
||||
char *zName;
|
||||
u8 enc;
|
||||
} encnames[] = {
|
||||
{ "UTF8", SQLITE_UTF8 },
|
||||
{ "UTF16LE", SQLITE_UTF16LE },
|
||||
{ "UTF16BE", SQLITE_UTF16BE },
|
||||
{ "UTF16", SQLITE_UTF16NATIVE },
|
||||
{ 0, 0 }
|
||||
};
|
||||
struct EncName *pEnc;
|
||||
char *z = Tcl_GetString(pObj);
|
||||
for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
|
||||
if( 0==sqlite3StrICmp(z, pEnc->zName) ){
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( !pEnc->enc ){
|
||||
Tcl_AppendResult(interp, "No such encoding: ", z, 0);
|
||||
}
|
||||
return pEnc->enc;
|
||||
}
|
||||
|
||||
static int test_translate(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
u8 enc_from;
|
||||
u8 enc_to;
|
||||
sqlite3_value *pVal;
|
||||
|
||||
const char *z;
|
||||
int len;
|
||||
|
||||
if( objc!=4 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
||||
Tcl_GetStringFromObj(objv[0], 0),
|
||||
" <string/blob> <from enc> <to enc>", 0
|
||||
);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
enc_from = name_to_enc(interp, objv[2]);
|
||||
if( !enc_from ) return TCL_ERROR;
|
||||
enc_to = name_to_enc(interp, objv[3]);
|
||||
if( !enc_to ) return TCL_ERROR;
|
||||
|
||||
pVal = sqlite3ValueNew();
|
||||
|
||||
if( enc_from==SQLITE_UTF8 ){
|
||||
z = Tcl_GetString(objv[1]);
|
||||
sqlite3ValueSetStr(pVal, -1, z, enc_from, SQLITE_STATIC);
|
||||
}else{
|
||||
z = Tcl_GetByteArrayFromObj(objv[1], &len);
|
||||
sqlite3ValueSetStr(pVal, -1, z, enc_from, SQLITE_STATIC);
|
||||
}
|
||||
|
||||
z = sqlite3ValueText(pVal, enc_to);
|
||||
len = sqlite3ValueBytes(pVal, enc_to) + (enc_to==SQLITE_UTF8?1:2);
|
||||
Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(z, len));
|
||||
|
||||
sqlite3ValueFree(pVal);
|
||||
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: translate_selftest
|
||||
**
|
||||
** Call sqlite3utfSelfTest() to run the internal tests for unicode
|
||||
** translation. If there is a problem an assert() will fail.
|
||||
**/
|
||||
void sqlite3utfSelfTest();
|
||||
static int test_translate_selftest(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
sqlite3utfSelfTest();
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Register commands with the TCL interpreter.
|
||||
@@ -290,13 +187,10 @@ int Sqlitetest5_Init(Tcl_Interp *interp){
|
||||
char *zName;
|
||||
Tcl_ObjCmdProc *xProc;
|
||||
} aCmd[] = {
|
||||
{ "sqlite_utf16to8", (Tcl_ObjCmdProc*)sqlite_utf16to8 },
|
||||
{ "sqlite_utf8to16le", (Tcl_ObjCmdProc*)sqlite_utf8to16le },
|
||||
{ "sqlite_utf8to16be", (Tcl_ObjCmdProc*)sqlite_utf8to16be },
|
||||
{ "sqlite_utf16to16le", (Tcl_ObjCmdProc*)sqlite_utf16to16le },
|
||||
{ "sqlite_utf16to16be", (Tcl_ObjCmdProc*)sqlite_utf16to16be },
|
||||
{ "binarize", (Tcl_ObjCmdProc*)binarize },
|
||||
{ "test_value_overhead", (Tcl_ObjCmdProc*)test_value_overhead },
|
||||
{ "test_translate", (Tcl_ObjCmdProc*)test_translate },
|
||||
{ "translate_selftest", (Tcl_ObjCmdProc*)test_translate_selftest},
|
||||
};
|
||||
int i;
|
||||
for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){
|
||||
|
||||
+14
-6
@@ -15,7 +15,7 @@
|
||||
** individual tokens and sends those tokens one-by-one over to the
|
||||
** parser for analysis.
|
||||
**
|
||||
** $Id: tokenize.c,v 1.76 2004/05/31 23:56:43 danielk1977 Exp $
|
||||
** $Id: tokenize.c,v 1.77 2004/06/18 04:24:55 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
@@ -701,10 +701,18 @@ int sqlite3_complete(const char *zSql){
|
||||
** UTF-8.
|
||||
*/
|
||||
int sqlite3_complete16(const void *zSql){
|
||||
int rc;
|
||||
char *zSql8 = sqlite3utf16to8(zSql, -1, SQLITE_BIGENDIAN);
|
||||
if( !zSql8 ) return 0;
|
||||
rc = sqlite3_complete(zSql8);
|
||||
sqliteFree(zSql8);
|
||||
sqlite3_value *pVal;
|
||||
char *zSql8;
|
||||
int rc = 0;
|
||||
|
||||
pVal = sqlite3ValueNew();
|
||||
sqlite3ValueSetStr(pVal, -1, zSql, SQLITE_UTF16NATIVE, SQLITE_STATIC);
|
||||
zSql8 = sqlite3ValueText(pVal, SQLITE_UTF8);
|
||||
if( zSql8 ){
|
||||
rc = sqlite3_complete(zSql8);
|
||||
sqliteFree(zSql8);
|
||||
}
|
||||
sqlite3ValueFree(pVal);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
+20
-18
@@ -14,7 +14,7 @@
|
||||
** This file contains functions for allocating memory, comparing
|
||||
** strings, and stuff like that.
|
||||
**
|
||||
** $Id: util.c,v 1.102 2004/06/16 07:45:29 danielk1977 Exp $
|
||||
** $Id: util.c,v 1.103 2004/06/18 04:24:55 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <stdarg.h>
|
||||
@@ -256,6 +256,13 @@ char *sqlite3StrNDup_(const char *z, int n, char *zFile, int line){
|
||||
}
|
||||
return zNew;
|
||||
}
|
||||
|
||||
/*
|
||||
** A version of sqliteFree that is always a function, not a macro.
|
||||
*/
|
||||
void sqlite3FreeX(void *p){
|
||||
sqliteFree(p);
|
||||
}
|
||||
#endif /* SQLITE_DEBUG */
|
||||
|
||||
/*
|
||||
@@ -446,23 +453,18 @@ void sqlite3SetNString(char **pz, ...){
|
||||
** to NULL.
|
||||
*/
|
||||
void sqlite3Error(sqlite *db, int err_code, const char *zFormat, ...){
|
||||
/* Free any existing error message. */
|
||||
if( db->zErrMsg ){
|
||||
sqliteFree(db->zErrMsg);
|
||||
db->zErrMsg = 0;
|
||||
}
|
||||
if( db->zErrMsg16 ){
|
||||
sqliteFree(db->zErrMsg16);
|
||||
db->zErrMsg16 = 0;
|
||||
}
|
||||
|
||||
/* Set the new error code and error message. */
|
||||
db->errCode = err_code;
|
||||
if( zFormat ){
|
||||
va_list ap;
|
||||
va_start(ap, zFormat);
|
||||
db->zErrMsg = sqlite3VMPrintf(zFormat, ap);
|
||||
va_end(ap);
|
||||
if( db && (db->pErr || (db->pErr = sqlite3ValueNew())) ){
|
||||
db->errCode = err_code;
|
||||
if( zFormat ){
|
||||
char *z;
|
||||
va_list ap;
|
||||
va_start(ap, zFormat);
|
||||
z = sqlite3VMPrintf(zFormat, ap);
|
||||
va_end(ap);
|
||||
sqlite3ValueSetStr(db->pErr, -1, z, SQLITE_UTF8, sqlite3FreeX);
|
||||
}else{
|
||||
sqlite3ValueSetStr(db->pErr, 0, 0, SQLITE_UTF8, SQLITE_STATIC);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+16
-23
@@ -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.378 2004/06/17 07:53:03 danielk1977 Exp $
|
||||
** $Id: vdbe.c,v 1.379 2004/06/18 04:24:55 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "os.h"
|
||||
@@ -361,10 +361,12 @@ static void applyAffinity(Mem *pRec, char affinity, u8 enc){
|
||||
** Write a nice string representation of the contents of cell pMem
|
||||
** into buffer zBuf, length nBuf.
|
||||
*/
|
||||
void prettyPrintMem(Mem *pMem, char *zBuf, int nBuf){
|
||||
void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf, int nBuf){
|
||||
char *zCsr = zBuf;
|
||||
int f = pMem->flags;
|
||||
|
||||
static const char *encnames[] = {"(X)", "(8)", "(16LE)", "(16BE)"};
|
||||
|
||||
if( f&MEM_Blob ){
|
||||
int i;
|
||||
char c;
|
||||
@@ -414,11 +416,6 @@ void prettyPrintMem(Mem *pMem, char *zBuf, int nBuf){
|
||||
zBuf[k++] = '[';
|
||||
for(j=0; j<15 && j<pMem->n; j++){
|
||||
u8 c = pMem->z[j];
|
||||
/*
|
||||
if( c==0 && j==pMem->n-1 ) break;
|
||||
zBuf[k++] = "0123456789ABCDEF"[c>>4];
|
||||
zBuf[k++] = "0123456789ABCDEF"[c&0xf];
|
||||
*/
|
||||
if( c>=0x20 && c<0x7f ){
|
||||
zBuf[k++] = c;
|
||||
}else{
|
||||
@@ -426,14 +423,10 @@ void prettyPrintMem(Mem *pMem, char *zBuf, int nBuf){
|
||||
}
|
||||
}
|
||||
zBuf[k++] = ']';
|
||||
k += sprintf(&zBuf[k], encnames[pMem->enc]);
|
||||
zBuf[k++] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Temporary - this is useful in conjunction with prettyPrintMem whilst
|
||||
** debugging.
|
||||
*/
|
||||
char zGdbBuf[100];
|
||||
#endif
|
||||
|
||||
|
||||
@@ -734,20 +727,20 @@ case OP_String8: {
|
||||
pOp->opcode = OP_String;
|
||||
|
||||
if( db->enc!=SQLITE_UTF8 && pOp->p3 ){
|
||||
char *z = pOp->p3;
|
||||
if( db->enc==SQLITE_UTF16LE ){
|
||||
pOp->p3 = sqlite3utf8to16le(z, -1);
|
||||
}else{
|
||||
pOp->p3 = sqlite3utf8to16be(z, -1);
|
||||
}
|
||||
pTos++;
|
||||
sqlite3VdbeMemSetStr(pTos, pOp->p3, -1, SQLITE_UTF8, SQLITE_STATIC);
|
||||
if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pTos, db->enc) ) goto no_mem;
|
||||
if( SQLITE_OK!=sqlite3VdbeMemDynamicify(pTos) ) goto no_mem;
|
||||
pTos->flags &= ~(MEM_Dyn);
|
||||
pTos->flags |= MEM_Static;
|
||||
if( pOp->p3type==P3_DYNAMIC ){
|
||||
sqliteFree(z);
|
||||
sqliteFree(pOp->p3);
|
||||
}
|
||||
pOp->p3type = P3_DYNAMIC;
|
||||
if( !pOp->p3 ) goto no_mem;
|
||||
pOp->p3 = pTos->z;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Fall through to the next case, OP_String */
|
||||
/* Otherwise fall through to the next case, OP_String */
|
||||
}
|
||||
|
||||
/* Opcode: String * * P3
|
||||
@@ -4590,7 +4583,7 @@ default: {
|
||||
fprintf(p->trace, " r:%g", pTos[i].r);
|
||||
}else{
|
||||
char zBuf[100];
|
||||
prettyPrintMem(&pTos[i], zBuf, 100);
|
||||
sqlite3VdbeMemPrettyPrint(&pTos[i], zBuf, 100);
|
||||
fprintf(p->trace, " ");
|
||||
fprintf(p->trace, zBuf);
|
||||
}
|
||||
|
||||
@@ -390,3 +390,5 @@ void sqlite3VdbeMemRelease(Mem *p);
|
||||
#ifndef NDEBUG
|
||||
void sqlite3VdbeMemSanity(Mem*, u8);
|
||||
#endif
|
||||
int sqlite3VdbeMemTranslate(Mem*, u8);
|
||||
void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf, int nBuf);
|
||||
|
||||
+1
-14
@@ -518,20 +518,7 @@ int sqlite3_bind_text16(
|
||||
}
|
||||
pVar = &p->apVar[i-1];
|
||||
|
||||
/* There may or may not be a byte order mark at the start of the UTF-16.
|
||||
** Either way set 'txt_enc' to the SQLITE_UTF16* value indicating the
|
||||
** actual byte order used by this string. If the string does happen
|
||||
** to contain a BOM, then move zData so that it points to the first
|
||||
** byte after the BOM.
|
||||
*/
|
||||
txt_enc = sqlite3UtfReadBom(zData, nData);
|
||||
if( txt_enc ){
|
||||
zData = (void *)(((u8 *)zData) + 2);
|
||||
nData -= 2;
|
||||
}else{
|
||||
txt_enc = SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE;
|
||||
}
|
||||
rc = sqlite3VdbeMemSetStr(pVar, zData, nData, txt_enc, xDel);
|
||||
rc = sqlite3VdbeMemSetStr(pVar, zData, nData, SQLITE_UTF16NATIVE, xDel);
|
||||
if( rc ){
|
||||
return rc;
|
||||
}
|
||||
|
||||
+28
-65
@@ -21,63 +21,23 @@
|
||||
#include "vdbeInt.h"
|
||||
|
||||
/*
|
||||
** If pMem is a string object, this routine sets the encoding of the string
|
||||
** (to one of UTF-8 or UTF16) and whether or not the string is
|
||||
** nul-terminated. If pMem is not a string object, then this routine is
|
||||
** a no-op.
|
||||
** If pMem is an object with a valid string representation, this routine
|
||||
** ensures the internal encoding for the string representation is
|
||||
** 'desiredEnc', one of SQLITE_UTF8, SQLITE_UTF16LE or SQLITE_UTF16BE.
|
||||
**
|
||||
** The second argument, "desiredEnc" is one of TEXT_Utf8, TEXT_Utf16le
|
||||
** or TEXT_Utf16be. This routine changes the encoding of pMem to match
|
||||
** desiredEnc.
|
||||
** If pMem is not a string object, or the encoding of the string
|
||||
** representation is already stored using the requested encoding, then this
|
||||
** routine is a no-op.
|
||||
**
|
||||
** SQLITE_OK is returned if the conversion is successful (or not required).
|
||||
** SQLITE_NOMEM may be returned if a malloc() fails during conversion
|
||||
** between formats.
|
||||
*/
|
||||
int sqlite3VdbeChangeEncoding(Mem *pMem, int desiredEnc){
|
||||
/* If this is not a string, or if it is a string but the encoding is
|
||||
** already correct, do nothing. */
|
||||
if( !(pMem->flags&MEM_Str) || pMem->enc==desiredEnc ){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
if( pMem->enc==SQLITE_UTF8 || desiredEnc==SQLITE_UTF8 ){
|
||||
/* If the current encoding does not match the desired encoding, then
|
||||
** we will need to do some translation between encodings.
|
||||
*/
|
||||
char *z;
|
||||
int n;
|
||||
int rc;
|
||||
|
||||
rc = sqlite3utfTranslate(pMem->z, pMem->n, pMem->enc, (void **)&z,
|
||||
&n, desiredEnc);
|
||||
if( rc!=SQLITE_OK ){
|
||||
return rc;
|
||||
}
|
||||
sqlite3VdbeMemRelease(pMem);
|
||||
|
||||
/* Result of sqlite3utfTranslate is currently always dynamically
|
||||
** allocated and nul terminated. This might be altered as a performance
|
||||
** enhancement later.
|
||||
*/
|
||||
pMem->z = z;
|
||||
pMem->n = n;
|
||||
pMem->flags &= ~(MEM_Ephem | MEM_Short | MEM_Static);
|
||||
pMem->flags |= MEM_Str | MEM_Dyn | MEM_Term;
|
||||
pMem->xDel = 0;
|
||||
}else{
|
||||
/* Must be translating between UTF-16le and UTF-16be. */
|
||||
int i;
|
||||
u8 *pFrom, *pTo;
|
||||
sqlite3VdbeMemMakeWriteable(pMem);
|
||||
for(i=0, pFrom=pMem->z, pTo=&pMem->z[1]; i<pMem->n; i+=2, pFrom+=2,pTo+=2){
|
||||
u8 temp = *pFrom;
|
||||
*pFrom = *pTo;
|
||||
*pTo = temp;
|
||||
}
|
||||
}
|
||||
pMem->enc = desiredEnc;
|
||||
return SQLITE_OK;
|
||||
return sqlite3VdbeMemTranslate(pMem, desiredEnc);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -405,16 +365,19 @@ int sqlite3VdbeMemSetStr(
|
||||
case SQLITE_UTF16LE:
|
||||
case SQLITE_UTF16BE:
|
||||
pMem->flags |= MEM_Str;
|
||||
if( n<0 ){
|
||||
pMem->n = sqlite3utf16ByteLen(z,-1);
|
||||
if( pMem->n<0 ){
|
||||
pMem->n = sqlite3utf16ByteLen(pMem->z,-1);
|
||||
pMem->flags |= MEM_Term;
|
||||
}
|
||||
if( sqlite3VdbeMemHandleBom(pMem) ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
if( xDel==SQLITE_TRANSIENT ){
|
||||
if( pMem->flags&MEM_Ephem ){
|
||||
return sqlite3VdbeMemMakeWriteable(pMem);
|
||||
}
|
||||
return SQLITE_OK;
|
||||
@@ -498,11 +461,9 @@ int sqlite3MemCompare(const Mem *pMem1, const Mem *pMem2, const CollSeq *pColl){
|
||||
assert( pMem1->enc==SQLITE_UTF8 ||
|
||||
pMem1->enc==SQLITE_UTF16LE || pMem1->enc==SQLITE_UTF16BE );
|
||||
|
||||
/* FIX ME: This may fail if the collation sequence is deleted after
|
||||
** this vdbe program is compiled. We cannot just use BINARY in this
|
||||
** case as this may lead to a segfault caused by traversing an index
|
||||
** table incorrectly. We need to return an error to the user in this
|
||||
** case.
|
||||
/* This assert may fail if the collation sequence is deleted after this
|
||||
** vdbe program is compiled. The documentation defines this as an
|
||||
** undefined condition. A crash is usual result.
|
||||
*/
|
||||
assert( !pColl || pColl->xCmp );
|
||||
|
||||
@@ -645,22 +606,17 @@ void sqlite3VdbeMemSanity(Mem *pMem, u8 db_enc){
|
||||
** SQLITE_UTF8.
|
||||
*/
|
||||
const void *sqlite3ValueText(sqlite3_value* pVal, u8 enc){
|
||||
if( !pVal ) return 0;
|
||||
assert( enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE || enc==SQLITE_UTF8);
|
||||
|
||||
if( pVal->flags&MEM_Null ){
|
||||
/* For a NULL return a NULL Pointer */
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( pVal->flags&MEM_Str ){
|
||||
/* If there is already a string representation, make sure it is in
|
||||
** encoded in the required UTF-16 byte order.
|
||||
*/
|
||||
sqlite3VdbeChangeEncoding(pVal, enc);
|
||||
}else if( !(pVal->flags&MEM_Blob) ){
|
||||
/* Otherwise, unless this is a blob, convert it to a UTF-16 string */
|
||||
sqlite3VdbeMemStringify(pVal, enc);
|
||||
}
|
||||
|
||||
return (const void *)(pVal->z);
|
||||
}
|
||||
|
||||
@@ -673,12 +629,19 @@ sqlite3_value* sqlite3ValueNew(){
|
||||
return p;
|
||||
}
|
||||
|
||||
void sqlite3ValueSetStr(sqlite3_value *v, int n, const void *z, u8 enc){
|
||||
sqlite3VdbeMemSetStr((Mem *)v, z, n, enc, SQLITE_STATIC);
|
||||
void sqlite3ValueSetStr(
|
||||
sqlite3_value *v,
|
||||
int n,
|
||||
const void *z,
|
||||
u8 enc,
|
||||
void (*xDel)(void*)
|
||||
){
|
||||
if( v ) sqlite3VdbeMemSetStr((Mem *)v, z, n, enc, xDel);
|
||||
}
|
||||
|
||||
void sqlite3ValueFree(sqlite3_value *v){
|
||||
sqlite3ValueSetStr(v, 0, 0, SQLITE_UTF8);
|
||||
if( !v ) return;
|
||||
sqlite3ValueSetStr(v, 0, 0, SQLITE_UTF8, SQLITE_STATIC);
|
||||
sqliteFree(v);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user