Properly zero-terminate UTF-16 collation names on an

sqlite3_collation_needed16 callback. (CVS 2815)

FossilOrigin-Name: 71a49d05bf174025c0d9141b8905c48f43e42541
This commit is contained in:
drh 2005-12-14 20:11:30 +00:00
parent 7ddad969a4
commit 268803a95b
5 changed files with 57 additions and 17 deletions

View File

@ -1,5 +1,5 @@
C Fix\sminor\smalloc()\srelated\sproblems\sand\sadd\ssqlite3_soft_heap_limit()\sstubs.\s(CVS\s2814)
D 2005-12-12T06:53:04
C Properly\szero-terminate\sUTF-16\scollation\snames\son\san\nsqlite3_collation_needed16\scallback.\s(CVS\s2815)
D 2005-12-14T20:11:30
F Makefile.in e3c6b3a38d734d41574c04f2fc90d18de2b87102
F Makefile.linux-gcc aee18d8a05546dcf1888bd4547e442008a49a092
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@ -37,7 +37,7 @@ F src/auth.c 31e2304bef67f44d635655f44234387ea7d21454
F src/btree.c de0fc1a0f6a4631001ffb6070d1b7588cdebcbc5
F src/btree.h 1ed561263ca0e335bc3e81d761c9d5ff8c22f61e
F src/build.c 306dde3134acd8f1c9f3821d81c3cb598af91280
F src/callback.c 4bc404e9912eecb28be1235581833f6269920c27
F src/callback.c 16f8198d3c187daeccc7593edb7e06f9eb10c772
F src/complete.c df1681cef40dec33a286006981845f87b194e7a4
F src/date.c bb079317bff6a2b78aba5c0d2ddae5f6f03acfb7
F src/delete.c 6010a081edda9871895260def092e852f0bb60a0
@ -72,7 +72,7 @@ F src/sqlite.h.in a52db91dfa4f90e8e42361f6c7824c09b4e101ad
F src/sqliteInt.h 22b18da438fb1298bfd6ad1e2e3b5a2826100da8
F src/table.c 486dcfce532685b53b5a2b5da8bba0ded6fb2316
F src/tclsqlite.c c155bf5f9ce9ae8950037931f7f7efcc0d92d9c5
F src/test1.c e995c713219d93a022fd6228150b5340aebcf456
F src/test1.c d6924b182773b2ad3b22e435e4d3bfd5a846da9e
F src/test2.c 36390cdfc70c08e5ee0b466d0654a117f398bbff
F src/test3.c 7c97833e33496c2b69f4fe6b9882ac60a481da97
F src/test4.c a8fd681e139e1c61f22a77d07fc3a99cb28fff3f
@ -148,7 +148,7 @@ F test/delete3.test 555e84a00a99230b7d049d477a324a631126a6ab
F test/diskfull.test d828d72adfc9e2d1a194d25996718c1989152cf9
F test/distinctagg.test 2b89d1c5220d966a30ba4b40430338669301188b
F test/enc.test 7a03417a1051fe8bc6c7641cf4c8c3f7e0066d52
F test/enc2.test 76c13b8c00beaf95b15c152e95dab51292eb1f0d
F test/enc2.test c91d183cc9ba7f545fdc32e11d96ce507d07a11e
F test/enc3.test f6a5f0b7b7f3a88f030d3143729b87cd5c86d837
F test/expr.test 06381174d8c25fbbfd9ed335fe0cde835d39123d
F test/fkey1.test 153004438d51e6769fb1ce165f6313972d6263ce
@ -327,7 +327,7 @@ F www/tclsqlite.tcl ddcf912ea48695603c8ed7efb29f0812ef8d1b49
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
P 8a355d7aade5c7a95ab08aeedf1ee1857c121c33
R 75658ca824ff0ff17378f907ba53f1f6
U danielk1977
Z 573b0e314e198362cddb16601e85e971
P 1637f3796015d1582ed8c6bc8bdf8c067b4bade9
R 63c8dfd64520196af72348a822d41225
U drh
Z 0e5476dc8c71cffe7a1439467de52a42

View File

@ -1 +1 @@
1637f3796015d1582ed8c6bc8bdf8c067b4bade9
71a49d05bf174025c0d9141b8905c48f43e42541

View File

