SQLite

Check-in [ad064bd429]
Login

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

Overview
Comment:Fix a bug that was preventing the library from opening existing files. (CVS 1358)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: ad064bd429602fcac26b377841da90a1a56f5966
User & Date: danielk1977 2004-05-11 09:50:02.000
Context
2004-05-11
09:57
A different fix for the problem with opening existing files. See also check-in (1358). (CVS 1359) (check-in: 93deaf54c6 user: drh tags: trunk)
09:50
Fix a bug that was preventing the library from opening existing files. (CVS 1358) (check-in: ad064bd429 user: danielk1977 tags: trunk)
09:31
Fix an offset problem in the meta values that was causing problems for many tests. (CVS 1357) (check-in: 6d378cb7e7 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/main.c.
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
**
*************************************************************************
** Main file for the SQLite library.  The routines in this file
** implement the programmer interface to the library.  Routines in
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.173 2004/05/11 09:31:32 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>

/*
** A pointer to this structure is used to communicate information







|







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
**
*************************************************************************
** Main file for the SQLite library.  The routines in this file
** implement the programmer interface to the library.  Routines in
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.174 2004/05/11 09:50:02 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>

/*
** A pointer to this structure is used to communicate information
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
     "  rootpage integer,\n"
     "  sql text\n"
     ")"
  ;

  /* The following SQL will read the schema from the master tables.
  */
  static char init_script[] = 
     "SELECT type, name, rootpage, sql, 1 FROM sqlite_temp_master "
     "UNION ALL "
     "SELECT type, name, rootpage, sql, 0 FROM sqlite_master";

  assert( iDb>=0 && iDb!=1 && iDb<db->nDb );

  /* Construct the schema tables: sqlite_master and sqlite_temp_master
  */
  sqlite3SafetyOff(db);







|
|
|







161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
     "  rootpage integer,\n"
     "  sql text\n"
     ")"
  ;

  /* The following SQL will read the schema from the master tables.
  */
  static char init_script1[] = 
     "SELECT type, name, rootpage, sql, 1 FROM sqlite_temp_master";
  static char init_script2[] = 
     "SELECT type, name, rootpage, sql, 0 FROM sqlite_master";

  assert( iDb>=0 && iDb!=1 && iDb<db->nDb );

  /* Construct the schema tables: sqlite_master and sqlite_temp_master
  */
  sqlite3SafetyOff(db);
281
282
283
284
285
286
287








288




289
290
291
292
293
294
295
  assert( db->init.busy );
  sqlite3SafetyOff(db);
  if( rc==SQLITE_EMPTY ){
    /* For an empty database, there is nothing to read */
    rc = SQLITE_OK;
  }else{
    if( iDb==0 ){








      rc = sqlite3_exec(db, init_script, sqlite3InitCallback, &initData, 0);




    }else{
      char *zSql = 0;
      sqlite3SetString(&zSql, 
         "SELECT type, name, rootpage, sql, ", zDbNum, " FROM \"",
         db->aDb[iDb].zName, "\".sqlite_master", (char*)0);
      rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
      sqliteFree(zSql);







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







281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
  assert( db->init.busy );
  sqlite3SafetyOff(db);
  if( rc==SQLITE_EMPTY ){
    /* For an empty database, there is nothing to read */
    rc = SQLITE_OK;
  }else{
    if( iDb==0 ){
      /* This SQL statement tries to read the temp.* schema from the
      ** sqlite_temp_master table. It might return SQLITE_EMPTY. We
      ** unset the SQLITE_InternChanges flag temporarily to ensure
      ** that the sqlite_master entry is not removed from the internal
      ** schema if this does return SQLITE_EMPTY.
      */
      assert( db->flags&SQLITE_InternChanges );
      db->flags &= ~SQLITE_InternChanges;
      rc = sqlite3_exec(db, init_script1, sqlite3InitCallback, &initData, 0);
      db->flags |= SQLITE_InternChanges;
      if( rc==SQLITE_OK || rc==SQLITE_EMPTY ){
        rc = sqlite3_exec(db, init_script2, sqlite3InitCallback, &initData, 0);
      }
    }else{
      char *zSql = 0;
      sqlite3SetString(&zSql, 
         "SELECT type, name, rootpage, sql, ", zDbNum, " FROM \"",
         db->aDb[iDb].zName, "\".sqlite_master", (char*)0);
      rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
      sqliteFree(zSql);
Changes to test/insert.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2001 September 15
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this file is testing the INSERT statement.
#
# $Id: insert.test,v 1.15 2003/06/15 23:42:25 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Try to insert into a non-existant table.
#
do_test insert-1.1 {













|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2001 September 15
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this file is testing the INSERT statement.
#
# $Id: insert.test,v 1.16 2004/05/11 09:50:02 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Try to insert into a non-existant table.
#
do_test insert-1.1 {
221
222
223
224
225
226
227

228
229
230


231
232
233
234
235
236


237
238
239
240
241
242
243
244
245
246
247
do_test insert-5.3 {
  # verify that a temporary table is used to copy t4 to t4
  set x [execsql {
    EXPLAIN INSERT INTO t4 SELECT x+2 FROM t4;
  }]
  expr {[lsearch $x OpenTemp]>0}
} {1}

do_test insert-5.4 {
  # Verify that table "test1" begins on page 3.  This should be the same
  # page number used by "t4" above.


  execsql {
    SELECT rootpage FROM sqlite_master WHERE name='test1';
  }
} {3}
do_test insert-5.5 {
  # Verify that "t4" begins on page 3.


  execsql {
    SELECT rootpage FROM sqlite_temp_master WHERE name='t4';
  }
} {3}
do_test insert-5.6 {
  # This should not use an intermediate temporary table.
  execsql {
    INSERT INTO t4 SELECT one FROM test1 WHERE three=7;
    SELECT * FROM t4
  }
} {1 2 8}







>



>
>



|


>
>



|







221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
do_test insert-5.3 {
  # verify that a temporary table is used to copy t4 to t4
  set x [execsql {
    EXPLAIN INSERT INTO t4 SELECT x+2 FROM t4;
  }]
  expr {[lsearch $x OpenTemp]>0}
} {1}

do_test insert-5.4 {
  # Verify that table "test1" begins on page 3.  This should be the same
  # page number used by "t4" above.
  #
  # Update for v3 - the first table now begins on page 2 of each file, not 3.
  execsql {
    SELECT rootpage FROM sqlite_master WHERE name='test1';
  }
} {2}
do_test insert-5.5 {
  # Verify that "t4" begins on page 3.
  #
  # Update for v3 - the first table now begins on page 2 of each file, not 3.
  execsql {
    SELECT rootpage FROM sqlite_temp_master WHERE name='t4';
  }
} {2}
do_test insert-5.6 {
  # This should not use an intermediate temporary table.
  execsql {
    INSERT INTO t4 SELECT one FROM test1 WHERE three=7;
    SELECT * FROM t4
  }
} {1 2 8}