subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1463601 - in /subversion/trunk/subversion/libsvn_wc: upgrade.c wc-metadata.sql wc-queries.sql
Date Tue, 02 Apr 2013 15:43:15 GMT
Author: stsp
Date: Tue Apr  2 15:43:15 2013
New Revision: 1463601

URL: http://svn.apache.org/r1463601
Log:
Fix WC upgrades from old formats that didn't yet have a NODES table to
format 31 and beyond.

Format 31 introduced a new column in NODES, called inherited_props. When an
svn client which uses format 31 or greater is used to upgrade a pre-NODES WC,
this new column will be created as part of the CREATE TABLE statement which
creates the NODES table.

The format 31 upgrade code would unconditionally attempt to add a new
inherited_props column, which raises an error if the column already exists.

To fix this, check whether the inherited_props column exists before
attempting to create the column. Unfortunately this has to be done
from C as there doesn't seem to be a way of executing an ALTER TABLE
statement based on the result of a PRAGMA table_info() statement.
(If somebody knows a better way of doing this, I welcome any suggestions.)

* subversion/libsvn_wc/wc-metadata.sql
  (STMT_UPGRADE_TO_31): Split this query into two parts, ...
  (STMT_UPGRADE_TO_31_ALTER_TABLE): ... this one, which creates the new
   column and can be skipped if needed, and ...
  (STMT_UPGRADE_TO_31_FINALIZE): ... this one, which runs other upgrade
   statements which are idempotent.

* subversion/libsvn_wc/wc-queries.sql
  (STMT_PRAGMA_TABLE_INFO_NODES): New statement which returns info about
   the NODES table, such as the names of existing columns.

* subversion/libsvn_wc/upgrade.c
  (bump_to_31): Check if the inherited_props column exists before running
   the SQL statement which attempts to create it.

Modified:
    subversion/trunk/subversion/libsvn_wc/upgrade.c
    subversion/trunk/subversion/libsvn_wc/wc-metadata.sql
    subversion/trunk/subversion/libsvn_wc/wc-queries.sql

Modified: subversion/trunk/subversion/libsvn_wc/upgrade.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/upgrade.c?rev=1463601&r1=1463600&r2=1463601&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/upgrade.c (original)
+++ subversion/trunk/subversion/libsvn_wc/upgrade.c Tue Apr  2 15:43:15 2013
@@ -1589,9 +1589,40 @@ bump_to_31(void *baton,
   apr_pool_t *iterpool = svn_pool_create(scratch_pool);
   apr_array_header_t *empty_iprops = apr_array_make(
     scratch_pool, 0, sizeof(svn_prop_inherited_item_t *));
+  svn_boolean_t iprops_column_exists = FALSE;
 
-  /* Add the inherited_props column to NODES. */
-  SVN_ERR(svn_sqlite__exec_statements(sdb, STMT_UPGRADE_TO_31));
+  /* Add the inherited_props column to NODES if it does not yet exist.
+   *
+   * When using a format >= 31 client to upgrade from old formats which
+   * did not yet have a NODES table, the inherited_props column has
+   * already been created as part of the NODES table. Attemping to add
+   * the inherited_props column will raise an error in this case, so check
+   * if the column exists first.
+   *
+   * Checking for the existence of a column before ALTER TABLE is not
+   * possible within SQLite. We need to run a separate query and evaluate
+   * its result in C first.
+   */
+  SVN_ERR(svn_sqlite__get_statement(&stmt, sdb, STMT_PRAGMA_TABLE_INFO_NODES));
+  SVN_ERR(svn_sqlite__step(&have_row, stmt));
+  while (have_row)
+    {
+      const char *column_name = svn_sqlite__column_text(stmt, 1, NULL);
+      
+      if (strcmp(column_name, "inherited_props") == 0)
+        {
+          iprops_column_exists = TRUE;
+          break;
+        }
+
+      SVN_ERR(svn_sqlite__step(&have_row, stmt));
+    }
+  SVN_ERR(svn_sqlite__reset(stmt));
+  if (!iprops_column_exists)
+    SVN_ERR(svn_sqlite__exec_statements(sdb, STMT_UPGRADE_TO_31_ALTER_TABLE));
+
+  /* Run additional statements to finalize the upgrade to format 31. */
+  SVN_ERR(svn_sqlite__exec_statements(sdb, STMT_UPGRADE_TO_31_FINALIZE));
 
   /* Set inherited_props to an empty array for the roots of all
      switched subtrees in the WC.  This allows subsequent updates

Modified: subversion/trunk/subversion/libsvn_wc/wc-metadata.sql
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/wc-metadata.sql?rev=1463601&r1=1463600&r2=1463601&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/wc-metadata.sql (original)
+++ subversion/trunk/subversion/libsvn_wc/wc-metadata.sql Tue Apr  2 15:43:15 2013
@@ -814,8 +814,9 @@ WHERE wc_id = ?1 and local_relpath = ?2
 /* Format 31 adds the inherited_props column to the NODES table. C code then
    initializes the update/switch roots to make sure future updates fetch the
    inherited properties */
--- STMT_UPGRADE_TO_31
+-- STMT_UPGRADE_TO_31_ALTER_TABLE
 ALTER TABLE NODES ADD COLUMN inherited_props BLOB;
+-- STMT_UPGRADE_TO_31_FINALIZE
 DROP INDEX IF EXISTS I_ACTUAL_CHANGELIST;
 DROP INDEX IF EXISTS I_EXTERNALS_PARENT;
 

Modified: subversion/trunk/subversion/libsvn_wc/wc-queries.sql
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/wc-queries.sql?rev=1463601&r1=1463600&r2=1463601&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/wc-queries.sql (original)
+++ subversion/trunk/subversion/libsvn_wc/wc-queries.sql Tue Apr  2 15:43:15 2013
@@ -1219,6 +1219,9 @@ WHERE wc_id = ?1 AND parent_relpath = ?2
 UPDATE nodes SET properties = ?4
 WHERE wc_id = ?1 AND local_relpath = ?2 AND op_depth = ?3
 
+-- STMT_PRAGMA_TABLE_INFO_NODES
+PRAGMA table_info("NODES")
+
 /* --------------------------------------------------------------------------
  * Complex queries for callback walks, caching results in a temporary table.
  *



Mime
View raw message