SQLite4
Check-in [9678daa99f]
Not logged in

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

Overview
Comment:Add file selectF.test.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 9678daa99f05495cddec8272f13ec93c4c586a9f
User & Date: dan 2013-06-12 19:20:59
Context
2013-06-13
15:24
Remove the 'encoding' argument from sqlite4_create_function(). check-in: f88d080127 user: dan tags: trunk
2013-06-12
19:20
Add file selectF.test. check-in: 9678daa99f user: dan tags: trunk
2013-06-11
17:27
Add a note to www/porting.wiki describing the changes to utf-16 support. check-in: 5cd50e225c user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/sqlite.h.in.

  2288   2288   ** behavior is undefined.
  2289   2289   **
  2290   2290   ** ^The fourth parameter, eTextRep, specifies the
  2291   2291   ** [SQLITE4_UTF8 | text encoding] this SQL function prefers for
  2292   2292   ** its parameters.  Every SQL function implementation must be able to work
  2293   2293   ** with UTF-8, UTF-16le, or UTF-16be.  But some implementations may be
  2294   2294   ** more efficient with one encoding than another.  ^An application may
  2295         -** invoke sqlite4_create_function() or sqlite4_create_function16() multiple
  2296         -** times with the same function but with different values of eTextRep.
  2297         -** ^When multiple implementations of the same function are available, SQLite
  2298         -** will pick the one that involves the least amount of data conversion.
  2299         -** If there is only a single implementation which does not care what text
  2300         -** encoding is used, then the fourth argument should be [SQLITE4_ANY].
         2295  +** invoke sqlite4_create_function() multiple times with the same function 
         2296  +** but with different values of eTextRep. ^When multiple implementations 
         2297  +** of the same function are available, SQLite will pick the one that 
         2298  +** involves the least amount of data conversion. If there is only a single 
         2299  +** implementation which does not care what text encoding is used, then the 
         2300  +** fourth argument should be [SQLITE4_ANY].
  2301   2301   **
  2302   2302   ** ^(The fifth parameter is an arbitrary pointer.  The implementation of the
  2303   2303   ** function can gain access to this pointer using [sqlite4_context_appdata()].)^
  2304   2304   **
  2305   2305   ** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are
  2306   2306   ** pointers to C-language functions that implement the SQL function or
  2307   2307   ** aggregate. ^A scalar SQL function requires an implementation of the xFunc
