/ Check-in [5be56dbe]
Login

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

Overview
Comment:Enhanced testing and documentation of sqlite3_result_error_code(). Ticket #2940. (CVS 4983)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 5be56dbe879f89351239accf5069e4cb166e0792
User & Date: drh 2008-04-10 17:14:07
Context
2008-04-10
17:27
Add the --ostrace and --ossummary options to tester.tcl. To log calls the vfs layer from within test scripts. (CVS 4984) check-in: e1322415 user: danielk1977 tags: trunk
17:14
Enhanced testing and documentation of sqlite3_result_error_code(). Ticket #2940. (CVS 4983) check-in: 5be56dbe user: drh tags: trunk
16:47
Disable nuisance warnings on borland compilers. ticket #2936. (CVS 4982) check-in: 1e094ecf user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/sqlite.h.in.

    26     26   ** on how SQLite interfaces are suppose to operate.
    27     27   **
    28     28   ** The name of this file under configuration management is "sqlite.h.in".
    29     29   ** The makefile makes some minor changes to this file (such as inserting
    30     30   ** the version number) and changes its name to "sqlite3.h" as
    31     31   ** part of the build process.
    32     32   **
    33         -** @(#) $Id: sqlite.h.in,v 1.303 2008/04/10 13:38:18 drh Exp $
           33  +** @(#) $Id: sqlite.h.in,v 1.304 2008/04/10 17:14:07 drh Exp $
    34     34   */
    35     35   #ifndef _SQLITE3_H_
    36     36   #define _SQLITE3_H_
    37     37   #include <stdarg.h>     /* Needed for the definition of va_list */
    38     38   
    39     39   /*
    40     40   ** Make sure we can call this stuff from C++.
................................................................................
  3942   3942   ** bytes (not characters) from the 2nd parameter as the error message.
  3943   3943   ** The sqlite3_result_error() and sqlite3_result_error16()
  3944   3944   ** routines make a copy private copy of the error message text before
  3945   3945   ** they return.  Hence, the calling function can deallocate or
  3946   3946   ** modify the text after they return without harm.
  3947   3947   ** The sqlite3_result_error_code() function changes the error code
  3948   3948   ** returned by SQLite as a result of an error in a function.  By default,
  3949         -** the error code is SQLITE_ERROR. 
         3949  +** the error code is SQLITE_ERROR.  A subsequent call to sqlite3_result_error()
         3950  +** or sqlite3_result_error16() resets the error code to SQLITE_ERROR.
  3950   3951   **
  3951   3952   ** The sqlite3_result_toobig() interface causes SQLite
  3952   3953   ** to throw an error indicating that a string or BLOB is to long
  3953   3954   ** to represent.  The sqlite3_result_nomem() interface
  3954   3955   ** causes SQLite to throw an exception indicating that the a
  3955   3956   ** memory allocation failed.
  3956   3957   **

Changes to src/test_func.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** Code for testing all sorts of SQLite interfaces.  This code
    13     13   ** implements new SQL functions used by the test scripts.
    14     14   **
    15         -** $Id: test_func.c,v 1.3 2008/03/19 19:01:22 drh Exp $
           15  +** $Id: test_func.c,v 1.4 2008/04/10 17:14:07 drh Exp $
    16     16   */
    17     17   #include "sqlite3.h"
    18     18   #include "tcl.h"
    19     19   #include <stdlib.h>
    20     20   #include <string.h>
    21     21   #include <assert.h>
    22     22   
................................................................................
   186    186       }
   187    187     }
   188    188     sqlite3_result_text(pCtx, zRet, 2*nArg-1, free_test_auxdata);
   189    189   }
   190    190   
   191    191   /*
   192    192   ** A function to test error reporting from user functions. This function
   193         -** returns a copy of its first argument as an error.
          193  +** returns a copy of its first argument as the error message.  If the
          194  +** second argument exists, it becomes the error code.
   194    195   */
   195    196   static void test_error(
   196    197     sqlite3_context *pCtx, 
   197    198     int nArg,
   198    199     sqlite3_value **argv
   199    200   ){
   200         -  sqlite3_result_error(pCtx, (char*)sqlite3_value_text(argv[0]), 0);
          201  +  sqlite3_result_error(pCtx, (char*)sqlite3_value_text(argv[0]), -1);
          202  +  if( nArg==2 ){
          203  +    sqlite3_result_error_code(pCtx, sqlite3_value_int(argv[1]));
          204  +  }
   201    205   }
   202    206   
   203    207   static int registerTestFunctions(sqlite3 *db){
   204    208     static const struct {
   205    209        char *zName;
   206    210        signed char nArg;
   207    211        unsigned char eTextRep; /* 1: UTF-16.  0: UTF-8 */
................................................................................
   209    213     } aFuncs[] = {
   210    214       { "randstr",               2, SQLITE_UTF8, randStr    },
   211    215       { "test_destructor",       1, SQLITE_UTF8, test_destructor},
   212    216       { "test_destructor16",     1, SQLITE_UTF8, test_destructor16},
   213    217       { "test_destructor_count", 0, SQLITE_UTF8, test_destructor_count},
   214    218       { "test_auxdata",         -1, SQLITE_UTF8, test_auxdata},
   215    219       { "test_error",            1, SQLITE_UTF8, test_error},
          220  +    { "test_error",            2, SQLITE_UTF8, test_error},
   216    221     };
   217    222     int i;
   218    223     extern int Md5_Register(sqlite3*);
   219    224   
   220    225     for(i=0; i<sizeof(aFuncs)/sizeof(aFuncs[0]); i++){
   221    226       sqlite3_create_function(db, aFuncs[i].zName, aFuncs[i].nArg,
   222    227           aFuncs[i].eTextRep, 0, aFuncs[i].xFunc, 0, 0);

Changes to test/capi3c.test.

     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  
    12     12   #
    13     13   # This is a copy of the capi3.test file that has been adapted to
    14     14   # test the new sqlite3_prepare_v2 interface.
    15     15   #
    16         -# $Id: capi3c.test,v 1.16 2008/03/19 13:03:34 drh Exp $
           16  +# $Id: capi3c.test,v 1.17 2008/04/10 17:14:07 drh Exp $
    17     17   #
    18     18   
    19     19   set testdir [file dirname $argv0]
    20     20   source $testdir/tester.tcl
    21     21   
    22     22   # Return the UTF-16 representation of the supplied UTF-8 string $str.
    23     23   # If $nt is true, append two 0x00 bytes as a nul terminator.
................................................................................
    83     83   } {1}
    84     84   do_test capi3c-1.6 {
    85     85     sqlite3_errcode $DB
    86     86   } {SQLITE_ERROR}
    87     87   do_test capi3c-1.7 {
    88     88     sqlite3_errmsg $DB
    89     89   } {no such column: namex}
           90  +
    90     91   
    91     92   ifcapable {utf16} {
    92     93     do_test capi3c-2.1 {
    93     94       set sql16 [utf16 {SELECT name FROM sqlite_master}]
    94     95       set STMT [sqlite3_prepare16_v2  $DB $sql16 -1 ::TAIL]
    95     96       sqlite3_finalize $STMT
    96     97       utf8 $::TAIL
................................................................................
  1239   1240     } {SQLITE_ERROR}
  1240   1241     do_test capi3c-21.6 {
  1241   1242       sqlite3_finalize $STMT
  1242   1243     } {SQLITE_INTERRUPT}
  1243   1244     do_test capi3c-21.7 {
  1244   1245       sqlite3_errcode $DB
  1245   1246     } {SQLITE_INTERRUPT}
  1246         -}  
         1247  +}
         1248  +
         1249  +# Make sure sqlite3_result_error_code() returns the correct error code.
         1250  +# See ticket #2940
         1251  +#
         1252  +do_test capi3c-22.1 {
         1253  +  db progress 0 {}
         1254  +  set STMT [sqlite3_prepare_v2 db {SELECT test_error('the message',3)} -1 TAIL]
         1255  +  sqlite3_step $STMT
         1256  +} {SQLITE_PERM}
         1257  +sqlite3_finalize $STMT
         1258  +do_test capi3c-22.2 {
         1259  +  set STMT [sqlite3_prepare_v2 db {SELECT test_error('the message',4)} -1 TAIL]
         1260  +  sqlite3_step $STMT
         1261  +} {SQLITE_ABORT}
         1262  +sqlite3_finalize $STMT
         1263  +do_test capi3c-22.3 {
         1264  +  set STMT [sqlite3_prepare_v2 db {SELECT test_error('the message',16)} -1 TAIL]
         1265  +  sqlite3_step $STMT
         1266  +} {SQLITE_EMPTY}
         1267  +sqlite3_finalize $STMT
         1268  +
  1247   1269   
  1248   1270   finish_test

