From: drh Date: Thu, 10 Apr 2008 17:14:07 +0000 (+0000) Subject: Enhanced testing and documentation of sqlite3_result_error_code(). X-Git-Tag: version-3.6.10~1194 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=00e087b24ba26995b350d739977272898287cf4f;p=thirdparty%2Fsqlite.git Enhanced testing and documentation of sqlite3_result_error_code(). Ticket #2940. (CVS 4983) FossilOrigin-Name: 5be56dbe879f89351239accf5069e4cb166e0792 --- diff --git a/manifest b/manifest index 39c3840e2a..7a6248338c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Disable\snuisance\swarnings\son\sborland\scompilers.\s\sticket\s#2936.\s(CVS\s4982) -D 2008-04-10T16:47:42 +C Enhanced\stesting\sand\sdocumentation\sof\ssqlite3_result_error_code().\nTicket\s#2940.\s(CVS\s4983) +D 2008-04-10T17:14:07 F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7 F Makefile.in b861627d91df5ee422c54237aa38296954dc0151 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -138,7 +138,7 @@ F src/random.c 2b2db2de4ab491f5a14d3480466f8f4b5a5db74a F src/select.c 1abe53c844f536a79cc11b19127c8e6d47a87b20 F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96 F src/shell.c 22297fffa6f00a6c6d44020fa13b1184a1bb372d -F src/sqlite.h.in 60ae3e8b044332669cd554d0cc9d95cf43b4b857 +F src/sqlite.h.in 824f823b341e9c979f82edebf710c87b74d1b7f5 F src/sqlite3ext.h faacd0e6a81aabee0861c6d7883c9172e74ef5b3 F src/sqliteInt.h 6e6e847b7315e9609ab79dba6d68748b7ad3e214 F src/sqliteLimit.h f435e728c6b620ef7312814d660a81f9356eb5c8 @@ -158,7 +158,7 @@ F src/test_autoext.c 5e892ab84aece3f0428920bf46923f16ac83962a F src/test_btree.c c1308ba0b88ab577fa56c9e493a09829dfcded9c F src/test_config.c 097a49a8804815799dc3d2220e6af693ad54f59d F src/test_devsym.c cee1aecaa90c895030399ca4ae38f84a08038f8a -F src/test_func.c 9e9b33ff083b65da91c389cece903bc32de06f01 +F src/test_func.c ef4ef3230b6346031bca2762bbc8b95ec7e0451a F src/test_hexio.c 1a1cd8324d57585ea86b922f609fa1fbaaf9662d F src/test_loadext.c 22065d601a18878e5542191001f0eaa5d77c0ed8 F src/test_malloc.c c92a65e8f9b31bb2b332448d92d2016c000a963d @@ -221,7 +221,7 @@ F test/cache.test 3ff445c445742a7b6b9ba6e1d62a25263f9424b9 F test/capi2.test cc64df7560a96f848f919ea2926c60acf639684b F test/capi3.test 8113010cd06a94b7ac72524858968069b7cac8e3 F test/capi3b.test 664eb55318132f292f2c436f90906f578cad6b97 -F test/capi3c.test 976673c1c5caef84201473ea5f7bb7b3093935a8 +F test/capi3c.test d704c1b9dff6a2749c758845d1a0358155642484 F test/cast.test ce8f14fc80f70b30ed984480cc0d8914a459e8f9 F test/check.test 024ed399600b799160378cf9d9f436bdf5dfd184 F test/collate1.test e3eaa48c21e150814be1a7b852d2a8af24458d04 @@ -322,7 +322,7 @@ F test/fts3ao.test 0aa29dd4fc1c8d46b1f7cfe5926f7ac97551bea9 F test/fts3atoken.test 25c2070e1e8755d414bf9c8200427b277a9f99fa F test/fts3b.test b3a25180a633873d37d86e1ccd00ed690d37237a F test/fts3near.test 2d4dadcaac5025ab65bb87e66c45f39e92966194 -F test/func.test 4118b1010187b8c7c96a30e1f94e424b482289b2 +F test/func.test 4ae1fb477bb6dbeba9ae8d09f258663c29d2f4aa F test/fuzz.test 62fc19dd36a427777fd671b569df07166548628a F test/fuzz2.test ea38692ce2da99ad79fe0be5eb1a452c1c4d37bb F test/fuzz_common.tcl ff4bc2dfc465f6878f8e2d819620914365382731 @@ -626,7 +626,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5 -P e3f798b1cafc3458941cf86ac4f9d4269fdf5b7e -R a993d519e15248ee201aa1d487e9beb7 +P 1e094ecfd7c6feaf8d524aa3c1477910b2328946 +R 76aadead09a9d806a27a54dca07b7abd U drh -Z 0927a0ae0269e482fb9e0766967b1751 +Z b01d010606845cba682f38fd64039c7c diff --git a/manifest.uuid b/manifest.uuid index 42b6660b85..cba6a46735 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1e094ecfd7c6feaf8d524aa3c1477910b2328946 \ No newline at end of file +5be56dbe879f89351239accf5069e4cb166e0792 \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index d8842e3c30..d66ff2c7e2 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -30,7 +30,7 @@ ** the version number) and changes its name to "sqlite3.h" as ** part of the build process. ** -** @(#) $Id: sqlite.h.in,v 1.303 2008/04/10 13:38:18 drh Exp $ +** @(#) $Id: sqlite.h.in,v 1.304 2008/04/10 17:14:07 drh Exp $ */ #ifndef _SQLITE3_H_ #define _SQLITE3_H_ @@ -3946,7 +3946,8 @@ typedef void (*sqlite3_destructor_type)(void*); ** modify the text after they return without harm. ** The sqlite3_result_error_code() function changes the error code ** returned by SQLite as a result of an error in a function. By default, -** the error code is SQLITE_ERROR. +** the error code is SQLITE_ERROR. A subsequent call to sqlite3_result_error() +** or sqlite3_result_error16() resets the error code to SQLITE_ERROR. ** ** The sqlite3_result_toobig() interface causes SQLite ** to throw an error indicating that a string or BLOB is to long diff --git a/src/test_func.c b/src/test_func.c index 05825b4b85..478474cbe1 100644 --- a/src/test_func.c +++ b/src/test_func.c @@ -12,7 +12,7 @@ ** Code for testing all sorts of SQLite interfaces. This code ** implements new SQL functions used by the test scripts. ** -** $Id: test_func.c,v 1.3 2008/03/19 19:01:22 drh Exp $ +** $Id: test_func.c,v 1.4 2008/04/10 17:14:07 drh Exp $ */ #include "sqlite3.h" #include "tcl.h" @@ -190,14 +190,18 @@ static void test_auxdata( /* ** A function to test error reporting from user functions. This function -** returns a copy of its first argument as an error. +** returns a copy of its first argument as the error message. If the +** second argument exists, it becomes the error code. */ static void test_error( sqlite3_context *pCtx, int nArg, sqlite3_value **argv ){ - sqlite3_result_error(pCtx, (char*)sqlite3_value_text(argv[0]), 0); + sqlite3_result_error(pCtx, (char*)sqlite3_value_text(argv[0]), -1); + if( nArg==2 ){ + sqlite3_result_error_code(pCtx, sqlite3_value_int(argv[1])); + } } static int registerTestFunctions(sqlite3 *db){ @@ -213,6 +217,7 @@ static int registerTestFunctions(sqlite3 *db){ { "test_destructor_count", 0, SQLITE_UTF8, test_destructor_count}, { "test_auxdata", -1, SQLITE_UTF8, test_auxdata}, { "test_error", 1, SQLITE_UTF8, test_error}, + { "test_error", 2, SQLITE_UTF8, test_error}, }; int i; extern int Md5_Register(sqlite3*); diff --git a/test/capi3c.test b/test/capi3c.test index 5ba1cc5bc0..5cb9ad3c92 100644 --- a/test/capi3c.test +++ b/test/capi3c.test @@ -13,7 +13,7 @@ # This is a copy of the capi3.test file that has been adapted to # test the new sqlite3_prepare_v2 interface. # -# $Id: capi3c.test,v 1.16 2008/03/19 13:03:34 drh Exp $ +# $Id: capi3c.test,v 1.17 2008/04/10 17:14:07 drh Exp $ # set testdir [file dirname $argv0] @@ -88,6 +88,7 @@ do_test capi3c-1.7 { sqlite3_errmsg $DB } {no such column: namex} + ifcapable {utf16} { do_test capi3c-2.1 { set sql16 [utf16 {SELECT name FROM sqlite_master}] @@ -1243,6 +1244,27 @@ ifcapable progress { do_test capi3c-21.7 { sqlite3_errcode $DB } {SQLITE_INTERRUPT} -} +} + +# Make sure sqlite3_result_error_code() returns the correct error code. +# See ticket #2940 +# +do_test capi3c-22.1 { + db progress 0 {} + set STMT [sqlite3_prepare_v2 db {SELECT test_error('the message',3)} -1 TAIL] + sqlite3_step $STMT +} {SQLITE_PERM} +sqlite3_finalize $STMT +do_test capi3c-22.2 { + set STMT [sqlite3_prepare_v2 db {SELECT test_error('the message',4)} -1 TAIL] + sqlite3_step $STMT +} {SQLITE_ABORT} +sqlite3_finalize $STMT +do_test capi3c-22.3 { + set STMT [sqlite3_prepare_v2 db {SELECT test_error('the message',16)} -1 TAIL] + sqlite3_step $STMT +} {SQLITE_EMPTY} +sqlite3_finalize $STMT + finish_test diff --git a/test/func.test b/test/func.test index 311de1b473..1690e814a9 100644 --- a/test/func.test +++ b/test/func.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this file is testing built-in functions. # -# $Id: func.test,v 1.75 2008/03/21 17:13:13 drh Exp $ +# $Id: func.test,v 1.76 2008/04/10 17:14:07 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -535,10 +535,17 @@ do_test func-14.2 { } {1} do_test func-15.1 { - catchsql { - select test_error(NULL); - } + catchsql {select test_error(NULL)} } {1 {}} +do_test func-15.2 { + catchsql {select test_error('this is the error message')} +} {1 {this is the error message}} +do_test func-15.3 { + catchsql {select test_error('this is the error message',12)} +} {1 {this is the error message}} +do_test func-15.4 { + db errorcode +} {12} # Test the quote function for BLOB and NULL values. do_test func-16.1 {