From: dan Date: Mon, 7 Jan 2013 13:26:23 +0000 (+0000) Subject: Do not raise an error if an unknown SQL function is found in a CHECK constraint while... X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=002bc1a34fcba8afbe2ba10279d8e81860d896ed;p=thirdparty%2Fsqlite.git Do not raise an error if an unknown SQL function is found in a CHECK constraint while parsing the schema of an existing database. FossilOrigin-Name: 0a1207c895d9f77586a3a2a4965175909be90503 --- diff --git a/manifest b/manifest index c0b5bd7ec3..c499b1397e 100644 --- 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 diff --git a/manifest.uuid b/manifest.uuid index 1b51e6969f..2c548d9fc3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7695b88fe0d73fd0a36fb7d8f95350b80615a89e \ No newline at end of file +0a1207c895d9f77586a3a2a4965175909be90503 \ No newline at end of file diff --git a/src/resolve.c b/src/resolve.c index 944fb5cad7..e071f25082 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -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++; diff --git a/test/check.test b/test/check.test index bf0b770a00..99b72ac8af 100644 --- a/test/check.test +++ b/test/check.test @@ -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