summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Hallam <jesse.hallam@gmail.com>2018-04-27 05:07:36 -0400
committerGeorge Goldberg <george@gberg.me>2018-04-27 10:07:36 +0100
commit7abd6176e99d3f82711af51f8d75b3142ab73758 (patch)
tree678e9846f02079142b1300f966b333d41a429365
parent6d50d836f538253e2d13d5ddb90495820f9cb259 (diff)
downloadchat-7abd6176e99d3f82711af51f8d75b3142ab73758.tar.gz
chat-7abd6176e99d3f82711af51f8d75b3142ab73758.tar.bz2
chat-7abd6176e99d3f82711af51f8d75b3142ab73758.zip
modestly extend SQLite support (#8677)
This is primarily to unblock the advanced permissions merge. There's still more work to do if we wanted this to be mainstream, but as it's mainly for unit tests, I'm just focussing on the minimum.
-rw-r--r--store/sqlstore/supplier.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/store/sqlstore/supplier.go b/store/sqlstore/supplier.go
index 99b35a664..8f37db0cd 100644
--- a/store/sqlstore/supplier.go
+++ b/store/sqlstore/supplier.go
@@ -61,6 +61,8 @@ const (
EXIT_REMOVE_TABLE = 134
EXIT_CREATE_INDEX_SQLITE = 135
EXIT_REMOVE_INDEX_SQLITE = 136
+ EXIT_TABLE_EXISTS_SQLITE = 137
+ EXIT_DOES_COLUMN_EXISTS_SQLITE = 138
)
type SqlSupplierOldStores struct {
@@ -365,6 +367,20 @@ func (ss *SqlSupplier) DoesTableExist(tableName string) bool {
return count > 0
+ } else if ss.DriverName() == model.DATABASE_DRIVER_SQLITE {
+ count, err := ss.GetMaster().SelectInt(
+ `SELECT name FROM sqlite_master WHERE type='table' AND name=?`,
+ tableName,
+ )
+
+ if err != nil {
+ l4g.Critical(utils.T("store.sql.table_exists.critical"), err)
+ time.Sleep(time.Second)
+ os.Exit(EXIT_TABLE_EXISTS_SQLITE)
+ }
+
+ return count > 0
+
} else {
l4g.Critical(utils.T("store.sql.column_exists_missing_driver.critical"))
time.Sleep(time.Second)
@@ -420,6 +436,21 @@ func (ss *SqlSupplier) DoesColumnExist(tableName string, columnName string) bool
return count > 0
+ } else if ss.DriverName() == model.DATABASE_DRIVER_SQLITE {
+ count, err := ss.GetMaster().SelectInt(
+ `SELECT COUNT(*) FROM pragma_table_info(?) WHERE name=?`,
+ tableName,
+ columnName,
+ )
+
+ if err != nil {
+ l4g.Critical(utils.T("store.sql.column_exists.critical"), err)
+ time.Sleep(time.Second)
+ os.Exit(EXIT_DOES_COLUMN_EXISTS_SQLITE)
+ }
+
+ return count > 0
+
} else {
l4g.Critical(utils.T("store.sql.column_exists_missing_driver.critical"))
time.Sleep(time.Second)