Skip to content

Commit 24ce67c

Browse files
committed
Fix issues 45 and 46
1 parent 4cda0af commit 24ce67c

File tree

6 files changed

+39
-41
lines changed

6 files changed

+39
-41
lines changed

sqliter-driver/src/nativeCommonMain/kotlin/co/touchlab/sqliter/DatabaseConnection.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ fun DatabaseConnection.stringForQuery(sql: String): String = withStatement(sql)
5959
* @param cipherKey the database cipher key
6060
*/
6161
fun DatabaseConnection.setCipherKey(cipherKey: String) {
62-
withStatement("PRAGMA key = ?;"){
63-
bindString(1, cipherKey)
64-
}
62+
stringForQuery("PRAGMA key = '${cipherKey.escapeSql()}';")
6563
}
6664

6765
/**
@@ -74,11 +72,11 @@ fun DatabaseConnection.setCipherKey(cipherKey: String) {
7472
//TODO: Maybe figure out key suppress in log?
7573
fun DatabaseConnection.resetCipherKey(oldKey: String, newKey: String) {
7674
setCipherKey(oldKey)
77-
withStatement("PRAGMA rekey = ?;"){
78-
bindString(1, newKey)
79-
}
75+
stringForQuery("PRAGMA rekey = '${newKey.escapeSql()}';")
8076
}
8177

78+
private fun String.escapeSql() = this.replace(oldValue = "'", newValue = "''")
79+
8280
/**
8381
* Gets the database version.
8482
*

sqliter-driver/src/nativeCommonMain/kotlin/co/touchlab/sqliter/interop/ActualSqliteStatement.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package co.touchlab.sqliter.interop
22

33
import kotlinx.cinterop.*
44
import platform.posix.usleep
5-
import sqlite3.*
5+
import co.touchlab.sqliter.sqlite3.*
66

77
expect inline fun bytesToString(bv:CPointer<ByteVar>):String
88

sqliter-driver/src/nativeCommonMain/kotlin/co/touchlab/sqliter/interop/SQLiteException.kt

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,37 +23,37 @@ internal inline fun sqlException(logging: Logger, config: SqliteDatabaseConfig,
2323
}
2424

2525
enum class SqliteErrorType(val code: Int) {
26-
SQLITE_OK(sqlite3.SQLITE_OK), /* Successful result */
26+
SQLITE_OK(co.touchlab.sqliter.sqlite3.SQLITE_OK), /* Successful result */
2727

