SQLite

Check-in [af7173a1]
Login

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

Overview
Comment:Ensure that the database encoding is detected before the code generator gets too far down into byte-code generation and execution, but not so early that it interferes with initialization. Forum thread bc75a4d20b756044.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: af7173a10ec6a4ab465207c1ee20393e8b5f06604c0f3b2fdc19e52c2fc013d5
User & Date: drh 2024-11-04 19:08:53
Context
2024-11-04
19:18
Fix harmless compiler warnings. (check-in: bc93e179 user: drh tags: trunk)
19:08
Ensure that the database encoding is detected before the code generator gets too far down into byte-code generation and execution, but not so early that it interferes with initialization. Forum thread bc75a4d20b756044. (check-in: af7173a1 user: drh tags: trunk)
16:59
Avoid loading the entire record into memory for an sqlite3_preupdate_old() call that retrieves an IPK value. (check-in: 7f4de437 user: dan tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ext/rtree/rtreecheck.test.

194
195
196
197
198
199
200
201
202
203
204
  # has already been loaded. 
  do_catchsql_test 6.1.inmemory_journal {
    SELECT ( 'elvis' IN(SELECT rtreecheck('t1')) ) FROM (SELECT 1) GROUP BY 1;
  } {0 0}
} else {
  do_catchsql_test 6.1 {
    SELECT ( 'elvis' IN(SELECT rtreecheck('t1')) ) FROM (SELECT 1) GROUP BY 1;
  } {1 {database table is locked}}
}

finish_test







|



194
195
196
197
198
199
200
201
202
203
204
  # has already been loaded. 
  do_catchsql_test 6.1.inmemory_journal {
    SELECT ( 'elvis' IN(SELECT rtreecheck('t1')) ) FROM (SELECT 1) GROUP BY 1;
  } {0 0}
} else {
  do_catchsql_test 6.1 {
    SELECT ( 'elvis' IN(SELECT rtreecheck('t1')) ) FROM (SELECT 1) GROUP BY 1;
  } {0 0}
}

finish_test

Changes to src/parse.y.

495
496
497
498
499
500
501



502

503
504
505
506
507
508
509
}
%endif  SQLITE_OMIT_VIEW

//////////////////////// The SELECT statement /////////////////////////////////
//
cmd ::= select(X).  {
  SelectDest dest = {SRT_Output, 0, 0, 0, 0, 0, 0};



  sqlite3Select(pParse, X, &dest);

  sqlite3SelectDelete(pParse->db, X);
}

%type select {Select*}
%destructor select {sqlite3SelectDelete(pParse->db, $$);}
%type selectnowith {Select*}
%destructor selectnowith {sqlite3SelectDelete(pParse->db, $$);}







>
>
>
|
>







495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
}
%endif  SQLITE_OMIT_VIEW

//////////////////////// The SELECT statement /////////////////////////////////
//
cmd ::= select(X).  {
  SelectDest dest = {SRT_Output, 0, 0, 0, 0, 0, 0};
  if( (pParse->db->mDbFlags & DBFLAG_EncodingFixed)!=0
   || sqlite3ReadSchema(pParse)==SQLITE_OK
  ){
    sqlite3Select(pParse, X, &dest);
  }
  sqlite3SelectDelete(pParse->db, X);
}

%type select {Select*}
%destructor select {sqlite3SelectDelete(pParse->db, $$);}
%type selectnowith {Select*}
%destructor selectnowith {sqlite3SelectDelete(pParse->db, $$);}

Changes to src/prepare.c.

302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#ifndef SQLITE_OMIT_UTF16
      /* If opening the main database, set ENC(db). */
      encoding = (u8)meta[BTREE_TEXT_ENCODING-1] & 3;
      if( encoding==0 ) encoding = SQLITE_UTF8;
#else
      encoding = SQLITE_UTF8;
