-
Notifications
You must be signed in to change notification settings - Fork 24
/
testnumbers.lua
57 lines (46 loc) · 1.48 KB
/
testnumbers.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
local pgsql = require 'pgsql'
conn = pgsql.connectdb('')
print(conn:errorMessage())
if conn:status() == pgsql.CONNECTION_OK then
print('connection is ok')
else
print('connection is not ok')
end
local n = 3.1415986
print(n)
local res = conn:exec('create table test (a integer, b numeric(8, 2), c float, d boolean)')
if res:status() ~= pgsql.PGRES_COMMAND_OK then
print('failed to create table')
print(res:errorMessage())
end
res = conn:execParams('insert into test (a, b, c) values ($1::integer, $1::numeric, $1)', n, n, n)
if res:status() ~= pgsql.PGRES_COMMAND_OK then
print('failed to insert data')
print(res:errorMessage())
end
res = conn:execParams('insert into test (c) values ($1)', n)
if res:status() ~= pgsql.PGRES_COMMAND_OK then
print('failed to insert data')
print(res:errorMessage())
end
-- Infinity
res = conn:execParams('insert into test (c) values ($1)', 1/0)
if res:status() ~= pgsql.PGRES_COMMAND_OK then
print('failed to insert data')
print(res:errorMessage())
end
-- -Infinity
res = conn:execParams('insert into test (c) values ($1)', -1/0)
if res:status() ~= pgsql.PGRES_COMMAND_OK then
print('failed to insert data')
print(res:errorMessage())
end
-- NaN
res = conn:execParams('insert into test (c) values ($1)', 0/0)
if res:status() ~= pgsql.PGRES_COMMAND_OK then
print('failed to insert data')
print(res:errorMessage())
end
res = conn:execParams('insert into test (d) values ($1)', true)
res = conn:execParams('insert into test (d) values ($1)', false)
conn:finish()