2828
/* beginning-of-error-codes */
29-
SQLITE_ERROR(sqlite3.SQLITE_ERROR), /* Generic error */
30-
SQLITE_INTERNAL(sqlite3.SQLITE_INTERNAL), /* Internal logic error in SQLite */
31-
SQLITE_PERM(sqlite3.SQLITE_PERM), /* Access permission denied */
32-
SQLITE_ABORT(sqlite3.SQLITE_ABORT), /* Callback routine requested an abort */
33-
SQLITE_BUSY(sqlite3.SQLITE_BUSY), /* The database file is locked */
34-
SQLITE_LOCKED(sqlite3.SQLITE_LOCKED), /* A table in the database is locked */
35-
SQLITE_NOMEM(sqlite3.SQLITE_NOMEM), /* A malloc() failed */
36-
SQLITE_READONLY(sqlite3.SQLITE_READONLY), /* Attempt to write a readonly database */
37-
SQLITE_INTERRUPT(sqlite3.SQLITE_INTERRUPT), /* Operation terminated by sqlite3_interrupt()*/
38-
SQLITE_IOERR(sqlite3.SQLITE_IOERR), /* Some kind of disk I/O error occurred */
39-
SQLITE_CORRUPT(sqlite3.SQLITE_CORRUPT), /* The database disk image is malformed */
40-
SQLITE_NOTFOUND(sqlite3.SQLITE_NOTFOUND), /* Unknown opcode in sqlite3_file_control() */
41-
SQLITE_FULL(sqlite3.SQLITE_FULL), /* Insertion failed because database is full */
42-
SQLITE_CANTOPEN(sqlite3.SQLITE_CANTOPEN), /* Unable to open the database file */
43-
SQLITE_PROTOCOL(sqlite3.SQLITE_PROTOCOL), /* Database lock protocol error */
44-
SQLITE_EMPTY(sqlite3.SQLITE_EMPTY), /* Internal use only */
45-
SQLITE_SCHEMA(sqlite3.SQLITE_SCHEMA), /* The database schema changed */
46-
SQLITE_TOOBIG(sqlite3.SQLITE_TOOBIG), /* String or BLOB exceeds size limit */
47-
SQLITE_CONSTRAINT(sqlite3.SQLITE_CONSTRAINT), /* Abort due to constraint violation */
48-
SQLITE_MISMATCH(sqlite3.SQLITE_MISMATCH), /* Data type mismatch */
49-
SQLITE_MISUSE(sqlite3.SQLITE_MISUSE), /* Library used incorrectly */
50-
SQLITE_NOLFS(sqlite3.SQLITE_NOLFS), /* Uses OS features not supported on host */
51-
SQLITE_AUTH(sqlite3.SQLITE_AUTH), /* Authorization denied */
52-
SQLITE_FORMAT(sqlite3.SQLITE_FORMAT), /* Not used */
53-
SQLITE_RANGE(sqlite3.SQLITE_RANGE), /* 2nd parameter to sqlite3_bind out of range */
54-
SQLITE_NOTADB(sqlite3.SQLITE_NOTADB), /* File opened that is not a database file */
55-
SQLITE_NOTICE(sqlite3.SQLITE_NOTICE), /* Notifications from sqlite3_log() */
56-
SQLITE_WARNING(sqlite3.SQLITE_WARNING), /* Warnings from sqlite3_log() */
57-
SQLITE_ROW(sqlite3.SQLITE_ROW), /* sqlite3_step() has another row ready */
58-
SQLITE_DONE(sqlite3.SQLITE_DONE), /* sqlite3_step() has finished executing */
29+
SQLITE_ERROR(co.touchlab.sqliter.sqlite3.SQLITE_ERROR), /* Generic error */
30+
SQLITE_INTERNAL(co.touchlab.sqliter.sqlite3.SQLITE_INTERNAL), /* Internal logic error in SQLite */
31+
SQLITE_PERM(co.touchlab.sqliter.sqlite3.SQLITE_PERM), /* Access permission denied */
32+
SQLITE_ABORT(co.touchlab.sqliter.sqlite3.SQLITE_ABORT), /* Callback routine requested an abort */
33+
SQLITE_BUSY(co.touchlab.sqliter.sqlite3.SQLITE_BUSY), /* The database file is locked */
34+
SQLITE_LOCKED(co.touchlab.sqliter.sqlite3.SQLITE_LOCKED), /* A table in the database is locked */
35+
SQLITE_NOMEM(co.touchlab.sqliter.sqlite3.SQLITE_NOMEM), /* A malloc() failed */
36+
SQLITE_READONLY(co.touchlab.sqliter.sqlite3.SQLITE_READONLY), /* Attempt to write a readonly database */
37+
SQLITE_INTERRUPT(co.touchlab.sqliter.sqlite3.SQLITE_INTERRUPT), /* Operation terminated by sqlite3_interrupt()*/
38+
SQLITE_IOERR(co.touchlab.sqliter.sqlite3.SQLITE_IOERR), /* Some kind of disk I/O error occurred */
39+
SQLITE_CORRUPT(co.touchlab.sqliter.sqlite3.SQLITE_CORRUPT), /* The database disk image is malformed */
40+
SQLITE_NOTFOUND(co.touchlab.sqliter.sqlite3.SQLITE_NOTFOUND), /* Unknown opcode in sqlite3_file_control() */
41+
SQLITE_FULL(co.touchlab.sqliter.sqlite3.SQLITE_FULL), /* Insertion failed because database is full */
42+
SQLITE_CANTOPEN(co.touchlab.sqliter.sqlite3.SQLITE_CANTOPEN), /* Unable to open the database file */
43+
SQLITE_PROTOCOL(co.touchlab.sqliter.sqlite3.SQLITE_PROTOCOL), /* Database lock protocol error */
44+
SQLITE_EMPTY(co.touchlab.sqliter.sqlite3.SQLITE_EMPTY), /* Internal use only */
45+
SQLITE_SCHEMA(co.touchlab.sqliter.sqlite3.SQLITE_SCHEMA), /* The database schema changed */
46+
SQLITE_TOOBIG(co.touchlab.sqliter.sqlite3.SQLITE_TOOBIG), /* String or BLOB exceeds size limit */
47+
SQLITE_CONSTRAINT(co.touchlab.sqliter.sqlite3.SQLITE_CONSTRAINT), /* Abort due to constraint violation */
48+
SQLITE_MISMATCH(co.touchlab.sqliter.sqlite3.SQLITE_MISMATCH), /* Data type mismatch */
49+
SQLITE_MISUSE(co.touchlab.sqliter.sqlite3.SQLITE_MISUSE), /* Library used incorrectly */
50+
SQLITE_NOLFS(co.touchlab.sqliter.sqlite3.SQLITE_NOLFS), /* Uses OS features not supported on host */
51+
SQLITE_AUTH(co.touchlab.sqliter.sqlite3.SQLITE_AUTH), /* Authorization denied */
52+
SQLITE_FORMAT(co.touchlab.sqliter.sqlite3.SQLITE_FORMAT), /* Not used */
53+
SQLITE_RANGE(co.touchlab.sqliter.sqlite3.SQLITE_RANGE), /* 2nd parameter to sqlite3_bind out of range */
54+
SQLITE_NOTADB(co.touchlab.sqliter.sqlite3.SQLITE_NOTADB), /* File opened that is not a database file */
55+
SQLITE_NOTICE(co.touchlab.sqliter.sqlite3.SQLITE_NOTICE), /* Notifications from sqlite3_log() */
56+
SQLITE_WARNING(co.touchlab.sqliter.sqlite3.SQLITE_WARNING), /* Warnings from sqlite3_log() */
57+
SQLITE_ROW(co.touchlab.sqliter.sqlite3.SQLITE_ROW), /* sqlite3_step() has another row ready */
58+
SQLITE_DONE(co.touchlab.sqliter.sqlite3.SQLITE_DONE), /* sqlite3_step() has finished executing */
5959
}