#endif
      if( db->nVdbeActive>0 && encoding!=ENC(db)
       && (db->mDbFlags & DBFLAG_Vacuum)==0
      ){
        rc = SQLITE_LOCKED;
        goto initone_error_out;
      }else{
        sqlite3SetTextEncoding(db, encoding);
      }
    }else{
      /* If opening an attached database, the encoding much match ENC(db) */
      if( (meta[BTREE_TEXT_ENCODING-1] & 3)!=ENC(db) ){
        sqlite3SetString(pzErrMsg, db, "attached databases must use the same"
            " text encoding as main database");
        rc = SQLITE_ERROR;
        goto initone_error_out;







<
<
<
<
<
<
|
<







302
303
304
305
306
307
308






309

310
311
312
313
314
315
316
#ifndef SQLITE_OMIT_UTF16
      /* If opening the main database, set ENC(db). */
      encoding = (u8)meta[BTREE_TEXT_ENCODING-1] & 3;
      if( encoding==0 ) encoding = SQLITE_UTF8;
#else
      encoding = SQLITE_UTF8;
#endif






      sqlite3SetTextEncoding(db, encoding);

    }else{
      /* If opening an attached database, the encoding much match ENC(db) */
      if( (meta[BTREE_TEXT_ENCODING-1] & 3)!=ENC(db) ){
        sqlite3SetString(pzErrMsg, db, "attached databases must use the same"
            " text encoding as main database");
        rc = SQLITE_ERROR;
        goto initone_error_out;

Changes to test/enc.test.

245
246
247
248
249
250
251





























252
  INSERT INTO t1 VALUES('xxx', 'yyy', 'zzz');
}
do_execsql_test enc-12.10 {
  SELECT * FROM t2;
  SELECT * FROM t1;
} {d e f xxx yyy zzz}






























finish_test







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
  INSERT INTO t1 VALUES('xxx', 'yyy', 'zzz');
}
do_execsql_test enc-12.10 {
  SELECT * FROM t2;
  SELECT * FROM t1;
} {d e f xxx yyy zzz}


# 2024-11-04
# https://sqlite.org/forum/forumpost/bc75a4d20b756044
#
# Ensure the database encoding is detected in a timely manner,
# and before we get too far along in generating and running
# bytecode.
#
# See also check-in https://sqlite.org/src/info/a02da71f3a.
#
db close
forcedelete utf16.db
sqlite3 db utf16.db
db eval {PRAGMA encoding=UTF16; CREATE TABLE t2(y); INSERT INTO t2 VALUES('utf16');}
db close
sqlite3 db utf16.db
do_test enc-13.1 {
  db eval {PRAGMA function_list} {db eval {SELECT * FROM sqlite_schema}}
} {}
ifcapable rtree {
  db eval {CREATE VIRTUAL TABLE t3 USING rtree(id,x1,x2)}
  db close
  sqlite3 db utf16.db
  do_execsql_test enc-13.2 {
    WITH t1(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM t1 WHERE x<3)
    SELECT rtreecheck('t3') FROM t1;
  } {ok ok ok}
}

finish_test

Changes to test/misc5.test.

519
520
521
522
523
524
525

526
527
528
529
530
531
532
    puts $fd "This is not really a database"
    close $fd
    sqlite3 db test.db
    catchsql {
      CREATE TABLE t1(a,b,c);
    }
  } {1 {file is not a database}}

}

# Ticket #1371.  Allow floating point numbers of the form .N  or N.
#
do_test misc5-5.1 {
  execsql {SELECT .1 }
} 0.1







>







519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
    puts $fd "This is not really a database"
    close $fd
    sqlite3 db test.db
    catchsql {
      CREATE TABLE t1(a,b,c);
    }
  } {1 {file is not a database}}
  reset_db
}

# Ticket #1371.  Allow floating point numbers of the form .N  or N.
#
do_test misc5-5.1 {
  execsql {SELECT .1 }
} 0.1