Fossil SCM
Add islink column to stashfile, undo, undo_vfile tables if needed.
Commit
44e673f5e992c6793b9816f11ed8bc1ca6296a63
Parent
be956c3c88fd5b7…
1 file changed
+36
-13
M
src/db.c
+36
-13
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -736,10 +736,29 @@ | ||
| 736 | 736 | } |
| 737 | 737 | g.configOpen = 1; |
| 738 | 738 | free(zDbName); |
| 739 | 739 | } |
| 740 | 740 | |
| 741 | + | |
| 742 | +/* | |
| 743 | + * * Returns TRUE if zTable exists in the local database. | |
| 744 | + */ | |
| 745 | +static int db_local_table_exists(const char *zTable){ | |
| 746 | + return db_exists("SELECT 1 FROM %s.sqlite_master" | |
| 747 | + " WHERE name=='%s'", | |
| 748 | + db_name("localdb"), zTable); | |
| 749 | +} | |
| 750 | + | |
| 751 | +/* | |
| 752 | +** Returns TRUE if zColumn exists in zTable in the local database. | |
| 753 | +*/ | |
| 754 | +static int db_local_column_exists(const char *zTable, const char *zColumn){ | |
| 755 | + return db_exists("SELECT 1 FROM %s.sqlite_master" | |
| 756 | + " WHERE name=='%s' AND sql GLOB '* %s *'", | |
| 757 | + db_name("localdb"), zTable, zColumn); | |
| 758 | +} | |
| 759 | + | |
| 741 | 760 | /* |
| 742 | 761 | ** If zDbName is a valid local database file, open it and return |
| 743 | 762 | ** true. If it is not a valid local database file, return 0. |
| 744 | 763 | */ |
| 745 | 764 | static int isValidLocalDb(const char *zDbName){ |
| @@ -757,27 +776,31 @@ | ||
| 757 | 776 | |
| 758 | 777 | /* If the "isexe" column is missing from the vfile table, then |
| 759 | 778 | ** add it now. This code added on 2010-03-06. After all users have |
| 760 | 779 | ** upgraded, this code can be safely deleted. |
| 761 | 780 | */ |
| 762 | - rc = db_exists("SELECT 1 FROM %s.sqlite_master" | |
| 763 | - " WHERE name=='vfile' AND sql GLOB '* isexe *'", | |
| 764 | - db_name("localdb")); | |
| 765 | - if( rc==0 ){ | |
| 781 | + if( !db_local_column_exists("vfile", "isexe") ) | |
| 766 | 782 | db_multi_exec("ALTER TABLE vfile ADD COLUMN isexe BOOLEAN DEFAULT 0"); |
| 767 | - } | |
| 768 | 783 | |
| 769 | - /* If the "islink" column is missing from the vfile table, then | |
| 770 | - ** add it now. This code added on 2011-01-17. After all users have | |
| 771 | - ** upgraded, this code can be safely deleted. | |
| 784 | + /* If "islink"/"isLink" columns are missing from tables, then | |
| 785 | + ** add them now. This code added on 2011-01-17 and 2011-08-27. | |
| 786 | + ** After all users have upgraded, this code can be safely deleted. | |
| 772 | 787 | */ |
| 773 | - rc = db_exists("SELECT 1 FROM %s.sqlite_master" | |
| 774 | - " WHERE name=='vfile' AND sql GLOB '* islink *'", | |
| 775 | - db_name("localdb")); | |
| 776 | - if( rc==0 ){ | |
| 788 | + if( !db_local_column_exists("vfile", "islink") ) | |
| 777 | 789 | db_multi_exec("ALTER TABLE vfile ADD COLUMN islink BOOLEAN DEFAULT 0"); |
| 778 | - } | |
| 790 | + | |
| 791 | + if( db_local_table_exists("stashfile") && | |
| 792 | + !db_local_column_exists("stashfile", "isLink") ) | |
| 793 | + db_multi_exec("ALTER TABLE stashfile ADD COLUMN isLink BOOLEAN DEFAULT 0"); | |
| 794 | + | |
| 795 | + if( db_local_table_exists("undo") && | |
| 796 | + !db_local_column_exists("undo", "isLink") ) | |
| 797 | + db_multi_exec("ALTER TABLE undo ADD COLUMN isLink BOOLEAN DEFAULT 0"); | |
| 798 | + | |
| 799 | + if( db_local_table_exists("undo_vfile") && | |
| 800 | + !db_local_column_exists("undo_vfile", "islink") ) | |
| 801 | + db_multi_exec("ALTER TABLE undo_vfile ADD COLUMN islink BOOLEAN DEFAULT 0"); | |
| 779 | 802 | |
| 780 | 803 | return 1; |
| 781 | 804 | } |
| 782 | 805 | |
| 783 | 806 | /* |
| 784 | 807 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -736,10 +736,29 @@ | |
| 736 | } |
| 737 | g.configOpen = 1; |
| 738 | free(zDbName); |
| 739 | } |
| 740 | |
| 741 | /* |
| 742 | ** If zDbName is a valid local database file, open it and return |
| 743 | ** true. If it is not a valid local database file, return 0. |
| 744 | */ |
| 745 | static int isValidLocalDb(const char *zDbName){ |
| @@ -757,27 +776,31 @@ | |
| 757 | |
| 758 | /* If the "isexe" column is missing from the vfile table, then |
| 759 | ** add it now. This code added on 2010-03-06. After all users have |
| 760 | ** upgraded, this code can be safely deleted. |
| 761 | */ |
| 762 | rc = db_exists("SELECT 1 FROM %s.sqlite_master" |
| 763 | " WHERE name=='vfile' AND sql GLOB '* isexe *'", |
| 764 | db_name("localdb")); |
| 765 | if( rc==0 ){ |
| 766 | db_multi_exec("ALTER TABLE vfile ADD COLUMN isexe BOOLEAN DEFAULT 0"); |
| 767 | } |
| 768 | |
| 769 | /* If the "islink" column is missing from the vfile table, then |
| 770 | ** add it now. This code added on 2011-01-17. After all users have |
| 771 | ** upgraded, this code can be safely deleted. |
| 772 | */ |
| 773 | rc = db_exists("SELECT 1 FROM %s.sqlite_master" |
| 774 | " WHERE name=='vfile' AND sql GLOB '* islink *'", |
| 775 | db_name("localdb")); |
| 776 | if( rc==0 ){ |
| 777 | db_multi_exec("ALTER TABLE vfile ADD COLUMN islink BOOLEAN DEFAULT 0"); |
| 778 | } |
| 779 | |
| 780 | return 1; |
| 781 | } |
| 782 | |
| 783 | /* |
| 784 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -736,10 +736,29 @@ | |
| 736 | } |
| 737 | g.configOpen = 1; |
| 738 | free(zDbName); |
| 739 | } |
| 740 | |
| 741 | |
| 742 | /* |
| 743 | * * Returns TRUE if zTable exists in the local database. |
| 744 | */ |
| 745 | static int db_local_table_exists(const char *zTable){ |
| 746 | return db_exists("SELECT 1 FROM %s.sqlite_master" |
| 747 | " WHERE name=='%s'", |
| 748 | db_name("localdb"), zTable); |
| 749 | } |
| 750 | |
| 751 | /* |
| 752 | ** Returns TRUE if zColumn exists in zTable in the local database. |
| 753 | */ |
| 754 | static int db_local_column_exists(const char *zTable, const char *zColumn){ |
| 755 | return db_exists("SELECT 1 FROM %s.sqlite_master" |
| 756 | " WHERE name=='%s' AND sql GLOB '* %s *'", |
| 757 | db_name("localdb"), zTable, zColumn); |
| 758 | } |
| 759 | |
| 760 | /* |
| 761 | ** If zDbName is a valid local database file, open it and return |
| 762 | ** true. If it is not a valid local database file, return 0. |
| 763 | */ |
| 764 | static int isValidLocalDb(const char *zDbName){ |
| @@ -757,27 +776,31 @@ | |
| 776 | |
| 777 | /* If the "isexe" column is missing from the vfile table, then |
| 778 | ** add it now. This code added on 2010-03-06. After all users have |
| 779 | ** upgraded, this code can be safely deleted. |
| 780 | */ |
| 781 | if( !db_local_column_exists("vfile", "isexe") ) |
| 782 | db_multi_exec("ALTER TABLE vfile ADD COLUMN isexe BOOLEAN DEFAULT 0"); |
| 783 | |
| 784 | /* If "islink"/"isLink" columns are missing from tables, then |
| 785 | ** add them now. This code added on 2011-01-17 and 2011-08-27. |
| 786 | ** After all users have upgraded, this code can be safely deleted. |
| 787 | */ |
| 788 | if( !db_local_column_exists("vfile", "islink") ) |
| 789 | db_multi_exec("ALTER TABLE vfile ADD COLUMN islink BOOLEAN DEFAULT 0"); |
| 790 | |
| 791 | if( db_local_table_exists("stashfile") && |
| 792 | !db_local_column_exists("stashfile", "isLink") ) |
| 793 | db_multi_exec("ALTER TABLE stashfile ADD COLUMN isLink BOOLEAN DEFAULT 0"); |
| 794 | |
| 795 | if( db_local_table_exists("undo") && |
| 796 | !db_local_column_exists("undo", "isLink") ) |
| 797 | db_multi_exec("ALTER TABLE undo ADD COLUMN isLink BOOLEAN DEFAULT 0"); |
| 798 | |
| 799 | if( db_local_table_exists("undo_vfile") && |
| 800 | !db_local_column_exists("undo_vfile", "islink") ) |
| 801 | db_multi_exec("ALTER TABLE undo_vfile ADD COLUMN islink BOOLEAN DEFAULT 0"); |
| 802 | |
| 803 | return 1; |
| 804 | } |
| 805 | |
| 806 | /* |
| 807 |