sqliter-driver/src/nativeCommonMain/kotlin/co/touchlab/sqliter/interop/SqliteDatabase.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package co.touchlab.sqliter.interop
33
import cnames.structs.sqlite3
44
import cnames.structs.sqlite3_stmt
55
import kotlinx.cinterop.*
6-
import sqlite3.*
6+
import co.touchlab.sqliter.sqlite3.*
77

88
class SqliteDatabase(path:String, label:String, val logger: Logger, private val verboseDataCalls: Boolean, val dbPointer:SqliteDatabasePointer) {
99
val config = SqliteDatabaseConfig(path, label)

sqliter-driver/src/nativeCommonMain/kotlin/co/touchlab/sqliter/interop/Types.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ package co.touchlab.sqliter.interop
33
import cnames.structs.sqlite3_stmt
44
import kotlinx.cinterop.CPointer
55

6-
typealias SqliteDatabasePointer = CPointer<sqlite3.sqlite3>
6+
typealias SqliteDatabasePointer = CPointer<co.touchlab.sqliter.sqlite3.sqlite3>
77
typealias SqliteStatementPointer = CPointer<sqlite3_stmt>

sqliter-driver/src/nativeInterop/cinterop/sqlite3.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package = sqlite3
1+
package = co.touchlab.sqliter.sqlite3
22
headers = sqlite3.h
33
headerFilter = sqlite3*.h
44

0 commit comments

Comments
 (0)