55def double (f : Nat -> Nat) n := f (f n)
66def inc := fun n => n + 1
77
8+ def cursorExplain (c : Sqlite.FFI.Connection) (emode : UInt32) : IO Unit := do
9+ match ← c.prepare "select * from users limit 50;" with
10+ | Except.error e => println s! "error { e} "
11+ | Except.ok q => do
12+ let _ ← q.cursorExplain emode
13+ let c ← q.columnsCount
14+ println s! "columnsCount: { c} "
15+ for i in [0 :100 ] do
16+ match ← q.step with
17+ | false => pure ()
18+ | true => do
19+ println s! "{ i} explain: { ← q.columnInt 0 } { ← q.columnText 1 } "
20+
21+
822def printUser (fuel : Nat) (cursor : Sqlite.FFI.Cursor) : IO Unit := do
923 if fuel = 0 then
1024 pure ()
@@ -16,7 +30,16 @@ def printUser (fuel : Nat) (cursor : Sqlite.FFI.Cursor) : IO Unit := do
1630 printUser (fuel - 1 ) cursor
1731
1832def main : IO Unit := do
19- let conn ← Sqlite.FFI.connect "test.sqlite3"
33+ println $ ← Sqlite.FFI.sqliteThreadsafe
34+ println Sqlite.FFI.Constants.SQLITE_CONFIG_SINGLETHREAD
35+ println Sqlite.FFI.Constants.SQLITE_CONFIG_MULTITHREAD
36+ println $ ← Sqlite.FFI.sqliteConfig Sqlite.FFI.Constants.SQLITE_CONFIG_MULTITHREAD
37+ let flags := Sqlite.FFI.Constants.SQLITE_OPEN_READWRITE ||| Sqlite.FFI.Constants.SQLITE_OPEN_CREATE
38+ let conn ← Sqlite.FFI.connect "test.sqlite3" flags
39+ cursorExplain conn 1
40+ match ← conn.prepare "delete from users where id = 154;" with
41+ | Except.ok c => c.step
42+ | _ => pure false
2043 match ← conn.prepare "insert into users values (?, ?);" with
2144 | Except.error e => println s! "error { e} "
2245 | Except.ok c =>
@@ -26,7 +49,7 @@ def main : IO Unit := do
2649 println "----------------------------------------------------------------"
2750 match ← conn.prepare "select count(1) from users;" with
2851 | Except.ok c =>
29- println s! "{ c.columnsCount} "
52+ println s! "{ ← c.columnsCount} "
3053 match ← c.step with
3154 | false => println "error"
3255 | true => println "step"
0 commit comments