Fossil SCM

Set an timeout on the database connection to the web-cache. Use the sqlite3_table_column_metadata() interface to check to see if the web-cache database file needs to be initialized prior to actually initializing it.

drh 2018-07-17 15:48 trunk
Commit e6e806a91e0770c7392aa9ee697e757d6719d2fda3dff0e7ed8899e87e54ae0d
1 file changed +21 -17
+21 -17
--- src/cache.c
+++ src/cache.c
@@ -61,27 +61,31 @@
6161
fossil_free(zDbName);
6262
if( rc ){
6363
sqlite3_close(db);
6464
return 0;
6565
}
66
- rc = sqlite3_exec(db,
67
- "PRAGMA page_size=8192;"
68
- "CREATE TABLE IF NOT EXISTS blob(id INTEGER PRIMARY KEY, data BLOB);"
69
- "CREATE TABLE IF NOT EXISTS cache("
70
- "key TEXT PRIMARY KEY," /* Key used to access the cache */
71
- "id INT REFERENCES blob," /* The cache content */
72
- "sz INT," /* Size of content in bytes */
73
- "tm INT," /* Last access time (unix timestampe) */
74
- "nref INT" /* Number of uses */
75
- ");"
76
- "CREATE TRIGGER IF NOT EXISTS cacheDel AFTER DELETE ON cache BEGIN"
77
- " DELETE FROM blob WHERE id=OLD.id;"
78
- "END;",
79
- 0, 0, 0);
80
- if( rc!=SQLITE_OK ){
81
- sqlite3_close(db);
82
- return 0;
66
+ sqlite3_busy_timeout(db, 5000);
67
+ if( sqlite3_table_column_metadata(db,0,"blob","key",0,0,0,0,0)!=SQLITE_OK ){
68
+ rc = sqlite3_exec(db,
69
+ "PRAGMA page_size=8192;"
70
+ "CREATE TABLE IF NOT EXISTS blob(id INTEGER PRIMARY KEY, data BLOB);"
71
+ "CREATE TABLE IF NOT EXISTS cache("
72
+ "key TEXT PRIMARY KEY," /* Key used to access the cache */
73
+ "id INT REFERENCES blob," /* The cache content */
74
+ "sz INT," /* Size of content in bytes */
75
+ "tm INT," /* Last access time (unix timestampe) */
76
+ "nref INT" /* Number of uses */
77
+ ");"
78
+ "CREATE TRIGGER IF NOT EXISTS cacheDel AFTER DELETE ON cache BEGIN"
79
+ " DELETE FROM blob WHERE id=OLD.id;"
80
+ "END;",
81
+ 0, 0, 0
82
+ );
83
+ if( rc!=SQLITE_OK ){
84
+ sqlite3_close(db);
85
+ return 0;
86
+ }
8387
}
8488
return db;
8589
}
8690
8791
/*
8892
--- src/cache.c
+++ src/cache.c
@@ -61,27 +61,31 @@
61 fossil_free(zDbName);
62 if( rc ){
63 sqlite3_close(db);
64 return 0;
65 }
66 rc = sqlite3_exec(db,
67 "PRAGMA page_size=8192;"
68 "CREATE TABLE IF NOT EXISTS blob(id INTEGER PRIMARY KEY, data BLOB);"
69 "CREATE TABLE IF NOT EXISTS cache("
70 "key TEXT PRIMARY KEY," /* Key used to access the cache */
71 "id INT REFERENCES blob," /* The cache content */
72 "sz INT," /* Size of content in bytes */
73 "tm INT," /* Last access time (unix timestampe) */
74 "nref INT" /* Number of uses */
75 ");"
76 "CREATE TRIGGER IF NOT EXISTS cacheDel AFTER DELETE ON cache BEGIN"
77 " DELETE FROM blob WHERE id=OLD.id;"
78 "END;",
79 0, 0, 0);
80 if( rc!=SQLITE_OK ){
81 sqlite3_close(db);
82 return 0;
 
 
 
 
83 }
84 return db;
85 }
86
87 /*
88
--- src/cache.c
+++ src/cache.c
@@ -61,27 +61,31 @@
61 fossil_free(zDbName);
62 if( rc ){
63 sqlite3_close(db);
64 return 0;
65 }
66 sqlite3_busy_timeout(db, 5000);
67 if( sqlite3_table_column_metadata(db,0,"blob","key",0,0,0,0,0)!=SQLITE_OK ){
68 rc = sqlite3_exec(db,
69 "PRAGMA page_size=8192;"
70 "CREATE TABLE IF NOT EXISTS blob(id INTEGER PRIMARY KEY, data BLOB);"
71 "CREATE TABLE IF NOT EXISTS cache("
72 "key TEXT PRIMARY KEY," /* Key used to access the cache */
73 "id INT REFERENCES blob," /* The cache content */
74 "sz INT," /* Size of content in bytes */
75 "tm INT," /* Last access time (unix timestampe) */
76 "nref INT" /* Number of uses */
77 ");"
78 "CREATE TRIGGER IF NOT EXISTS cacheDel AFTER DELETE ON cache BEGIN"
79 " DELETE FROM blob WHERE id=OLD.id;"
80 "END;",
81 0, 0, 0
82 );
83 if( rc!=SQLITE_OK ){
84 sqlite3_close(db);
85 return 0;
86 }
87 }
88 return db;
89 }
90
91 /*
92

Keyboard Shortcuts

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