SQLite

Check-in [03b003c988]
Login

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

Overview
Comment:Do not allow the "PRAGMA encoding" statement to change the database encoding if TEMP content exists, or content in any other attached database. Formerly, encoding changes were allowed if just the main database file was empty. Ticket [a08879a4a476eea9].
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 03b003c988d27f3aa1b1e44972ee5a3c7e44ad667ec7f2b8a31d0411c66583d3
User & Date: drh 2020-01-15 16:20:16.110
Context
2020-01-16
11:51
Clean up the definitions of the TERM_ constants in the code generator. Formatting only - no logic changes. (check-in: af06f80a59 user: drh tags: trunk)
2020-01-15
16:20
Do not allow the "PRAGMA encoding" statement to change the database encoding if TEMP content exists, or content in any other attached database. Formerly, encoding changes were allowed if just the main database file was empty. Ticket [a08879a4a476eea9]. (check-in: 03b003c988 user: drh tags: trunk)
2020-01-14
16:50
Fix the urifuncs.c extension (used for testing and debugging only) so that the sqlite3_filename_database() SQL function and its siblings correctly handle an invalid schema name passed in as the argument. (check-in: 3d7434a9d8 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/pragma.c.
1820
1821
1822
1823
1824
1825
1826



1827
1828
1829
1830




1831
1832
1833
1834
1835
1836
1837
      returnSingleText(v, encnames[ENC(pParse->db)].zName);
    }else{                        /* "PRAGMA encoding = XXX" */
      /* Only change the value of sqlite.enc if the database handle is not
      ** initialized. If the main database exists, the new sqlite.enc value
      ** will be overwritten when the schema is next loaded. If it does not
      ** already exists, it will be created to use the new encoding value.
      */



      if( 
        !(DbHasProperty(db, 0, DB_SchemaLoaded)) || 
        DbHasProperty(db, 0, DB_Empty) 
      ){




        for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
          if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){
            SCHEMA_ENC(db) = ENC(db) =
                pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE;
            break;
          }
        }







>
>
>
|
|
|
|
>
>
>
>







1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
      returnSingleText(v, encnames[ENC(pParse->db)].zName);
    }else{                        /* "PRAGMA encoding = XXX" */
      /* Only change the value of sqlite.enc if the database handle is not
      ** initialized. If the main database exists, the new sqlite.enc value
      ** will be overwritten when the schema is next loaded. If it does not
      ** already exists, it will be created to use the new encoding value.
      */
      int canChangeEnc = 1;  /* True if allowed to change the encoding */
      int i;                 /* For looping over all attached databases */
      for(i=0; i<db->nDb; i++){
        if( db->aDb[i].pBt!=0
         && DbHasProperty(db,i,DB_SchemaLoaded)
         && !DbHasProperty(db,i,DB_Empty)
        ){
          canChangeEnc = 0;
        }
      }
      if( canChangeEnc ){
        for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
          if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){
            SCHEMA_ENC(db) = ENC(db) =
                pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE;
            break;
          }
        }
Changes to test/enc2.test.
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The focus of
# this file is testing the SQLite routines used for converting between the
# various suported unicode encodings (UTF-8, UTF-16, UTF-16le and
# UTF-16be).
#
# $Id: enc2.test,v 1.29 2007/10/09 08:29:32 danielk1977 Exp $

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

# If UTF16 support is disabled, ignore the tests in this file
#
ifcapable {!utf16} {







<







9
10
11
12
13
14
15

16
17
18
19
20
21
22
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The focus of
# this file is testing the SQLite routines used for converting between the
# various suported unicode encodings (UTF-8, UTF-16, UTF-16le and
# UTF-16be).
#


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

# If UTF16 support is disabled, ignore the tests in this file
#
ifcapable {!utf16} {
547
548
549
550
551
552
553
554













555
  }
  db close
  sqlite3 db test.db
  db eval {
    SELECT name FROM sqlite_master
  }
} {t1 t2}














finish_test








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

546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
  }
  db close
  sqlite3 db test.db
  db eval {
    SELECT name FROM sqlite_master
  }
} {t1 t2}

# 2020-01-15 ticket a08879a4a476eea9
# Do not allow a database connection encoding change unless *all*
# attached databases are empty.
#
reset_db
do_execsql_test enc2-11.10 {
  PRAGMA encoding=UTF8;
  CREATE TEMP TABLE t1(x);
  INSERT INTO t1 VALUES('this is a test');
  PRAGMA encoding=UTF16;
  SELECT * FROM t1;
} {{this is a test}}

finish_test