Ticket #34463: mp-base-src-cregistry-sql.c-support-dbupgrade-on-sqlite-before-3.2.0.patch

File mp-base-src-cregistry-sql.c-support-dbupgrade-on-sqlite-before-3.2.0.patch, 2.3 KB (added by neverpanic (Clemens Lang), 12 years ago)

Patch against base/src/cregistry/sql.c to use a different update mechanism on systems with SQLite < 3.2.0

  • sql.c

     
    263263            /* we need to update to 1.1, add binary field and index to files
    264264             * table */
    265265            static char* version_1_1_queries[] = {
     266#if SQLITE_VERSION_NUMBER >= 3002000
    266267                "ALTER TABLE registry.files ADD COLUMN binary BOOL",
     268#else
     269                /*
     270                 * SQLite < 3.2.0 doesn't support ALTER TABLE ADD COLUMN
     271                 * Unfortunately, Tiger ships with SQLite < 3.2.0 (#34463)
     272                 * This is taken from http://www.sqlite.org/faq.html#q11
     273                 */
     274
     275                /* Create a temporary table */
     276                "CREATE TEMPORARY TABLE mp_files_backup (id INTEGER, path TEXT, "
     277                    "actual_path TEXT, active INT, mtime DATETIME, md5sum TEXT, editable INT, "
     278                    "FOREIGN KEY(id) REFERENCES ports(id))",
     279
     280                /* Copy all data into the temporary table */
     281                "INSERT INTO mp_files_backup SELECT id, path, actual_path, active, mtime, "
     282                    "md5sum, editable FROM registry.files",
     283
     284                /* Drop the original table and re-create it with the new structure */
     285                "DROP TABLE registry.files",
     286                "CREATE TABLE registry.files (id INTEGER, path TEXT, actual_path TEXT, "
     287                    "active INT, mtime DATETIME, md5sum TEXT, editable INT, binary BOOL, "
     288                    "FOREIGN KEY(id) REFERENCES ports(id))",
     289                "CREATE INDEX registry.file_port ON files(id)",
     290                "CREATE INDEX registry.file_path ON files(path)",
     291                "CREATE INDEX registry.file_actual ON files(actual_path)",
     292
     293                /* Copy all data back from temporary table */
     294                "INSERT INTO registry.files (id, path, actual_path, active, mtime, md5sum, "
     295                    "editable) SELECT id, path, actual_path, active, mtime, md5sum, "
     296                    "editable FROM mp_files_backup",
     297
     298                /* Remove temporary table */
     299                "DROP TABLE mp_files_backup",
     300#endif
    267301                "CREATE INDEX registry.file_binary ON files(binary)",
    268302
    269303                "UPDATE registry.metadata SET value = '1.100' WHERE key = 'version'",