................................................................................
  2811   2811   ** of the default VFS is not implemented correctly, or not implemented at
  2812   2812   ** all, then the behavior of sqlite4_sleep() may deviate from the description
  2813   2813   ** in the previous paragraphs.
  2814   2814   */
  2815   2815   int sqlite4_sleep(int);
  2816   2816   
  2817   2817   /*
  2818         -** CAPIREF: Test For Auto-Commit Mode
         2818  +** CAPIREF: Test For An Open Transaction
  2819   2819   ** KEYWORDS: {autocommit mode}
  2820   2820   **
  2821   2821   ** ^The sqlite4_db_transaction_status() interface returns non-zero if
  2822   2822   ** the database connection passed as the only argument is currently within
  2823   2823   ** an explicitly started transaction. An explicit transaction is opened
  2824   2824   ** using a [BEGIN] command, and usually concluded using a [COMMIT] or
  2825   2825   ** [ROLLBACK].

Added test/selectF.test.

            1  +# 2013 June 12
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +# 
           12  +# Test cases for SELECT statements.
           13  +#
           14  +
           15  +set testdir [file dirname $argv0]
           16  +source $testdir/tester.tcl
           17  +set testprefix selectF
           18  +
           19  +# Evaluate the SQL query passed as the only argument using database
           20  +# connection [db]. Return any results as a list of lists - one list
           21  +# element for each row. i.e.
           22  +#
           23  +#   "SELECT 1, 2 UNION SELECT 3, 4" -> "{1 2} {3 4}"
           24  +#
           25  +proc eval_to_list {bOrdered sql} {
           26  +  set sqlresult [list]
           27  +  db eval $sql a {
           28  +    set row [list]
           29  +    foreach c $a(*) { lappend row $a($c) }
           30  +    lappend sqlresult $row
           31  +  }
           32  +  if {!$bOrdered} {set sqlresult [lsort $sqlresult]}
           33  +  set sqlresult
           34  +}
           35  +
           36  +# Execute SELECT query $zSql using [eval_to_list] and compare the results
           37  +# to $lRes. If argument $bOrdered is false, this indicates that the order
           38  +# of results is non-deterministic. In this case the results are passed
           39  +# to [lsort] before they are compared to $lRes.
           40  +#
           41  +proc do_select_test {testname bOrdered zSql lRes} {
           42  +  uplevel [list do_test $testname [list eval_to_list $bOrdered $zSql] $lRes]
           43  +}
           44  +
           45  +# The SELECT tests in this file all use the following command. See the
           46  +# example below for details.
           47  +#
           48  +proc do_select_test_set {tn data indexes tests} {
           49  +  db_delete_and_reopen
           50  +  execsql $data
           51  +  db_save_and_close
           52  +
           53  +  if {$tn=="*"} {
           54  +    foreach {tn2 bOrder sql res} $tests {
           55  +      puts "$tn2 $bOrder \"$sql\" {[eval_to_list $bOrder $sql]}"
           56  +    }
           57  +  } else {
           58  +    foreach {tn1 sql} $indexes {
           59  +      db_restore_and_reopen
           60  +      foreach {tn2 bOrder sql res} $tests {
           61  +        do_select_test $tn.$tn1.$tn2 $bOrder $sql $res
           62  +      }
           63  +    }
           64  +  }
           65  +}
           66  +
           67  +#--------------------------------------------------------------------
           68  +# Warm-body tests. This block serves as an example of how to use
           69  +# the [do_select_test_set] command.
           70  +#
           71  +do_select_test_set 1 {
           72  +  CREATE TABLE t1(a, b, c);
           73  +  INSERT INTO t1 VALUES(2, 4,  6);
           74  +  INSERT INTO t1 VALUES(1, 2,  3);
           75  +  INSERT INTO t1 VALUES(4, 8,  12);
           76  +  INSERT INTO t1 VALUES(3, 6,  9);
           77  +  INSERT INTO t1 VALUES(6, 12, 18);
           78  +  INSERT INTO t1 VALUES(5, 10, 15);
           79  +} {
           80  +  1 { }
           81  +  2 { CREATE INDEX ON t1(a, b, c) }
           82  +  3 { CREATE INDEX ON t1(c, b, a) }
           83  +  4 { 
           84  +    CREATE INDEX ON t1(a);
           85  +    CREATE INDEX ON t1(b);
           86  +    CREATE INDEX ON t1(c);
           87  +  }
           88  +} {
           89  +1 0 "SELECT * FROM t1 WHERE a = 2" {{2 4 6}}
           90  +2 0 "SELECT * FROM t1 WHERE a < 4" {{1 2 3} {2 4 6} {3 6 9}}
           91  +3 0 "SELECT * FROM t1 WHERE a = b/2 AND c%2" {{1 2 3} {3 6 9} {5 10 15}}
           92  +4 0 "SELECT (a/2) FROM t1 GROUP BY (a/2)" {0 1 2 3}
           93  +5 0 "SELECT a+b FROM t1 GROUP BY (a+b)" {12 15 18 3 6 9}
           94  +6 1 "SELECT a+b FROM t1 GROUP BY (a+b) ORDER BY 1" {3 6 9 12 15 18}
           95  +7 0 "SELECT a*b FROM t1 WHERE (c%2)" {18 2 50}
           96  +8 0 "SELECT count(*) FROM t1, t1 AS t2 WHERE t1.a=t2.a" {6}
           97  +9 0 "SELECT * FROM t1 WHERE a=1 AND b=2" {{1 2 3}}
           98  +10 0 "SELECT * FROM t1 WHERE a>3 AND b<12" {{4 8 12} {5 10 15}}
           99  +}
          100  +
          101  +finish_test
          102  +
          103  +
          104  +
          105  +

Changes to www/porting.wiki.

    37     37   
    38     38   <h3> UTF-16 Functions </h3>
    39     39   
    40     40   <p>
    41     41   Many SQLite3 APIs come in two flavours - UTF-8 and UTF-16. For example,
    42     42   sqlite3_complete() and sqlite3_complete16(). In most cases, the only 
    43     43   difference between the two versions is that one interprets or returns
    44         -text encoded using UTF-8, and the other using native byte-order utf-16.
           44  +text encoded using UTF-8, and the other using native byte-order UTF-16.
    45     45   For SQLite4, all UTF-16 APIs have been removed except the following:
    46     46   
    47     47   <ul>
    48     48     <li> sqlite4_column_text16()
    49     49     <li> sqlite4_value_text16()
    50     50     <li> sqlite4_bind_text16()
    51     51     <li> sqlite4_result_text16()
................................................................................
    58     58   the current error message formated using UTF-16 (available in SQLite3
    59     59   by calling sqlite3_errmsg16()), the following:
    60     60   
    61     61   <pre>
    62     62     u16 *pError;                    /* Pointer to translated error message */
    63     63     sqlite4_buffer buf;             /* Buffer to manage memory used for pError */
    64     64   
    65         -  /* Initialize a buffer object. Then populate it with the utf-16 translation
    66         -  ** of the utf-8 error message returned by sqlite4_errmsg().  */
           65  +  /* Initialize a buffer object. Then populate it with the UTF-16 translation
           66  +  ** of the UTF-8 error message returned by sqlite4_errmsg().  */
    67     67     sqlite4_buffer_init(&buf, 0);
    68     68     pError = sqlite4_translate(
    69     69         &buf, sqlite4_errmsg(db), -1, SQLITE4_TRANSLATE_UTF8_UTF16
    70     70     );
    71     71   
    72     72     if( pError==0 ){
    73     73       /* An out-of-memory error has occurred */
    74     74     }else{
    75     75       /* pError now points to a buffer containing the current error message
    76         -    ** encoded using native byte-order utf-16. Do something with it! */
           76  +    ** encoded using native byte-order UTF-16. Do something with it! */
    77     77     }
    78     78   
    79     79     /* Free the contents of the buffer (and hence pError) */
    80     80     sqlite4_buffer_clear(&buf);
    81     81   </pre>
    82     82