@@ -33,11 +33,11 @@ class SQLite3Driver internal constructor(private val db: Sqlite3.Database) : Sql
3333 if (enclosingTransaction == null ) {
3434 val sql = if (successful) " END TRANSACTION" else " ROLLBACK TRANSACTION"
3535 suspendCoroutine { cont ->
36- val callback: (Any? ) -> Unit = { self ->
37- if (self !is Throwable ) {
38- cont.resume(self as Sqlite3 . Statement )
36+ val callback: (Any? ) -> Unit = {
37+ if (it == null || it !is Throwable ) {
38+ cont.resume(it )
3939 } else {
40- cont.resumeWithException(SQLite3Exception (self ))
40+ cont.resumeWithException(SQLite3JsException (it ))
4141 }
4242 }
4343 db.exec(sql, callback)
@@ -60,9 +60,6 @@ class SQLite3Driver internal constructor(private val db: Sqlite3.Database) : Sql
6060 val res2 = db.prepare(sql)
6161 return @getOrPut res2
6262 }
63- // .apply {
64- // reset()
65- // }
6663 }
6764 return res
6865 }
@@ -75,7 +72,7 @@ class SQLite3Driver internal constructor(private val db: Sqlite3.Database) : Sql
7572 val rows = suspendCoroutine { cont ->
7673 statement.all { error, rows ->
7774 if (error is Throwable ) {
78- cont.resumeWithException(error)
75+ cont.resumeWithException(SQLite3JsException ( error) )
7976 } else {
8077 cont.resume(rows)
8178 }
@@ -88,19 +85,24 @@ class SQLite3Driver internal constructor(private val db: Sqlite3.Database) : Sql
8885 }
8986
9087 override fun execute (identifier : Int? , sql : String , parameters : Int , binders : (SqlPreparedStatement .() -> Unit )? ): QueryResult <Long > = QueryResult .AsyncValue {
91- val statement = createOrGetStatement(identifier, sql)
92- statement.bind(parameters, binders)
93- suspendCoroutine { cont ->
94- val callback: (Any ) -> Unit = { self ->
95- if (self is Throwable ) {
96- cont.resumeWithException(SQLite3Exception (self))
97- } else {
98- cont.resume(Unit )
88+ try {
89+ val statement = createOrGetStatement(identifier, sql)
90+ statement.bind(parameters, binders)
91+ suspendCoroutine { cont ->
92+ val callback: (Any ) -> Unit = {
93+ if (it is Throwable ) {
94+ cont.resumeWithException(SQLite3JsException (it))
95+ } else {
96+ cont.resume(Unit )
97+ }
9998 }
99+ statement.run (callback)
100100 }
101- statement.run (callback)
101+ return @AsyncValue 0
102+ } catch (e: Throwable ) {
103+ println (" exception $e " )
104+ return @AsyncValue 0
102105 }
103- return @AsyncValue 0
104106 }
105107
106108 override fun newTransaction (): QueryResult <Transacter .Transaction > = QueryResult .AsyncValue {
@@ -113,7 +115,7 @@ class SQLite3Driver internal constructor(private val db: Sqlite3.Database) : Sql
113115 if (it == null || it !is Throwable ) {
114116 cont.resume(it)
115117 } else {
116- cont.resumeWithException(SQLite3Exception (it))
118+ cont.resumeWithException(SQLite3JsException (it))
117119 }
118120 }
119121 db.exec(" BEGIN TRANSACTION" , callback)
@@ -159,16 +161,22 @@ class SQLite3Driver internal constructor(private val db: Sqlite3.Database) : Sql
159161 if (parameters > 0 ) {
160162 val bound = SQLite3PreparedStatement (parameters)
161163 binders(bound)
164+ println (" binders" )
162165 suspendCoroutine { cont ->
163166 val callback: (Any? ) -> Unit = {
164167 if (it == null || it !is Throwable ) {
168+ println (" bind resume" )
165169 cont.resume(it)
166170 } else {
167- cont.resumeWithException(it)
171+ println (" bind resume exception" )
172+ cont.resumeWithException(SQLite3JsException (it))
168173 }
169174 }
170- bind(bound.parameters.toTypedArray(), callback)
175+ println (" bind" )
176+ bind(bound.parameters.toTypedArray(), callback = callback)
177+ println (" bind end" )
171178 }
179+ println (" bind after susp" )
172180 }
173181 }
174182}
0 commit comments