Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boolean unwrapping fix #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static const char *bind1(sqlite3_stmt *stmt, int index, Janet value) {
res = sqlite3_bind_null(stmt, index);
break;
case JANET_BOOLEAN:
res = sqlite3_bind_int(stmt, index, janet_unwrap_integer(value));
res = sqlite3_bind_int(stmt, index, janet_unwrap_boolean(value));
break;
case JANET_NUMBER:
res = sqlite3_bind_double(stmt, index, janet_unwrap_number(value));
Expand Down
14 changes: 7 additions & 7 deletions test/test.janet
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
(if (not c) (error "failed assertion")))
(def db (sql/open "build/test.db"))
(try (sql/eval db `DROP TABLE people`) ([_]))
(sql/eval db `CREATE TABLE people(name TEXT, age INTEGER);`)
(sql/eval db `INSERT INTO people values(:name, :age)` {:name "John" :age 20})
(sql/eval db `INSERT INTO people values(:name, :age)` {:name "Paul" :age 30})
(sql/eval db `INSERT INTO people values(:name, :age)` {:name "Bob" :age 40})
(sql/eval db `INSERT INTO people values(:name, :age)` {:name "Joe" :age 50})
(sql/eval db `CREATE TABLE people(name TEXT, age INTEGER, bool INTEGER);`)
(sql/eval db `INSERT INTO people values(:name, :age, :bool)` {:name "John" :age 20 :bool false})
(sql/eval db `INSERT INTO people values(:name, :age, :bool)` {:name "Paul" :age 30 :bool true})
(sql/eval db `INSERT INTO people values(:name, :age, :bool)` {:name "Bob" :age 40 :bool false})
(sql/eval db `INSERT INTO people values(:name, :age, :bool)` {:name "Joe" :age 50 :bool true})
(def results (sql/eval db `SELECT * FROM people`))
(assert (= (length results) 4))

(def update-result
(-> (sql/eval db
`UPDATE people set name = :new_name where name = :old_name RETURNING name, age`
`UPDATE people set name = :new_name where name = :old_name RETURNING name, age, bool`
{:new_name "Harry" :old_name "Paul"})
(first)))
(assert (= update-result {:name "Harry" :age 30}))
(assert (= update-result {:name "Harry" :age 30 :bool 1}))


(sql/close db)