]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Do not raise an error if an unknown SQL function is found in a CHECK constraint while...
authordan <dan@noemail.net>
Mon, 7 Jan 2013 13:26:23 +0000 (13:26 +0000)
committerdan <dan@noemail.net>
Mon, 7 Jan 2013 13:26:23 +0000 (13:26 +0000)
FossilOrigin-Name: 0a1207c895d9f77586a3a2a4965175909be90503

manifest
manifest.uuid
src/resolve.c
test/check.test

index c0b5bd7ec32358a7e9d44e325f8974cfca540bc7..c499b1397e4cd2249ce6c836453b4407fdd9351b 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C More\sbug\sfixes\sto\sthe\stest_regexp.c\smodule.\s\sBring\stest_regexp.c\sinto\salignment\nwith\sthe\sregexp.c\sfile\sin\sthe\sFossil\ssources.
-D 2013-01-05T17:17:21.332
+C Do\snot\sraise\san\serror\sif\san\sunknown\sSQL\sfunction\sis\sfound\sin\sa\sCHECK\sconstraint\swhile\sparsing\sthe\sschema\sof\san\sexisting\sdatabase.
+D 2013-01-07T13:26:23.647
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in a48faa9e7dd7d556d84f5456eabe5825dd8a6282
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -172,7 +172,7 @@ F src/pragma.c 8907c559d3127729d3bcedb1fe5c59fc196d3a17
 F src/prepare.c 931ad0d852a0df48f79adcba6ce79ca5f475625c
 F src/printf.c 4a9f882f1c1787a8b494a2987765acf9d97ac21f
 F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50
-F src/resolve.c 521bdc0f6c7cf8246c0b9167d726d84005097c30
+F src/resolve.c e41ccbe4e01b1dc22479317a8e0184dff206c61c
 F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0
 F src/select.c 395e458a6dc611cbe1179f424753f0c344957607
 F src/shell.c 11c9611580bb2ffce3a232f31f7f8cc310df0843
@@ -322,7 +322,7 @@ F test/capi3c.test 93d24621c9ff84da9da060f30431e0453db1cdb0
 F test/capi3d.test 17b57ca28be3e37e14c2ba8f787d292d84b724a1
 F test/capi3e.test f7408dda65c92b9056199fdc180f893015f83dde
 F test/cast.test 4c275cbdc8202d6f9c54a3596701719868ac7dc3
-F test/check.test 193f47ed43a8d29aca12b30cd30ceb105fbe710d
+F test/check.test 2eb93611139a7dfaed3be80067c7dc5ceb5fb287
 F test/coalesce.test cee0dccb9fbd2d494b77234bccf9dc6c6786eb91
 F test/collate1.test fd02c4d8afc71879c4bb952586389961a21fb0ce
 F test/collate2.test 04cebe4a033be319d6ddbb3bbc69464e01700b49
@@ -1031,7 +1031,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
 F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
-P e9ac5339603766c120c775bda8ae816d0ccb1503
-R b07326038178e7051b1863f2d68963fe
-U drh
-Z 66007f41514d49327911f47fbc5d3001
+P 7695b88fe0d73fd0a36fb7d8f95350b80615a89e
+R 9a3bff9cb6013200a01cbc0ed4f44558
+U dan
+Z 791019463b5aabd6eb50149b1f94afdd
index 1b51e6969fda94ff669a2e95b376d149d47544c1..2c548d9fc36065f2a0979c9ce0090c20484f1aac 100644 (file)
@@ -1 +1 @@
-7695b88fe0d73fd0a36fb7d8f95350b80615a89e
\ No newline at end of file
+0a1207c895d9f77586a3a2a4965175909be90503
\ No newline at end of file
index 944fb5cad79535cad458d3a30499dc660d63fd0d..e071f250821d76e8043b8e3bf8e98fec794e52f5 100644 (file)
@@ -611,38 +611,39 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
       int auth;                   /* Authorization to use the function */
       int nId;                    /* Number of characters in function name */
       const char *zId;            /* The function name. */
