/ Check-in [6c5c11e0]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Minor fixes for UTF-16 databases. (CVS 1770)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 6c5c11e07e157c15cf99078fce2a1bc478e287ce
User & Date: danielk1977 2004-06-30 02:35:51
Context
2004-06-30
02:43
Allow strings that look like integers to be inserted into IPK columns in a UTF-16 database. (CVS 1771) check-in: e5e39764 user: danielk1977 tags: trunk
02:35
Minor fixes for UTF-16 databases. (CVS 1770) check-in: 6c5c11e0 user: danielk1977 tags: trunk
02:29
Some extra tests for the OP_MustBeInt opcode. (CVS 1769) check-in: b9d5858c user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/test3.c.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** Code for testing the btree.c module in SQLite.  This code
    13     13   ** is not included in the SQLite library.  It is used for automated
    14     14   ** testing of the SQLite library.
    15     15   **
    16         -** $Id: test3.c,v 1.46 2004/06/29 13:18:24 danielk1977 Exp $
           16  +** $Id: test3.c,v 1.47 2004/06/30 02:35:51 danielk1977 Exp $
    17     17   */
    18     18   #include "sqliteInt.h"
    19     19   #include "pager.h"
    20     20   #include "btree.h"
    21     21   #include "tcl.h"
    22     22   #include <stdlib.h>
    23     23   #include <string.h>
