Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Properly zero-terminate UTF-16 collation names on an sqlite3_collation_needed16 callback. (CVS 2815) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
71a49d05bf174025c0d9141b8905c48f |
User & Date: | drh 2005-12-14 20:11:30.000 |
Context
2005-12-14
| ||
22:51 | Avoid using the transient value in the UTF-16 collation needed callback. (CVS 2816) (check-in: ab6241af29 user: drh tags: trunk) | |
20:11 | Properly zero-terminate UTF-16 collation names on an sqlite3_collation_needed16 callback. (CVS 2815) (check-in: 71a49d05bf user: drh tags: trunk) | |
2005-12-12
| ||
06:53 | Fix minor malloc() related problems and add sqlite3_soft_heap_limit() stubs. (CVS 2814) (check-in: 1637f37960 user: danielk1977 tags: trunk) | |
Changes
Changes to src/callback.c.
︙ | ︙ | |||
9 10 11 12 13 14 15 | ** May you share freely, never taking more than you give. ** ************************************************************************* ** ** This file contains functions used to access the internal hash tables ** of user defined functions and collation sequences. ** | | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ** May you share freely, never taking more than you give. ** ************************************************************************* ** ** This file contains functions used to access the internal hash tables ** of user defined functions and collation sequences. ** ** $Id: callback.c,v 1.6 2005/12/14 20:11:30 drh Exp $ */ #include "sqliteInt.h" /* ** Invoke the 'collation needed' callback to request a collation sequence ** in the database text encoding of name zName, length nName. |
︙ | ︙ | |||
32 33 34 35 36 37 38 | db->xCollNeeded(db->pCollNeededArg, db, (int)db->enc, zExternal); sqliteFree(zExternal); } #ifndef SQLITE_OMIT_UTF16 if( db->xCollNeeded16 ){ char const *zExternal; sqlite3_value *pTmp = sqlite3GetTransientValue(db); | | | 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | db->xCollNeeded(db->pCollNeededArg, db, (int)db->enc, zExternal); sqliteFree(zExternal); } #ifndef SQLITE_OMIT_UTF16 if( db->xCollNeeded16 ){ char const *zExternal; sqlite3_value *pTmp = sqlite3GetTransientValue(db); 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); } #endif } |
︙ | ︙ |
Changes to src/test1.c.
︙ | ︙ | |||
9 10 11 12 13 14 15 | ** May you share freely, never taking more than you give. ** ************************************************************************* ** Code for testing the printf() interface to SQLite. This code ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** | | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ** May you share freely, never taking more than you give. ** ************************************************************************* ** Code for testing the printf() interface to SQLite. This code ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** ** $Id: test1.c,v 1.176 2005/12/14 20:11:30 drh Exp $ */ #include "sqliteInt.h" #include "tcl.h" #include "os.h" #include <stdlib.h> #include <string.h> |
︙ | ︙ | |||
1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 | bad_args: Tcl_AppendResult(interp, "wrong # args: should be \"", Tcl_GetStringFromObj(objv[0], 0), " <DB> <utf8> <utf16le> <utf16be>", 0); return TCL_ERROR; } static void test_collate_needed_cb( void *pCtx, sqlite3 *db, int eTextRep, | > > > > > > > > > > > > > > | > > > > > > > | 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 | bad_args: Tcl_AppendResult(interp, "wrong # args: should be \"", Tcl_GetStringFromObj(objv[0], 0), " <DB> <utf8> <utf16le> <utf16be>", 0); 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 *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); } /* ** Usage: add_test_collate_needed DB */ static int test_collate_needed( void * clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[] ){ sqlite3 *db; int rc; 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; bad_args: Tcl_WrongNumArgs(interp, 1, objv, "DB"); return TCL_ERROR; } |
︙ | ︙ | |||
3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 | (char*)&sqlite3_interrupt_count, TCL_LINK_INT); Tcl_LinkVar(interp, "sqlite_open_file_count", (char*)&sqlite3_open_file_count, TCL_LINK_INT); Tcl_LinkVar(interp, "sqlite_current_time", (char*)&sqlite3_current_time, TCL_LINK_INT); Tcl_LinkVar(interp, "sqlite_os_trace", (char*)&sqlite3_os_trace, TCL_LINK_INT); #ifdef SQLITE_MEMDEBUG Tcl_LinkVar(interp, "sqlite_malloc_id", (char*)&sqlite3_malloc_id, TCL_LINK_STRING); #endif #if OS_WIN Tcl_LinkVar(interp, "sqlite_os_type", (char*)&sqlite3_os_type, TCL_LINK_INT); | > > > > | 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 | (char*)&sqlite3_interrupt_count, TCL_LINK_INT); Tcl_LinkVar(interp, "sqlite_open_file_count", (char*)&sqlite3_open_file_count, TCL_LINK_INT); Tcl_LinkVar(interp, "sqlite_current_time", (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); #endif #if OS_WIN Tcl_LinkVar(interp, "sqlite_os_type", (char*)&sqlite3_os_type, TCL_LINK_INT); |
︙ | ︙ |
Changes to test/enc2.test.
︙ | ︙ | |||
9 10 11 12 13 14 15 | # #*********************************************************************** # This file implements regression tests for SQLite library. The focus of # this file is testing the SQLite routines used for converting between the # various suported unicode encodings (UTF-8, UTF-16, UTF-16le and # UTF-16be). # | | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | # #*********************************************************************** # This file implements regression tests for SQLite library. The focus of # this file is testing the SQLite routines used for converting between the # various suported unicode encodings (UTF-8, UTF-16, UTF-16le and # UTF-16be). # # $Id: enc2.test,v 1.24 2005/12/14 20:11:31 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # If UTF16 support is disabled, ignore the tests in this file # ifcapable {!utf16} { |
︙ | ︙ | |||
199 200 201 202 203 204 205 | INSERT INTO t5 VALUES('five'); INSERT INTO t5 VALUES('three'); INSERT INTO t5 VALUES('four'); } } {} do_test enc2-5.1 { add_test_collate $DB 1 1 1 | | | 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | INSERT INTO t5 VALUES('five'); INSERT INTO t5 VALUES('three'); INSERT INTO t5 VALUES('four'); } } {} do_test enc2-5.1 { add_test_collate $DB 1 1 1 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 { add_test_collate $DB 0 1 0 set res [execsql {SELECT * FROM t5 ORDER BY 1 COLLATE test_collate}] lappend res $::test_collate_enc } {one two three four five UTF-16LE} |
︙ | ︙ | |||
282 283 284 285 286 287 288 | add_test_collate $DB 0 0 0 catchsql { SELECT * FROM t5 ORDER BY 1 COLLATE test_collate } } {1 {no such collation sequence: test_collate}} do_test enc2-5.13 { add_test_collate_needed $DB | | > > > > > > > > > > > > > > > | 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | add_test_collate $DB 0 0 0 catchsql { SELECT * FROM t5 ORDER BY 1 COLLATE test_collate } } {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; }] 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. proc test_function {enc arg} { return "$enc $arg" } |
︙ | ︙ |