-      FuncDef *pDef;              /* Information about the function */
       u8 enc = ENC(pParse->db);   /* The database encoding */
 
       testcase( pExpr->op==TK_CONST_FUNC );
       assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
       zId = pExpr->u.zToken;
       nId = sqlite3Strlen30(zId);
-      pDef = sqlite3FindFunction(pParse->db, zId, nId, n, enc, 0);
-      if( pDef==0 ){
-        pDef = sqlite3FindFunction(pParse->db, zId, nId, -2, enc, 0);
+      if( pParse->db->init.busy==0 ){
+        FuncDef *pDef = sqlite3FindFunction(pParse->db, zId, nId, n, enc, 0);
         if( pDef==0 ){
-          no_such_func = 1;
+          pDef = sqlite3FindFunction(pParse->db, zId, nId, -2, enc, 0);
+          if( pDef==0 ){
+            no_such_func = 1;
+          }else{
+            wrong_num_args = 1;
+          }
         }else{
-          wrong_num_args = 1;
+          is_agg = pDef->xFunc==0;
         }
-      }else{
-        is_agg = pDef->xFunc==0;
-      }
 #ifndef SQLITE_OMIT_AUTHORIZATION
-      if( pDef ){
-        auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0, pDef->zName, 0);
-        if( auth!=SQLITE_OK ){
-          if( auth==SQLITE_DENY ){
-            sqlite3ErrorMsg(pParse, "not authorized to use function: %s",
-                                    pDef->zName);
-            pNC->nErr++;
+        if( pDef ){
+          auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0, pDef->zName, 0);
+          if( auth!=SQLITE_OK ){
+            if( auth==SQLITE_DENY ){
+              sqlite3ErrorMsg(pParse, "not authorized to use function: %s",
+                  pDef->zName);
+              pNC->nErr++;
+            }
+            pExpr->op = TK_NULL;
+            return WRC_Prune;
           }
-          pExpr->op = TK_NULL;
-          return WRC_Prune;
         }
-      }
 #endif
+      }
       if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){
         sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId);
         pNC->nErr++;
index bf0b770a006b554da7d331f402d5ee536c637771..99b72ac8af9b02ba3502762569a9417cda5f031f 100644 (file)
@@ -15,6 +15,7 @@
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
+set ::testprefix check
 
 # Only run these tests if the build includes support for CHECK constraints
 ifcapable !check {
@@ -413,4 +414,42 @@ do_test check-6.15 {
 
 }
 
+#--------------------------------------------------------------------------
+# If a connection opens a database that contains a CHECK constraint that
+# uses an unknown UDF, the schema should not be considered malformed.
+# Attempting to modify the table should fail (since the CHECK constraint
+# cannot be tested).
+#
+reset_db
+proc myfunc {x} {expr $x < 10}
+db func myfunc myfunc
+
+do_execsql_test  7.1 { CREATE TABLE t6(a CHECK (myfunc(a))) }
+do_execsql_test  7.2 { INSERT INTO t6 VALUES(9)  }
+do_catchsql_test 7.3 { INSERT INTO t6 VALUES(11) } {1 {constraint failed}}
+
+do_test 7.4 {
+  sqlite3 db2 test.db
+  execsql { SELECT * FROM t6 } db2 
+} {9}
+
+do_test 7.5 {
+  catchsql { INSERT INTO t6 VALUES(8) } db2
+} {1 {unknown function: myfunc()}}
+
+do_test 7.6 {
+  catchsql { CREATE TABLE t7(a CHECK (myfunc(a))) } db2
+} {1 {no such function: myfunc}}
+
+do_test 7.7 {
+  db2 func myfunc myfunc
+  execsql { INSERT INTO t6 VALUES(8) } db2
+} {}
+
+do_test 7.8 {
+  db2 func myfunc myfunc
+  catchsql { INSERT INTO t6 VALUES(12) } db2
+} {1 {constraint failed}}
+
+
 finish_test