1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2016 Guilherme Mansur <guilhermerpmansur@gmail.com>
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 module test_postgres_nity
19 import postgresql
::postgres
21 var db_suffix
= "NIT_TESTING_ID".environ
22 var db
= new Postgres.open
("dbname=postgres")
23 assert open_db
: not db
.is_closed
else print db
.error
25 assert create_table
: db
.create_table
("IF NOT EXISTS users_{db_suffix} (uname TEXT PRIMARY KEY, pass TEXT NOT NULL, activated INTEGER, perc FLOAT)") else
29 assert insert1
: db
.insert
("INTO users_{db_suffix} VALUES('Bob', 'zzz', 1, 77.7)") else
33 assert insert2
: db
.insert
("INTO users_{db_suffix} VALUES('Guilherme', 'xxx', 1, 88)") else
37 var result
= db
.raw_execute
("SELECT * FROM users_{db_suffix}")
39 assert raw_exec
: result
.is_ok
else print db
.error
41 assert postgres_nfields
: result
.nfields
== 4 else print_error db
.error
42 assert postgres_fname
: result
.fname
(0) == "uname" else print_error db
.error
43 assert postgres_isnull
: result
.is_null
(0,0) == false else print_error db
.error
44 assert postgres_value
: result
.value
(0,0) == "Bob" else print_error db
.error
46 assert drop_table
: db
.execute
("DROP TABLE users_{db_suffix}") else print db
.error
50 assert db
.is_closed
else print db
.error