Fossil SCM

Avoid using invalid SQL when checking to see if the vfile table needs to have the islink column added.

drh 2011-08-23 16:50 symlinks
Commit 2de9e87600d6a447ee44969410ff5eef0aabd76d
1 file changed +11 -50
+11 -50
--- src/db.c
+++ src/db.c
@@ -757,66 +757,27 @@
757757
758758
/* If the "isexe" column is missing from the vfile table, then
759759
** add it now. This code added on 2010-03-06. After all users have
760760
** upgraded, this code can be safely deleted.
761761
*/
762
- rc = sqlite3_prepare(g.db, "SELECT isexe FROM vfile", -1, &pStmt, 0);
763
- nPrepare++;
764
- sqlite3_finalize(pStmt);
765
- if( rc==SQLITE_ERROR ){
766
- sqlite3_exec(g.db, "ALTER TABLE vfile ADD COLUMN isexe BOOLEAN", 0, 0, 0);
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");
767767
}
768768
769769
/* If the "islink" column is missing from the vfile table, then
770770
** add it now. This code added on 2011-01-17. After all users have
771771
** upgraded, this code can be safely deleted.
772772
*/
773
- rc = sqlite3_prepare(g.db, "SELECT islink FROM vfile", -1, &pStmt, 0);
774
- sqlite3_finalize(pStmt);
775
- if( rc==SQLITE_ERROR ){
776
- sqlite3_exec(g.db, "ALTER TABLE vfile ADD COLUMN islink BOOLEAN", 0, 0, 0);
777
- }
778
-
779
-#if 0
780
- /* If the "isLink" column is missing from the stashfile table, then
781
- ** add it now. This code added on 2011-01-18. After all users have
782
- ** upgraded, this code can be safely deleted.
783
- **
784
- ** Table stashfile may not exist at all. We don't handle this case,
785
- ** and leave it to sqlite.
786
- */
787
- rc = sqlite3_prepare(g.db, "SELECT isLink FROM stashfile", -1, &pStmt, 0);
788
- sqlite3_finalize(pStmt);
789
- /* NOTE: this prints "SQLITE_ERROR: no such column: isLink" for some reason */
790
- if( rc==SQLITE_ERROR ){
791
- sqlite3_exec(g.db, "ALTER TABLE stashfile ADD COLUMN isLink BOOLEAN", 0, 0, 0);
792
- }
793
-#endif
794
-
795
-#if 0
796
- /* If the "mtime" column is missing from the vfile table, then
797
- ** add it now. This code added on 2008-12-06. After all users have
798
- ** upgraded, this code can be safely deleted.
799
- */
800
- rc = sqlite3_prepare(g.db, "SELECT mtime FROM vfile", -1, &pStmt, 0);
801
- sqlite3_finalize(pStmt);
802
- if( rc==SQLITE_ERROR ){
803
- sqlite3_exec(g.db, "ALTER TABLE vfile ADD COLUMN mtime INTEGER", 0, 0, 0);
804
- }
805
-#endif
806
-
807
-#if 0
808
- /* If the "origname" column is missing from the vfile table, then
809
- ** add it now. This code added on 2008-11-09. After all users have
810
- ** upgraded, this code can be safely deleted.
811
- */
812
- rc = sqlite3_prepare(g.db, "SELECT origname FROM vfile", -1, &pStmt, 0);
813
- sqlite3_finalize(pStmt);
814
- if( rc==SQLITE_ERROR ){
815
- sqlite3_exec(g.db, "ALTER TABLE vfile ADD COLUMN origname TEXT", 0, 0, 0);
816
- }
817
-#endif
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
+ }
818779
819780
return 1;
820781
}
821782
822783
/*
823784
--- src/db.c
+++ src/db.c
@@ -757,66 +757,27 @@
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 = sqlite3_prepare(g.db, "SELECT isexe FROM vfile", -1, &pStmt, 0);
763 nPrepare++;
764 sqlite3_finalize(pStmt);
765 if( rc==SQLITE_ERROR ){
766 sqlite3_exec(g.db, "ALTER TABLE vfile ADD COLUMN isexe BOOLEAN", 0, 0, 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 = sqlite3_prepare(g.db, "SELECT islink FROM vfile", -1, &pStmt, 0);
774 sqlite3_finalize(pStmt);
775 if( rc==SQLITE_ERROR ){
776 sqlite3_exec(g.db, "ALTER TABLE vfile ADD COLUMN islink BOOLEAN", 0, 0, 0);
777 }
778
779 #if 0
780 /* If the "isLink" column is missing from the stashfile table, then
781 ** add it now. This code added on 2011-01-18. After all users have
782 ** upgraded, this code can be safely deleted.
783 **
784 ** Table stashfile may not exist at all. We don't handle this case,
785 ** and leave it to sqlite.
786 */
787 rc = sqlite3_prepare(g.db, "SELECT isLink FROM stashfile", -1, &pStmt, 0);
788 sqlite3_finalize(pStmt);
789 /* NOTE: this prints "SQLITE_ERROR: no such column: isLink" for some reason */
790 if( rc==SQLITE_ERROR ){
791 sqlite3_exec(g.db, "ALTER TABLE stashfile ADD COLUMN isLink BOOLEAN", 0, 0, 0);
792 }
793 #endif
794
795 #if 0
796 /* If the "mtime" column is missing from the vfile table, then
797 ** add it now. This code added on 2008-12-06. After all users have
798 ** upgraded, this code can be safely deleted.
799 */
800 rc = sqlite3_prepare(g.db, "SELECT mtime FROM vfile", -1, &pStmt, 0);
801 sqlite3_finalize(pStmt);
802 if( rc==SQLITE_ERROR ){
803 sqlite3_exec(g.db, "ALTER TABLE vfile ADD COLUMN mtime INTEGER", 0, 0, 0);
804 }
805 #endif
806
807 #if 0
808 /* If the "origname" column is missing from the vfile table, then
809 ** add it now. This code added on 2008-11-09. After all users have
810 ** upgraded, this code can be safely deleted.
811 */
812 rc = sqlite3_prepare(g.db, "SELECT origname FROM vfile", -1, &pStmt, 0);
813 sqlite3_finalize(pStmt);
814 if( rc==SQLITE_ERROR ){
815 sqlite3_exec(g.db, "ALTER TABLE vfile ADD COLUMN origname TEXT", 0, 0, 0);
816 }
817 #endif
818
819 return 1;
820 }
821
822 /*
823
--- src/db.c
+++ src/db.c
@@ -757,66 +757,27 @@
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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button