parameter binding

This commit is contained in:
2026-03-03 23:15:41 -05:00
parent eb29593eb0
commit f1e9650c97
4 changed files with 67 additions and 2 deletions

View File

@@ -10,12 +10,17 @@ tail fun do-while(f: () -> <div|e> maybe<a>): <div|e> a
Nothing -> do-while(f)
Just(r) -> r
fun stmt(db: sqlite3, sql: string)
fun stmt(db: sqlite3, sql: string, bind: maybe<string> = Nothing)
println(sql)
match db.prepare(sql.slice)
Left(r-prep) -> println(" prepare result: " ++ r-prep.show)
Right((stmt, rest)) ->
println(" prepare remainder: " ++ rest.show)
match bind
Nothing -> ()
Just(text) ->
val r = stmt.bind-text(1, text)
println(" bind result: " ++ r.show)
val r-step = do-while
val r = stmt.step
match r
@@ -34,7 +39,7 @@ pub fun main()
println("open result: " ++ r-open.show)
stmt(db, "DROP TABLE IF EXISTS koka; -- reset previous test runs")
stmt(db, "CREATE TABLE koka(v TEXT NOT NULL)")
stmt(db, "INSERT INTO koka VALUES ('value inserted from koka');")
stmt(db, "INSERT INTO koka VALUES (?);", Just("value inserted from koka"))
stmt(db, "SELECT * FROM koka")
val r-close = db.close
println("close result: " ++ r-close.show)