@ -13,7 +13,7 @@
** This file contains functions used to access the internal hash tables
** of user defined functions and collation sequences.
**
** $Id: callback.c,v 1.5 2005/12/06 12:52:59 danielk1977 Exp $
** $Id: callback.c,v 1.6 2005/12/14 20:11:30 drh Exp $
*/
#include "sqliteInt.h"
@ -36,7 +36,7 @@ static void callCollNeeded(sqlite3 *db, const char *zName, int nName){
if( db->xCollNeeded16 ){
char const *zExternal;
sqlite3_value *pTmp = sqlite3GetTransientValue(db);
sqlite3ValueSetStr(pTmp, -1, zName, SQLITE_UTF8, SQLITE_STATIC);
sqlite3ValueSetStr(pTmp, nName, zName, SQLITE_UTF8, SQLITE_STATIC);
zExternal = sqlite3ValueText(pTmp, SQLITE_UTF16NATIVE);
if( !zExternal ) return;
db->xCollNeeded16(db->pCollNeededArg, db, (int)db->enc, zExternal);

View File

@ -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.175 2005/12/12 06:53:05 danielk1977 Exp $
** $Id: test1.c,v 1.176 2005/12/14 20:11:30 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
@ -1232,13 +1232,33 @@ bad_args:
return TCL_ERROR;
}
/*
** When the collation needed callback is invoked, record the name of
** the requested collating function here. The recorded name is linked
** to a TCL variable and used to make sure that the requested collation
** name is correct.
*/
static char zNeededCollation[200];
static char *pzNeededCollation = zNeededCollation;
/*
** Called when a collating sequence is needed. Registered using
** sqlite3_collation_needed16().
*/
static void test_collate_needed_cb(
void *pCtx,
sqlite3 *db,
int eTextRep,
const void *notUsed
const void *pName
){
int enc = db->enc;
int i;
char *z;
for(z = (char*)pName, i=0; *z || z[1]; z++){
if( *z ) zNeededCollation[i++] = *z;
}
zNeededCollation[i] = 0;
sqlite3_create_collation(
db, "test_collate", db->enc, (void *)enc, test_collate_func);
}
@ -1258,6 +1278,7 @@ static int test_collate_needed(
if( objc!=2 ) goto bad_args;
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
rc = sqlite3_collation_needed16(db, 0, test_collate_needed_cb);
zNeededCollation[0] = 0;
if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
return TCL_OK;
@ -3222,6 +3243,10 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
(char*)&sqlite3_current_time, TCL_LINK_INT);
Tcl_LinkVar(interp, "sqlite_os_trace",
(char*)&sqlite3_os_trace, TCL_LINK_INT);
#ifndef SQLITE_OMIT_UTF16
Tcl_LinkVar(interp, "sqlite_last_needed_collation",
(char*)&pzNeededCollation, TCL_LINK_STRING|TCL_LINK_READ_ONLY);
#endif
#ifdef SQLITE_MEMDEBUG
Tcl_LinkVar(interp, "sqlite_malloc_id",
(char*)&sqlite3_malloc_id, TCL_LINK_STRING);

View File

@ -13,7 +13,7 @@
# various suported unicode encodings (UTF-8, UTF-16, UTF-16le and
# UTF-16be).
#
# $Id: enc2.test,v 1.23 2005/09/01 12:16:29 drh Exp $
# $Id: enc2.test,v 1.24 2005/12/14 20:11:31 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -203,7 +203,7 @@ do_test enc2-5.0 {
} {}
do_test enc2-5.1 {
add_test_collate $DB 1 1 1
set res [execsql {SELECT * FROM t5 ORDER BY 1 COLLATE test_collate}]
set res [execsql {SELECT * FROM t5 ORDER BY 1 COLLATE test_collate;}]
lappend res $::test_collate_enc
} {one two three four five UTF-8}
do_test enc2-5.2 {
@ -286,13 +286,28 @@ do_test enc2-5-12 {
} {1 {no such collation sequence: test_collate}}
do_test enc2-5.13 {
add_test_collate_needed $DB
set res [execsql {SELECT * FROM t5 ORDER BY 1 COLLATE test_collate}]
set res [execsql {SELECT * FROM t5 ORDER BY 1 COLLATE test_collate; }]
lappend res $::test_collate_enc
} {one two three four five UTF-16BE}
do_test enc2-5.14 {
set ::sqlite_last_needed_collation
} test_collate
db close
file delete -force test.db
do_test enc2-5.15 {
set ::DB [sqlite3 db test.db]
add_test_collate_needed $::DB
set ::sqlite_last_needed_collation
} {}
do_test enc2-5.16 {
execsql {CREATE TABLE t1(a varchar collate test_collate);}
} {}
do_test enc2-5.17 {
set ::sqlite_last_needed_collation
} {test_collate}
# The following tests - enc2-6.* - test that SQLite selects the correct
# user function when more than one is available.