/ Check-in [79f24184]
Login

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

Overview
Comment:Have sqlite3ota.c use grave accents instead of double-quotes to enclose identifiers in generated SQL. To avoid having the SQL engine substitute a literal string if a column reference cannot be resolved.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | ota-update
Files: files | file ages | folders
SHA1: 79f2418429aa05c56069c56d51b4d72f662a6970
User & Date: dan 2014-09-15 15:22:32
Context
2014-09-15
15:34
Merge latest trunk changes with this branch. check-in: 55b8011d user: dan tags: ota-update
15:22
Have sqlite3ota.c use grave accents instead of double-quotes to enclose identifiers in generated SQL. To avoid having the SQL engine substitute a literal string if a column reference cannot be resolved. check-in: 79f24184 user: dan tags: ota-update
14:54
Ensure the correct collation sequences are used when sorting data in sqlite3ota.c. check-in: 473a72d7 user: dan tags: ota-update
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/ota/ota3.test.

    71     71     list [catch { run_ota test.db ota.db } msg] $msg
    72     72   } {1 {SQLITE_MISMATCH - datatype mismatch}}
    73     73   
    74     74   do_execsql_test 2.2 {
    75     75     PRAGMA integrity_check;
    76     76   } {ok}
    77     77   
           78  +#--------------------------------------------------------------------
           79  +# Test that missing columns are detected.
           80  +#
           81  +forcedelete ota.db
           82  +reset_db
           83  +
           84  +do_execsql_test 2.0 {
           85  +  CREATE TABLE x1(a INTEGER PRIMARY KEY, b, c);
           86  +  CREATE INDEX i1 ON x1(b, c);
           87  +} {}
           88  +
           89  +do_test 2.1 {
           90  +  sqlite3 db2 ota.db
           91  +  db2 eval {
           92  +    CREATE TABLE data_x1(a, b, ota_control);
           93  +    INSERT INTO data_x1 VALUES(1, 'a', 0);
           94  +  }
           95  +  db2 close
           96  +  list [catch { run_ota test.db ota.db } msg] $msg
           97  +} {1 {SQLITE_ERROR - no such column: c}}
           98  +
           99  +do_execsql_test 2.2 {
          100  +  PRAGMA integrity_check;
          101  +} {ok}
    78    102   
    79    103   finish_test

Changes to ext/ota/sqlite3ota.c.

   295    295   }
   296    296   
   297    297   /*
   298    298   ** Allocate a buffer and populate it with the double-quoted version of the
   299    299   ** string in the argument buffer, suitable for use as an SQL identifier. 
   300    300   ** For example:
   301    301   **
   302         -**      [quick "brown" fox]    ->    ["quick ""brown"" fox"]
          302  +**      [quick `brown` fox]    ->    [`quick ``brown`` fox`]
   303    303   **
   304    304   ** Assuming the allocation is successful, a pointer to the new buffer is 
   305    305   ** returned. It is the responsibility of the caller to free it using 
   306    306   ** sqlite3_free() at some point in the future. Or, if the allocation fails,
   307    307   ** a NULL pointer is returned.
   308    308   */
   309    309   static char *otaQuoteName(const char *zName){
   310    310     int nName = strlen(zName);
   311    311     char *zRet = sqlite3_malloc(nName * 2 + 2 + 1);
   312    312     if( zRet ){
   313    313       int i;
   314    314       char *p = zRet;
   315         -    *p++ = '"';
          315  +    *p++ = '`';
   316    316       for(i=0; i<nName; i++){
   317         -      if( zName[i]=='"' ) *p++ = '"';
          317  +      if( zName[i]=='`' ) *p++ = '`';
   318    318         *p++ = zName[i];
   319    319       }
   320         -    *p++ = '"';
          320  +    *p++ = '`';
   321    321       *p++ = '\0';
   322    322     }
   323    323     return zRet;
   324    324   }
   325    325   
   326    326   /*
   327    327   ** Argument zFmt is a sqlite3_mprintf() style format string. The trailing