/ Check-in [e5d07045fa]
Login

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

Overview
Comment:Fix a problem in the shell tool. In some cases sqlite3_errmsg() was being called before sqlite3_finalize(), causing error messages to be more generic than they should be.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e5d07045fabe0803715cfb291aa9e971235cb08a
User & Date: dan 2010-01-05 04:59:57
Context
2010-01-05
13:40
Make sure new pages are zeroed even when loading a freelist page using the noContent option. This prevents a harmless valgrind warning. check-in: e47e213369 user: drh tags: trunk
04:59
Fix a problem in the shell tool. In some cases sqlite3_errmsg() was being called before sqlite3_finalize(), causing error messages to be more generic than they should be. check-in: e5d07045fa user: dan tags: trunk
03:30
In the debugging memory allocator, initialize new memory allocations to pseudo-randomness in an effort to find problems with memcmp() of structures that have uninitialized pad bytes. check-in: 6462817b2f user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/shell.c.

1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
....
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941


1942
1943
1944
1945
1946
1947
1948
  sqlite3 *db,                                /* An open database */
  const char *zSql,                           /* SQL to be evaluated */
  int (*xCallback)(void*,int,char**,char**,int*),   /* Callback function */
                                              /* (not the same as sqlite3_exec) */
  struct callback_data *pArg,                 /* Pointer to struct callback_data */
  char **pzErrMsg                             /* Error msg written here */
){
  sqlite3_stmt *pStmt = NULL;
  int rc = SQLITE_OK;
  int rc2;
  const char *zLeftover;      /* Tail of unprocessed SQL */

  if( pzErrMsg ){
    *pzErrMsg = NULL;
  }

  while( zSql[0] && (SQLITE_OK == rc) ){
    rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
................................................................................
        }else{
          do{
            rc = sqlite3_step(pStmt);
          } while( rc == SQLITE_ROW );
        }
      }

      /* if the last sqlite3_step() didn't complete successfully... */
      if( (SQLITE_OK != rc) && (SQLITE_DONE != rc) ){ 
        if( pzErrMsg ){
          *pzErrMsg = save_err_msg(db);
        }
      }else{
        rc = SQLITE_OK;
      }

      rc2 = sqlite3_finalize(pStmt);
      /* if the last sqlite3_finalize() didn't complete successfully 
      ** AND we don't have a saved error from sqlite3_step ... */
      if( (SQLITE_OK != rc2) && (SQLITE_OK == rc) ){
        rc = rc2;
        if( pzErrMsg ){
          *pzErrMsg = save_err_msg(db);
        }
      }

      if( SQLITE_OK == rc ){ 
        zSql = zLeftover;
        while( isspace(zSql[0]) ) zSql++;


      }
    }
  } /* end while */

  return rc;
}








|
|
<
|







 







|
|
|
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
|


>
>







1829
1830
1831
1832
1833
1834
1835
1836
1837

1838
1839
1840
1841
1842
1843
1844
1845
....
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921






1922









1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
  sqlite3 *db,                                /* An open database */
  const char *zSql,                           /* SQL to be evaluated */
  int (*xCallback)(void*,int,char**,char**,int*),   /* Callback function */
                                              /* (not the same as sqlite3_exec) */
  struct callback_data *pArg,                 /* Pointer to struct callback_data */
  char **pzErrMsg                             /* Error msg written here */
){
  sqlite3_stmt *pStmt = NULL;     /* Statement to execute. */
  int rc = SQLITE_OK;             /* Return Code */

  const char *zLeftover;          /* Tail of unprocessed SQL */

  if( pzErrMsg ){
    *pzErrMsg = NULL;
  }

  while( zSql[0] && (SQLITE_OK == rc) ){
    rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
................................................................................
        }else{
          do{
            rc = sqlite3_step(pStmt);
          } while( rc == SQLITE_ROW );
        }
      }

      /* Finalize the statement just executed. If this fails, save a 
      ** copy of the error message. Otherwise, set zSql to point to the
      ** next statement to execute. */






      rc = sqlite3_finalize(pStmt);









      if( rc==SQLITE_OK ){
        zSql = zLeftover;
        while( isspace(zSql[0]) ) zSql++;
      }else if( pzErrMsg ){
        *pzErrMsg = save_err_msg(db);
      }
    }
  } /* end while */

  return rc;
}

Changes to tool/shell1.test.

191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
  list $rc \
       [regexp {Error: missing argument for option: -nullvalue} $res]
} {1 1}

# -version             show SQLite version
do_test shell1-1.16.1 {
  catchcmd "-version test.db" "" 
} {0 3.6.21}

#----------------------------------------------------------------------------
# Test cases shell1-2.*: Basic "dot" command token parsing.
#

# check first token handling
do_test shell1-2.1.1 {







|







191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
  list $rc \
       [regexp {Error: missing argument for option: -nullvalue} $res]
} {1 1}

# -version             show SQLite version
do_test shell1-1.16.1 {
  catchcmd "-version test.db" "" 
} {0 3.6.22}

#----------------------------------------------------------------------------
# Test cases shell1-2.*: Basic "dot" command token parsing.
#

# check first token handling
do_test shell1-2.1.1 {

Changes to tool/shell2.test.

77
78
79
80
81
82
83



84








85





# Ticket [f5cb008a65].
do_test shell2-1.2.1 {
  set rc [catch { eval exec $CLI \":memory:\" \"select 3\" \"select 4\" } msg]
  list $rc \
       [regexp {Error: too many options: "select 4"} $msg]
} {1 1}


























>
>
>
|
>
>
>
>
>
>
>
>

>
>
>
>
>
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Ticket [f5cb008a65].
do_test shell2-1.2.1 {
  set rc [catch { eval exec $CLI \":memory:\" \"select 3\" \"select 4\" } msg]
  list $rc \
       [regexp {Error: too many options: "select 4"} $msg]
} {1 1}

# Test a problem reported on the mailing list. The shell was at one point
# returning the generic SQLITE_ERROR message ("SQL error or missing database")
# instead of the "too many levels..." message in the test below.
#
do_test shell2-1.3 {
  catchcmd "-batch test.db" {
    PRAGMA recursive_triggers = ON;
    CREATE TABLE t5(a PRIMARY KEY, b, c);
    INSERT INTO t5 VALUES(1, 2, 3);
    CREATE TRIGGER au_tble AFTER UPDATE ON t5 BEGIN
      UPDATE OR IGNORE t5 SET a = new.a, c = 10;
    END;

    UPDATE OR REPLACE t5 SET a = 4 WHERE a = 1;
  }
} {1 {Error: near line 9: too many levels of trigger recursion}}