Fossil SCM
Avoid using invalid SQL when checking to see if the vfile table needs to have the islink column added.
Commit
2de9e87600d6a447ee44969410ff5eef0aabd76d
Parent
6c880a4f5e664ba…
1 file changed
+11
-50
M
src/db.c
+11
-50
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -757,66 +757,27 @@ | ||
| 757 | 757 | |
| 758 | 758 | /* If the "isexe" column is missing from the vfile table, then |
| 759 | 759 | ** add it now. This code added on 2010-03-06. After all users have |
| 760 | 760 | ** upgraded, this code can be safely deleted. |
| 761 | 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); | |
| 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 | 767 | } |
| 768 | 768 | |
| 769 | 769 | /* If the "islink" column is missing from the vfile table, then |
| 770 | 770 | ** add it now. This code added on 2011-01-17. After all users have |
| 771 | 771 | ** upgraded, this code can be safely deleted. |
| 772 | 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 | |
| 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 | + } | |
| 818 | 779 | |
| 819 | 780 | return 1; |
| 820 | 781 | } |
| 821 | 782 | |
| 822 | 783 | /* |
| 823 | 784 |
| --- 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 |