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
= new Postgres.open
("dbname=postgres")
22 assert open_db
: not db
.is_closed
else print db
.error
24 assert create_table
: db
.create_table
("IF NOT EXISTS users (uname TEXT PRIMARY KEY, pass TEXT NOT NULL, activated INTEGER, perc FLOAT)") else
28 assert insert1
: db
.insert
("INTO users VALUES('Bob', 'zzz', 1, 77.7)") else
32 assert insert2
: db
.insert
("INTO users VALUES('Guilherme', 'xxx', 1, 88)") else
36 var result
= db
.raw_execute
("SELECT * FROM users")
38 assert raw_exec
: result
.is_ok
else print db
.error
40 assert postgres_nfields
: result
.nfields
== 4 else print_error db
.error
41 assert postgres_fname
: result
.fname
(0) == "uname" else print_error db
.error
42 assert postgres_isnull
: result
.is_null
(0,0) == false else print_error db
.error
43 assert postgres_value
: result
.value
(0,0) == "Bob" else print_error db
.error
45 assert drop_table
: db
.execute
("DROP TABLE users") else print db
.error
49 assert db
.is_closed
else print db
.error