mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 17:18:52 -06:00
Remove custom iosTest task; fix IosDatabase
This commit is contained in:
@@ -122,24 +122,11 @@ kotlin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// task iosTestCopyResources(type: Copy) {
|
task iosTestCopyResources(type: Copy) {
|
||||||
// dependsOn 'linkTestIos'
|
from 'assets/test/'
|
||||||
// from 'assets/test/'
|
from 'assets/main/'
|
||||||
// from 'assets/main/'
|
into 'build/bin/ios/debugTest'
|
||||||
// into 'build/bin/ios/testDebugExecutable'
|
}
|
||||||
// }
|
|
||||||
//
|
iosTest.dependsOn(iosTestCopyResources)
|
||||||
// task iosTestCustom {
|
|
||||||
// dependsOn 'linkTestIos', 'iosTestCopyResources'
|
|
||||||
// group = JavaBasePlugin.VERIFICATION_GROUP
|
|
||||||
// description = "Runs tests on iOS simulator"
|
|
||||||
//
|
|
||||||
// doLast {
|
|
||||||
// def emulatorName = "iPhone 8 Plus"
|
|
||||||
// def binary = kotlin.targets.ios.compilations.test.getBinary('EXECUTABLE', 'DEBUG')
|
|
||||||
// exec {
|
|
||||||
// commandLine 'xcrun', 'simctl', 'spawn', emulatorName, binary.absolutePath
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
@@ -20,19 +20,25 @@
|
|||||||
package org.isoron.platform.io
|
package org.isoron.platform.io
|
||||||
|
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
|
import platform.Foundation.*
|
||||||
import sqlite3.*
|
import sqlite3.*
|
||||||
|
|
||||||
fun sqlite3_errstr(db: CPointer<sqlite3>): String {
|
fun sqlite3_errstr(db: CPointer<sqlite3>): String {
|
||||||
return "SQLite3 error: " + sqlite3_errmsg(db).toString()
|
return "SQLite3 error: " + sqlite3_errmsg(db).toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("CAST_NEVER_SUCCEEDS")
|
||||||
class IosDatabaseOpener : DatabaseOpener {
|
class IosDatabaseOpener : DatabaseOpener {
|
||||||
override fun open(file: UserFile): Database = memScoped {
|
override fun open(file: UserFile): Database = memScoped {
|
||||||
val db = alloc<CPointerVar<sqlite3>>()
|
|
||||||
val path = (file as IosFile).path
|
val path = (file as IosFile).path
|
||||||
if (sqlite3_open(path, db.ptr) != SQLITE_OK) {
|
val dirname = (path as NSString).stringByDeletingLastPathComponent
|
||||||
throw Exception(sqlite3_errstr(db.value!!))
|
NSFileManager.defaultManager.createDirectoryAtPath(dirname, true, null, null)
|
||||||
}
|
|
||||||
|
val db = alloc<CPointerVar<sqlite3>>()
|
||||||
|
val result = sqlite3_open(path, db.ptr)
|
||||||
|
if (result != SQLITE_OK)
|
||||||
|
throw Exception("sqlite3_open failed (code $result)")
|
||||||
|
|
||||||
return IosDatabase(db.value!!)
|
return IosDatabase(db.value!!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -41,9 +47,9 @@ class IosDatabase(val db: CPointer<sqlite3>) : Database {
|
|||||||
override fun prepareStatement(sql: String): PreparedStatement = memScoped {
|
override fun prepareStatement(sql: String): PreparedStatement = memScoped {
|
||||||
if (sql.isEmpty()) throw Exception("empty SQL query")
|
if (sql.isEmpty()) throw Exception("empty SQL query")
|
||||||
val stmt = alloc<CPointerVar<sqlite3_stmt>>()
|
val stmt = alloc<CPointerVar<sqlite3_stmt>>()
|
||||||
if (sqlite3_prepare_v2(db, sql.cstr, -1, stmt.ptr, null) != SQLITE_OK) {
|
val result = sqlite3_prepare_v2(db, sql.cstr, -1, stmt.ptr, null)
|
||||||
throw Exception(sqlite3_errstr(db))
|
if (result != SQLITE_OK)
|
||||||
}
|
throw Exception("sqlite3_prepare_v2 failed (code $result)")
|
||||||
return IosPreparedStatement(db, stmt.value!!)
|
return IosPreparedStatement(db, stmt.value!!)
|
||||||
}
|
}
|
||||||
override fun close() {
|
override fun close() {
|
||||||
@@ -54,8 +60,7 @@ class IosDatabase(val db: CPointer<sqlite3>) : Database {
|
|||||||
class IosPreparedStatement(val db: CPointer<sqlite3>,
|
class IosPreparedStatement(val db: CPointer<sqlite3>,
|
||||||
val stmt: CPointer<sqlite3_stmt>) : PreparedStatement {
|
val stmt: CPointer<sqlite3_stmt>) : PreparedStatement {
|
||||||
override fun step(): StepResult {
|
override fun step(): StepResult {
|
||||||
val result = sqlite3_step(stmt)
|
when (sqlite3_step(stmt)) {
|
||||||
when (result) {
|
|
||||||
SQLITE_ROW -> return StepResult.ROW
|
SQLITE_ROW -> return StepResult.ROW
|
||||||
SQLITE_DONE -> return StepResult.DONE
|
SQLITE_DONE -> return StepResult.DONE
|
||||||
else -> throw Exception(sqlite3_errstr(db))
|
else -> throw Exception(sqlite3_errstr(db))
|
||||||
|
|||||||
Reference in New Issue
Block a user