We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ba929b2 commit 67c2243Copy full SHA for 67c2243
1 file changed
Sources/SQLiteAdapter/SQLiteAdapter.swift
@@ -191,6 +191,15 @@ open class SQLite {
191
log("successfully created table, sql: \(sql)")
192
}
193
194
+ public func checkIfTableExists(_ tableName: String) throws -> Bool {
195
+ if let count = try? getRowCountWithCondition(sql: "SELECT count(*) FROM sqlite_schema WHERE type='table' AND name='\(tableName)';", valuesToBind: nil) {
196
+ let result = count == 1 ? true : false
197
+ log("successfully checked if \(tableName) exists: \(result)")
198
+ return result
199
+ }
200
+ throw SQLiteError.Other(getErrorMessage(dbPointer: dbPointer))
201
202
+
203
public func dropTable(_ tableName: String, vacuum: Bool = true) throws {
204
let sql = "DROP TABLE IF EXISTS \(tableName);"
205
try operation(sql: sql)
0 commit comments