started working on the nit wrapper over the native postgres wrapper
[nit.git] / tests / test_postgres_nity.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2016 Guilherme Mansur <guilhermerpmansur@gmail.com>
4 #
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
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
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.
16
17 module test_postgres_nity
18
19 import postgresql::postgres
20
21 var db = new Postgres.open("dbname=postgres")
22 assert open_db: not db.is_closed else print db.error
23
24 assert create_table: db.create_table("IF NOT EXISTS users (uname TEXT PRIMARY KEY, pass TEXT NOT NULL, activated INTEGER, perc FLOAT)") else
25 print db.error
26 end
27
28 assert insert1: db.insert("INTO users VALUES('Bob', 'zzz', 1, 77.7)") else
29 print db.error
30 end
31
32 assert insert2: db.insert("INTO users VALUES('Guilherme', 'xxx', 1, 88)") else
33 print db.error
34 end
35
36 var result = db.raw_execute("SELECT * FROM users")
37
38 assert raw_exec: result.is_ok else print db.error
39
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
44
45 assert drop_table: db.execute("DROP TABLE users") else print db.error
46
47 db.finish
48
49 assert db.is_closed else print db.error