Skip to content

Commit 96a01f6

Browse files
committed
Updated several methods
1 parent 7b269da commit 96a01f6

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

Sources/SQLiteAdapter/SQLiteAdapter.swift

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ open class SQLite: SQLiteType {
218218
}
219219

220220
public func checkIfTableExists(_ tableName: String) throws -> Bool {
221-
if let count = try? getRowCountWithCondition(sql: "SELECT count(*) FROM sqlite_schema WHERE type='table' AND name='\(tableName)';", valuesToBind: nil) {
221+
if let count = try? getRowCountWithCondition(sql: "SELECT count(*) FROM sqlite_master WHERE type='table' AND name='\(tableName)';", valuesToBind: nil) {
222222
let result = count == 1 ? true : false
223223
log("successfully checked if table \(tableName) exists: \(result)")
224224
return result
@@ -260,7 +260,7 @@ open class SQLite: SQLiteType {
260260
}
261261

262262
public func checkIfIndexExists(in tableName: String, indexName: String) throws -> Bool {
263-
if let count = try? getRowCountWithCondition(sql: "SELECT count(*) FROM sqlite_schema WHERE type='index' AND tbl_name='\(tableName)' AND name='\(indexName)';", valuesToBind: nil) {
263+
if let count = try? getRowCountWithCondition(sql: "SELECT count(*) FROM sqlite_master WHERE type='index' AND tbl_name='\(tableName)' AND name='\(indexName)';", valuesToBind: nil) {
264264
let result = count == 1 ? true : false
265265
log("successfully checked if index \(indexName) exists: \(result)")
266266
return result
@@ -315,17 +315,17 @@ open class SQLite: SQLiteType {
315315
public func deleteAllRows(in tableName: String, vacuum: Bool = true, resetAutoincrement: Bool = true) throws {
316316
let sql = "DELETE FROM \(tableName);"
317317
try operation(sql: sql)
318+
log("successfully deleted all rows in \(tableName)")
318319
if vacuum {
319320
try self.vacuum()
320321
}
321-
log("successfully deleted all rows in \(tableName)")
322322
if resetAutoincrement {
323323
try self.resetAutoincrement(in: tableName)
324324
}
325325
}
326326

327327
public func getRowCount(in tableName: String) throws -> Int {
328-
let sql = "SELECT COUNT(*) FROM \(tableName);"
328+
let sql = "SELECT count(*) FROM \(tableName);"
329329
let sqlStatement = try prepareStatement(sql: sql)
330330
defer {
331331
sqlite3_finalize(sqlStatement)
@@ -435,9 +435,6 @@ open class SQLite: SQLiteType {
435435
defer {
436436
sqlite3_finalize(sqlStatement)
437437
}
438-
439-
try bindPlaceholders(sqlStatement: sqlStatement, valuesToBind: nil)
440-
441438
guard sqlite3_step(sqlStatement) == SQLITE_ROW else {
442439
throw SQLiteError.Step(getErrorMessage(dbPointer: dbPointer))
443440
}
@@ -454,7 +451,7 @@ open class SQLite: SQLiteType {
454451
}
455452

456453
public func resetAutoincrement(in tableName: String) throws {
457-
let sql = "UPDATE SQLITE_SEQUENCE SET SEQ=0 WHERE NAME=\"\(tableName)\";"
454+
let sql = "UPDATE sqlite_sequence SET SEQ=0 WHERE name='\(tableName)';"
458455
try operation(sql: sql)
459456
log("successfully reseted autoincrement in \(tableName)")
460457
}

0 commit comments

Comments
 (0)