/ Check-in [0ad1ed8e]
Login

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

Overview
Comment:A simpler fix for ticket [3a88d85f36704eebe1] - one that uses less code. The error message is not quite as good, but as this error has apparently not previously occurred in over 8 years of heavy use, that is not seen as a serious problem.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:0ad1ed8ef0b5fb5d8db44479373b2b93d8fcfd66
User & Date: drh 2014-08-06 00:29:06
Context
2014-08-06
01:08
Fix typos in the opcode documentation. Comment changes only. No changes to code. check-in: 717245d4 user: drh tags: trunk
00:29
A simpler fix for ticket [3a88d85f36704eebe1] - one that uses less code. The error message is not quite as good, but as this error has apparently not previously occurred in over 8 years of heavy use, that is not seen as a serious problem. check-in: 0ad1ed8e user: drh tags: trunk
2014-08-05
21:31
Ensure that aggregate functions are not used when evaluating a default value for a table column. Candidate fix for ticket [3a88d85f36704eebe134f7]. check-in: 29ba8128 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/expr.c.

  2760   2760           pFarg = pExpr->x.pList;
  2761   2761         }
  2762   2762         nFarg = pFarg ? pFarg->nExpr : 0;
  2763   2763         assert( !ExprHasProperty(pExpr, EP_IntValue) );
  2764   2764         zId = pExpr->u.zToken;
  2765   2765         nId = sqlite3Strlen30(zId);
  2766   2766         pDef = sqlite3FindFunction(db, zId, nId, nFarg, enc, 0);
  2767         -      if( pDef==0 ){
         2767  +      if( pDef==0 || pDef->xFunc==0 ){
  2768   2768           sqlite3ErrorMsg(pParse, "unknown function: %.*s()", nId, zId);
  2769   2769           break;
  2770   2770         }
  2771         -      if( pDef->xFunc==0 ){
  2772         -        sqlite3ErrorMsg(pParse, "misuse of aggregate function: %.*s()",
  2773         -                        nId, zId);
  2774         -        break;
  2775         -      }
  2776   2771   
  2777   2772         /* Attempt a direct implementation of the built-in COALESCE() and
  2778   2773         ** IFNULL() functions.  This avoids unnecessary evalation of
  2779   2774         ** arguments past the first non-NULL argument.
  2780   2775         */
  2781   2776         if( pDef->funcFlags & SQLITE_FUNC_COALESCE ){
  2782   2777           int endCoalesce = sqlite3VdbeMakeLabel(v);

Changes to test/table.test.

   740    740   do_execsql_test table-16.1 {
   741    741     CREATE TABLE t16(x DEFAULT(max(1)));
   742    742     INSERT INTO t16(x) VALUES(123);
   743    743     SELECT rowid, x FROM t16;
   744    744   } {1 123}
   745    745   do_catchsql_test table-16.2 {
   746    746     INSERT INTO t16(rowid) VALUES(4);
   747         -} {1 {misuse of aggregate function: max()}}
          747  +} {1 {unknown function: max()}}
   748    748   do_execsql_test table-16.3 {
   749    749     DROP TABLE t16;
   750    750     CREATE TABLE t16(x DEFAULT(abs(1)));
   751    751     INSERT INTO t16(rowid) VALUES(4);
   752    752     SELECT rowid, x FROM t16;
   753    753   } {4 1}
   754    754   do_catchsql_test table-16.4 {
   755    755     DROP TABLE t16;
   756    756     CREATE TABLE t16(x DEFAULT(avg(1)));
   757    757     INSERT INTO t16(rowid) VALUES(123);
   758    758     SELECT rowid, x FROM t16;
   759         -} {1 {misuse of aggregate function: avg()}}
          759  +} {1 {unknown function: avg()}}
   760    760   do_catchsql_test table-16.5 {
   761    761     DROP TABLE t16;
   762    762     CREATE TABLE t16(x DEFAULT(count()));
   763    763     INSERT INTO t16(rowid) VALUES(123);
   764    764     SELECT rowid, x FROM t16;
   765         -} {1 {misuse of aggregate function: count()}}
          765  +} {1 {unknown function: count()}}
   766    766   do_catchsql_test table-16.6 {
   767    767     DROP TABLE t16;
   768    768     CREATE TABLE t16(x DEFAULT(group_concat('x',',')));
   769    769     INSERT INTO t16(rowid) VALUES(123);
   770    770     SELECT rowid, x FROM t16;
   771         -} {1 {misuse of aggregate function: group_concat()}}
   772         -
   773         -
          771  +} {1 {unknown function: group_concat()}}
          772  +do_catchsql_test table-16.7 {
          773  +  INSERT INTO t16 DEFAULT VALUES;
          774  +} {1 {unknown function: group_concat()}}
   774    775   
   775    776   finish_test