/ Check-in [82b08a3d]
Login

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

Overview
Comment:Use the 2-argument version of substr() in the SQL contained in the VACUUM and ALTER TABLE commands. Ticket #2737. (CVS 4499)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 82b08a3dc2366007bcac4d9e451ef61c8c018fa5
User & Date: drh 2007-10-20 20:58:57
Context
2007-10-21
22:47
Finally bring OS/2 to the 3.5 level. This at least is a first draft version that survives very basic tests. It still contains a lot of debugging stuff... (CVS 4500) check-in: 46b2d103 user: pweilbacher tags: trunk
2007-10-20
20:58
Use the 2-argument version of substr() in the SQL contained in the VACUUM and ALTER TABLE commands. Ticket #2737. (CVS 4499) check-in: 82b08a3d user: drh tags: trunk
16:36
Add the new memory allocator to the amalgamation. Improvements to out-of-memory handling. (CVS 4498) check-in: b58c2b37 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/alter.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains C code routines that used to generate VDBE code
    13     13   ** that implements the ALTER TABLE command.
    14     14   **
    15         -** $Id: alter.c,v 1.32 2007/08/29 14:06:23 danielk1977 Exp $
           15  +** $Id: alter.c,v 1.33 2007/10/20 20:58:57 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   #include <ctype.h>
    19     19   
    20     20   /*
    21     21   ** The code in this file only exists if we are not omitting the
    22     22   ** ALTER TABLE logic from the build.
................................................................................
   374    374               "WHEN type = 'trigger' THEN sqlite_rename_trigger(sql, %Q)"
   375    375               "ELSE sqlite_rename_table(sql, %Q) END, "
   376    376   #endif
   377    377             "tbl_name = %Q, "
   378    378             "name = CASE "
   379    379               "WHEN type='table' THEN %Q "
   380    380               "WHEN name LIKE 'sqlite_autoindex%%' AND type='index' THEN "
   381         -             "'sqlite_autoindex_' || %Q || substr(name,%d+18,10) "
          381  +             "'sqlite_autoindex_' || %Q || substr(name,%d+18) "
   382    382               "ELSE name END "
   383    383         "WHERE tbl_name=%Q AND "
   384    384             "(type='table' OR type='index' OR type='trigger');", 
   385    385         zDb, SCHEMA_TABLE(iDb), zName, zName, zName, 
   386    386   #ifndef SQLITE_OMIT_TRIGGER
   387    387         zName,
   388    388   #endif
................................................................................
   511    511     if( zCol ){
   512    512       char *zEnd = &zCol[pColDef->n-1];
   513    513       while( (zEnd>zCol && *zEnd==';') || isspace(*(unsigned char *)zEnd) ){
   514    514         *zEnd-- = '\0';
   515    515       }
   516    516       sqlite3NestedParse(pParse, 
   517    517           "UPDATE %Q.%s SET "
   518         -          "sql = substr(sql,1,%d) || ', ' || %Q || substr(sql,%d,length(sql)) "
          518  +          "sql = substr(sql,1,%d) || ', ' || %Q || substr(sql,%d) "
   519    519           "WHERE type = 'table' AND name = %Q", 
   520    520         zDb, SCHEMA_TABLE(iDb), pNew->addColOffset, zCol, pNew->addColOffset+1,
   521    521         zTab
   522    522       );
   523    523       sqlite3_free(zCol);
   524    524     }
   525    525   

Changes to src/vacuum.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code used to implement the VACUUM command.
    13     13   **
    14     14   ** Most of the code in this file may be omitted by defining the
    15     15   ** SQLITE_OMIT_VACUUM macro.
    16     16   **
    17         -** $Id: vacuum.c,v 1.73 2007/08/29 12:31:28 danielk1977 Exp $
           17  +** $Id: vacuum.c,v 1.74 2007/10/20 20:58:57 drh Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include "vdbeInt.h"
    21     21   
    22     22   #if !defined(SQLITE_OMIT_VACUUM) && !defined(SQLITE_OMIT_ATTACH)
    23     23   /*
    24     24   ** Execute zSql on database db. Return an error code.
................................................................................
   132    132     rc = execSql(db, "BEGIN EXCLUSIVE;");
   133    133     if( rc!=SQLITE_OK ) goto end_of_vacuum;
   134    134   
   135    135     /* Query the schema of the main database. Create a mirror schema
   136    136     ** in the temporary database.
   137    137     */
   138    138     rc = execExecSql(db, 
   139         -      "SELECT 'CREATE TABLE vacuum_db.' || substr(sql,14,100000000) "
          139  +      "SELECT 'CREATE TABLE vacuum_db.' || substr(sql,14) "
   140    140         "  FROM sqlite_master WHERE type='table' AND name!='sqlite_sequence'"
   141    141         "   AND rootpage>0"
   142    142     );
   143    143     if( rc!=SQLITE_OK ) goto end_of_vacuum;
   144    144     rc = execExecSql(db, 
   145         -      "SELECT 'CREATE INDEX vacuum_db.' || substr(sql,14,100000000)"
          145  +      "SELECT 'CREATE INDEX vacuum_db.' || substr(sql,14)"
   146    146         "  FROM sqlite_master WHERE sql LIKE 'CREATE INDEX %' ");
   147    147     if( rc!=SQLITE_OK ) goto end_of_vacuum;
   148    148     rc = execExecSql(db, 
   149         -      "SELECT 'CREATE UNIQUE INDEX vacuum_db.' || substr(sql,21,100000000) "
          149  +      "SELECT 'CREATE UNIQUE INDEX vacuum_db.' || substr(sql,21) "
   150    150         "  FROM sqlite_master WHERE sql LIKE 'CREATE UNIQUE INDEX %'");
   151    151     if( rc!=SQLITE_OK ) goto end_of_vacuum;
   152    152   
   153    153     /* Loop through the tables in the main database. For each, do
   154    154     ** an "INSERT INTO vacuum_db.xxx SELECT * FROM xxx;" to copy
   155    155     ** the contents to the temporary database.
   156    156     */