SQLite

Check-in [0ad1ed8ef0]
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
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 0ad1ed8ef0b5fb5d8db44479373b2b93d8fcfd66
User & Date: drh 2014-08-06 00:29:06.807
Context
2014-08-06
01:08
Fix typos in the opcode documentation. Comment changes only. No changes to code. (check-in: 717245d487 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: 0ad1ed8ef0 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: 29ba812825 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/expr.c.
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
        pFarg = pExpr->x.pList;
      }
      nFarg = pFarg ? pFarg->nExpr : 0;
      assert( !ExprHasProperty(pExpr, EP_IntValue) );
      zId = pExpr->u.zToken;
      nId = sqlite3Strlen30(zId);
      pDef = sqlite3FindFunction(db, zId, nId, nFarg, enc, 0);
      if( pDef==0 ){
        sqlite3ErrorMsg(pParse, "unknown function: %.*s()", nId, zId);
        break;
      }
      if( pDef->xFunc==0 ){
        sqlite3ErrorMsg(pParse, "misuse of aggregate function: %.*s()",
                        nId, zId);
        break;
      }

      /* Attempt a direct implementation of the built-in COALESCE() and
      ** IFNULL() functions.  This avoids unnecessary evalation of
      ** arguments past the first non-NULL argument.
      */
      if( pDef->funcFlags & SQLITE_FUNC_COALESCE ){
        int endCoalesce = sqlite3VdbeMakeLabel(v);







|



<
<
<
<
<







2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770





2771
2772
2773
2774
2775
2776
2777
        pFarg = pExpr->x.pList;
      }
      nFarg = pFarg ? pFarg->nExpr : 0;
      assert( !ExprHasProperty(pExpr, EP_IntValue) );
      zId = pExpr->u.zToken;
      nId = sqlite3Strlen30(zId);
      pDef = sqlite3FindFunction(db, zId, nId, nFarg, enc, 0);
      if( pDef==0 || pDef->xFunc==0 ){
        sqlite3ErrorMsg(pParse, "unknown function: %.*s()", nId, zId);
        break;
      }






      /* Attempt a direct implementation of the built-in COALESCE() and
      ** IFNULL() functions.  This avoids unnecessary evalation of
      ** arguments past the first non-NULL argument.
      */
      if( pDef->funcFlags & SQLITE_FUNC_COALESCE ){
        int endCoalesce = sqlite3VdbeMakeLabel(v);
Changes to test/table.test.
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773

774
775
do_execsql_test table-16.1 {
  CREATE TABLE t16(x DEFAULT(max(1)));
  INSERT INTO t16(x) VALUES(123);
  SELECT rowid, x FROM t16;
} {1 123}
do_catchsql_test table-16.2 {
  INSERT INTO t16(rowid) VALUES(4);
} {1 {misuse of aggregate function: max()}}
do_execsql_test table-16.3 {
  DROP TABLE t16;
  CREATE TABLE t16(x DEFAULT(abs(1)));
  INSERT INTO t16(rowid) VALUES(4);
  SELECT rowid, x FROM t16;
} {4 1}
do_catchsql_test table-16.4 {
  DROP TABLE t16;
  CREATE TABLE t16(x DEFAULT(avg(1)));
  INSERT INTO t16(rowid) VALUES(123);
  SELECT rowid, x FROM t16;
} {1 {misuse of aggregate function: avg()}}
do_catchsql_test table-16.5 {
  DROP TABLE t16;
  CREATE TABLE t16(x DEFAULT(count()));
  INSERT INTO t16(rowid) VALUES(123);
  SELECT rowid, x FROM t16;
} {1 {misuse of aggregate function: count()}}
do_catchsql_test table-16.6 {
  DROP TABLE t16;
  CREATE TABLE t16(x DEFAULT(group_concat('x',',')));
  INSERT INTO t16(rowid) VALUES(123);
  SELECT rowid, x FROM t16;
} {1 {misuse of aggregate function: group_concat()}}




finish_test







|











|





|





|
|
|
>


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

finish_test