Changes to test/func.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 file is testing built-in functions.
    13     13   #
    14         -# $Id: func.test,v 1.75 2008/03/21 17:13:13 drh Exp $
           14  +# $Id: func.test,v 1.76 2008/04/10 17:14:07 drh Exp $
    15     15   
    16     16   set testdir [file dirname $argv0]
    17     17   source $testdir/tester.tcl
    18     18   
    19     19   # Create a table to work with.
    20     20   #
    21     21   do_test func-0.0 {
................................................................................
   531    531   do_test func-14.2 {
   532    532     catch {
   533    533       db function [string repeat X 256] {return "hello"}
   534    534     }
   535    535   } {1}
   536    536   
   537    537   do_test func-15.1 {
   538         -  catchsql {
   539         -    select test_error(NULL);
   540         -  }
          538  +  catchsql {select test_error(NULL)}
   541    539   } {1 {}}
          540  +do_test func-15.2 {
          541  +  catchsql {select test_error('this is the error message')}
          542  +} {1 {this is the error message}}
          543  +do_test func-15.3 {
          544  +  catchsql {select test_error('this is the error message',12)}
          545  +} {1 {this is the error message}}
          546  +do_test func-15.4 {
          547  +  db errorcode
          548  +} {12}
   542    549   
   543    550   # Test the quote function for BLOB and NULL values.
   544    551   do_test func-16.1 {
   545    552     execsql {
   546    553       CREATE TABLE tbl2(a, b);
   547    554     }
   548    555     set STMT [sqlite3_prepare $::DB "INSERT INTO tbl2 VALUES(?, ?)" -1 TAIL]