1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2013 Guillaume Auger <jeho@resist.ca>
4 # Copyright 2013 Alexis Laferrière <alexis.laf@xymus.net>
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
18 module test_sqlite3_native
20 import sqlite3
::native_sqlite3
22 var filename
= "test.db"
24 var create_req
= "CREATE TABLE IF NOT EXISTS users (uname TEXT PRIMARY KEY, pass TEXT NOT NULL, activated INTEGER)"
25 var insert_req_1
= "INSERT INTO users VALUES('Bob', 'zzz', 1)"
26 var insert_req_2
= "INSERT INTO users VALUES('Guillaume', 'xxx', 1)"
27 var select_req
= "SELECT * FROM users"
29 var db
= new NativeSqlite3.open
(filename
.to_cstring
)
30 assert sqlite_open
: db
.error
.is_ok
33 assert sqlite_create_table
: db
.error
.is_ok
36 assert sqlite_insert_1
: db
.error
.is_ok
39 assert sqlite_insert_2
: db
.error
.is_ok
41 var stmt
= db
.prepare
(select_req
)
42 assert sqlite_select
: db
.error
.is_ok
44 print
"Prepared failed got: {db.error.to_s}"
48 while stmt
.step
.is_row
do
49 print stmt
.column_text
(0)
50 print stmt
.column_text
(1)
51 print stmt
.column_text
(2)
56 db
= new NativeSqlite3.open
(filename
.to_cstring
)
57 assert sqlite_reopen
: db
.error
.is_ok
59 stmt
= db
.prepare
(select_req
)
60 assert sqlite_reselect
: db
.error
.is_ok
63 assert sqlite_column_0_0_reopened
: stmt
.column_text
(0).to_s
== "Bob"