................................................................................
   416    416       sprintf(zBuf,"%d",SQLITE_N_BTREE_META);
   417    417       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   418    418          " ID METADATA...\" (METADATA is ", zBuf, " integers)", 0);
   419    419       return TCL_ERROR;
   420    420     }
   421    421     if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
   422    422     for(i=1; i<SQLITE_N_BTREE_META; i++){
   423         -    if( Tcl_GetInt(interp, argv[i+1], &aMeta[i]) ) return TCL_ERROR;
          423  +    if( Tcl_GetInt(interp, argv[i+2], &aMeta[i]) ) return TCL_ERROR;
   424    424     }
   425    425     for(i=1; i<SQLITE_N_BTREE_META; i++){
   426    426       rc = sqlite3BtreeUpdateMeta(pBt, i, aMeta[i]);
   427    427       if( rc!=SQLITE_OK ){
   428    428         Tcl_AppendResult(interp, errorName(rc), 0);
   429    429         return TCL_ERROR;
   430    430       }

Changes to src/util.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** Utility functions used throughout sqlite.
    13     13   **
    14     14   ** This file contains functions for allocating memory, comparing
    15     15   ** strings, and stuff like that.
    16     16   **
    17         -** $Id: util.c,v 1.107 2004/06/25 01:10:48 drh Exp $
           17  +** $Id: util.c,v 1.108 2004/06/30 02:35:51 danielk1977 Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include <stdarg.h>
    21     21   #include <ctype.h>
    22     22   
    23     23   #if SQLITE_DEBUG>2 && defined(__GLIBC__)
    24     24   #include <execinfo.h>
................................................................................
   590    590   ** the string is numeric and contains the '.' character, set *realnum
   591    591   ** to TRUE (otherwise FALSE).
   592    592   **
   593    593   ** Am empty string is considered non-numeric.
   594    594   */
   595    595   int sqlite3IsNumber(const char *z, int *realnum, u8 enc){
   596    596     int incr = (enc==SQLITE_UTF8?1:2);
   597         -  if( enc==SQLITE_UTF16LE ) z++;
          597  +  if( enc==SQLITE_UTF16BE ) z++;
   598    598     if( *z=='-' || *z=='+' ) z += incr;
   599    599     if( !isdigit(*z) ){
   600    600       return 0;
   601    601     }
   602    602     z += incr;
   603    603     if( realnum ) *realnum = 0;
   604    604     while( isdigit(*z) ){ z += incr; }

Changes to src/vdbe.c.

    39     39   **
    40     40   ** Various scripts scan this source file in order to generate HTML
    41     41   ** documentation, headers files, or other derived files.  The formatting
    42     42   ** of the code in this file is, therefore, important.  See other comments
    43     43   ** in this file for details.  If in doubt, do not deviate from existing
    44     44   ** commenting and indentation practices when changing or adding code.
    45     45   **
    46         -** $Id: vdbe.c,v 1.394 2004/06/29 13:54:50 drh Exp $
           46  +** $Id: vdbe.c,v 1.395 2004/06/30 02:35:51 danielk1977 Exp $
    47     47   */
    48     48   #include "sqliteInt.h"
    49     49   #include "os.h"
    50     50   #include <ctype.h>
    51     51   #include "vdbeInt.h"
    52     52   
    53     53   /*
................................................................................
   698    698     pTos++;
   699    699     pTos->flags = MEM_Str|MEM_Static|MEM_Term;
   700    700     pTos->z = pOp->p3;
   701    701     pTos->n = strlen(pTos->z);
   702    702     pTos->enc = SQLITE_UTF8;
   703    703     pTos->r = sqlite3VdbeRealValue(pTos);
   704    704     pTos->flags |= MEM_Real;
          705  +  sqlite3VdbeChangeEncoding(pTos, db->enc);
   705    706     break;
   706    707   }
   707    708   
   708    709   /* Opcode: String8 * * P3
   709    710   **
   710    711   ** P3 points to a nul terminated UTF-8 string. This opcode is transformed
   711    712   ** into an OP_String before it is executed for the first time.

Changes to test/btree.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script is btree database backend
    13     13   #
    14         -# $Id: btree.test,v 1.28 2004/06/20 03:06:18 dougcurrie Exp $
           14  +# $Id: btree.test,v 1.29 2004/06/30 02:35:51 danielk1977 Exp $
    15     15   
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   # Basic functionality.  Open and close a database.
    21     21   #
................................................................................
   368    368   # Try to read and write meta data
   369    369   #
   370    370   do_test btree-5.1 {
   371    371     btree_get_meta $::b1
   372    372   } {0 0 0 0 0 0 0 0 0 0}
   373    373   do_test btree-5.2 {
   374    374     set rc [catch {
   375         -    btree_update_meta $::b1 1 2 3 4 5 6 7 8 9 10
          375  +    btree_update_meta $::b1 0 1 2 3 4 5 6 7 8 9
   376    376     } msg]
   377    377     lappend rc $msg
   378    378   } {1 SQLITE_ERROR}
   379    379   do_test btree-5.3 {
   380    380     btree_begin_transaction $::b1
   381    381     set rc [catch {
   382         -    btree_update_meta $::b1 1 2 3 4 5 6 7 8 9 10
          382  +    btree_update_meta $::b1 0 1 2 3 4 5 6 7 8 9
   383    383     } msg]
   384    384     lappend rc $msg
   385    385   } {0 {}}
   386    386   do_test btree-5.4 {
   387    387     btree_get_meta $::b1
   388    388   } {0 1 2 3 4 5 6 7 8 9}
   389    389   do_test btree-5.5 {
   390    390     btree_close_cursor $::c1
   391    391     btree_rollback $::b1
   392    392     btree_get_meta $::b1
   393    393   } {0 0 0 0 0 0 0 0 0 0}
   394    394   do_test btree-5.6 {
   395    395     btree_begin_transaction $::b1
   396         -  btree_update_meta $::b1 10 20 30 40 50 60 70 80 90 100
          396  +  btree_update_meta $::b1 0 10 20 30 40 50 60 70 80 90
   397    397     btree_commit $::b1
   398    398     btree_get_meta $::b1
   399    399   } {0 10 20 30 40 50 60 70 80 90}
   400    400   
   401    401   proc select_all {cursor} {
   402    402     set r {}
   403    403     btree_first $cursor

Changes to test/capi3.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script testing the callback-free C/C++ API.
    13     13   #
    14         -# $Id: capi3.test,v 1.17 2004/06/29 14:03:58 danielk1977 Exp $
           14  +# $Id: capi3.test,v 1.18 2004/06/30 02:35:51 danielk1977 Exp $
    15     15   #
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   # Return the UTF-16 representation of the supplied UTF-8 string $str.
    21     21   # If $nt is true, append two 0x00 bytes as a nul terminator.
................................................................................
   401    401       CREATE TABLE t1(a VARINT, b BLOB, c VARCHAR(16));
   402    402       INSERT INTO t1 VALUES(1, 2, 3);
   403    403       INSERT INTO t1 VALUES('one', 'two', NULL);
   404    404       INSERT INTO t1 VALUES(1.2, 1.3, 1.4);
   405    405     }
   406    406     set sql "SELECT * FROM t1"
   407    407     set STMT [sqlite3_prepare $DB $sql -1 TAIL]
   408         -
   409    408     sqlite3_column_count $STMT
   410    409   } 3
   411    410   
   412    411   check_header $STMT capi3-5.1 {a b c} {VARINT BLOB VARCHAR(16)}
   413         -
   414    412   do_test capi3-5.2 {
   415    413     sqlite3_step $STMT
   416    414   } SQLITE_ROW
   417    415   
   418    416   check_header $STMT capi3-5.3 {a b c} {VARINT BLOB VARCHAR(16)}
   419    417   check_data $STMT capi3-5.4 {INTEGER INTEGER TEXT} {1 2 3} {1.0 2.0 3.0} {1 2 3}
   420    418   
................................................................................
   436    434     sqlite3_step $STMT
   437    435   } SQLITE_DONE
   438    436   
   439    437   do_test capi3-5.12 {
   440    438     sqlite3_finalize $STMT
   441    439   } SQLITE_OK
   442    440   
          441  +set ::ENC [execsql {pragma encoding}]
   443    442   db close
   444    443   
   445    444   do_test capi3-6.0 {
   446    445     set DB [sqlite3_open test.db]
   447    446     set sql {SELECT a FROM t1 order by rowid}
   448    447     set STMT [sqlite3_prepare $DB $sql -1 TAIL]
   449    448     expr 0
................................................................................
   464    463   
   465    464   # Test what happens when the library encounters a newer file format.
   466    465   # Do this by updating the file format via the btree layer.
   467    466   do_test capi3-7.1 {
   468    467     set ::bt [btree_open test.db 10 0]
   469    468     btree_begin_transaction $::bt
   470    469     set meta [btree_get_meta $::bt]
   471         -  lset meta 5 2
   472         -  eval [concat btree_update_meta $::bt $meta]
          470  +  lset meta 2 2
          471  +  eval [concat btree_update_meta $::bt [lrange $meta 0 end]]
   473    472     btree_commit $::bt
   474    473     btree_close $::bt
   475    474   } {}
   476    475   do_test capi3-7.2 {
   477    476     sqlite3 db test.db
          477  +breakpoint
   478    478     catchsql {
   479    479       SELECT * FROM sqlite_master;
   480    480     }
   481    481   } {1 {unsupported file format}}
   482    482   
   483    483   # Now test that the library correctly handles bogus entries in the
   484    484   # sqlite_master table (schema corruption).
................................................................................
   494    494   do_test capi3-8.2 {
   495    495     set ::bt [btree_open test.db 10 0]
   496    496     btree_begin_transaction $::bt
   497    497     set ::bc [btree_cursor $::bt 1 1]
   498    498   
   499    499     # Build a 5-field row record consisting of 5 null records. This is
   500    500     # officially black magic.
          501  +  unset data
   501    502     set data [binary format c6 {6 0 0 0 0 0}]
   502    503     btree_insert $::bc 5 $data
   503    504   
   504    505     btree_close_cursor $::bc
   505    506     btree_commit $::bt
   506    507     btree_close $::bt
   507    508   } {}
................................................................................
   514    515   do_test capi3-8.4 {
   515    516     set ::bt [btree_open test.db 10 0]
   516    517     btree_begin_transaction $::bt
   517    518     set ::bc [btree_cursor $::bt 1 1]
   518    519   
   519    520     # Build a 5-field row record. The first field is a string 'table', and
   520    521     # subsequent fields are all NULL. Replace the other broken record with
   521         -  # this one and try to read the schema again.
   522         -  set data [binary format c6a5 {6 23 0 0 0 0} table]
          522  +  # this one and try to read the schema again. The broken record uses
          523  +  # either UTF-8 or native UTF-16 (if this file is being run by
          524  +  # utf16.test).
          525  +  if { [string match UTF-16* $::ENC] } {
          526  +    set data [binary format c6a10 {6 33 0 0 0 0} [utf16 table]]
          527  +  } else {
          528  +    set data [binary format c6a5 {6 23 0 0 0 0} table]
          529  +  }
   523    530     btree_insert $::bc 5 $data
   524    531   
   525    532     btree_close_cursor $::bc
   526    533     btree_commit $::bt
   527    534     btree_close $::bt
   528    535   } {}
   529    536   do_test capi3-8.5 {

Changes to test/trace.test.

     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.
    12     12   #
    13     13   # This file implements tests for the "sqlite3_trace()" API.
    14     14   #
    15         -# $Id: trace.test,v 1.1 2004/06/29 11:26:59 drh Exp $
           15  +# $Id: trace.test,v 1.2 2004/06/30 02:35:51 danielk1977 Exp $
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
           20  +set ::stmtlist {}
    20     21   do_test trace-1.1 {
    21     22     set rc [catch {db trace 1 2 3} msg]
    22     23     lappend rc $msg
    23     24   } {1 {wrong # args: should be "db trace ?CALLBACK?"}}
    24     25   proc trace_proc cmd {
    25     26     lappend ::stmtlist [string trim $cmd]
    26     27   }

Changes to test/types.test.

     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library. Specfically
    12     12   # it tests that the different storage classes (integer, real, text etc.)
    13     13   # all work correctly.
    14     14   #
    15         -# $Id: types.test,v 1.7 2004/05/27 19:59:33 drh Exp $
           15  +# $Id: types.test,v 1.8 2004/06/30 02:35:51 danielk1977 Exp $
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   # Tests in this file are organized roughly as follows:
    21     21   #
    22     22   # types-1.*.*: Test that values are stored using the expected storage
................................................................................
   256    256   } {}
   257    257   do_test types-2.4.2 {
   258    258     execsql {
   259    259       SELECT a FROM t4;
   260    260     }
   261    261   } [list $string10 $string500 $string500000]
   262    262   
   263         -# Check that all the record sizes are as we expected.
   264         -do_test types-2.4.3 {
   265         -  set root [db eval {select rootpage from sqlite_master where name = 't4'}]
   266         -  record_sizes $root
   267         -} {12 503 500004}
          263  +# Check that all the record sizes are as we expected. This is dependant on
          264  +# the database encoding.
          265  +if { [execsql {pragma encoding}] == "UTF-8" } {
          266  +  do_test types-2.4.3 {
          267  +    set root [db eval {select rootpage from sqlite_master where name = 't4'}]
          268  +    record_sizes $root
          269  +  } {12 503 500004}
          270  +} else {
          271  +  do_test types-2.4.3 {
          272  +    set root [db eval {select rootpage from sqlite_master where name = 't4'}]
          273  +    record_sizes $root
          274  +  } {22 1003 1000004}
          275  +}
   268    276   
   269    277   do_test types-2.5.1 {
   270    278     execsql {
   271    279       DROP TABLE t1;
   272    280       DROP TABLE t2;
   273    281       DROP TABLE t3;
   274    282       DROP TABLE t4;

Changes to test/utf16.test.

     6      6   #    May you do good and not evil.
     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file runs all tests.
    12     12   #
    13         -# $Id: utf16.test,v 1.2 2004/06/29 23:52:48 danielk1977 Exp $
           13  +# $Id: utf16.test,v 1.3 2004/06/30 02:35:51 danielk1977 Exp $
    14     14   
    15     15   set testdir [file dirname $argv0]
    16     16   source $testdir/tester.tcl
    17     17   rename finish_test really_finish_test2
    18     18   proc finish_test {} {}
    19     19   set ISQUICK 1
    20     20   
................................................................................
    28     28       conflict.test date.test delete.test expr.test fkey1.test func.test
    29     29       hook.test index.test insert2.test insert.test interrupt.test in.test
    30     30       intpkey.test ioerr.test join2.test join.test lastinsert.test
    31     31       laststmtchanges.test limit.test lock2.test lock.test main.test 
    32     32       memdb.test minmax.test misc1.test misc2.test misc3.test notnull.test
    33     33       null.test progress.test quote.test rowid.test select1.test select2.test
    34     34       select3.test select4.test select5.test select6.test sort.test 
    35         -    subselect.test tableapi.test table.test tclsqlite.test temptable.test
    36         -    trace.test trans.test trigger1.test trigger2.test trigger3.test
           35  +    subselect.test tableapi.test table.test temptable.test
           36  +    trace.test trigger1.test trigger2.test trigger3.test
    37     37       trigger4.test types2.test types.test unique.test update.test
    38     38       vacuum.test view.test where.test
    39     39     }
    40     40     foreach f $F {lappend FILES $testdir/$f}
    41     41   }
    42         -puts $FILES
    43     42   
    44     43   rename sqlite3 real_sqlite3
    45     44   proc sqlite3 {args} {
    46     45     set r [eval "real_sqlite3 $args"]
    47     46     if { [llength $args] == 2 } {
    48     47       [lindex $args 0] eval {pragma encoding = 'UTF-16'}
    49     48     }