/
postgresql_test.bas
50 lines (39 loc) · 1.02 KB
/
postgresql_test.bas
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
''
'' PostgreSQL (www.postgresql.org) example, translated from C by dr0p (dr0p[-at-]perfectbg.com)
''
#include "postgresql/libpq-fe.bi"
'' main
dim as string conninfo
dim as PGconn ptr conn
dim as PGresult ptr res
dim as integer nFields, i, j
conninfo = "dbname=postgres user=postgres password=12345678"
conn = PQconnectdb(conninfo)
if (PQstatus(conn) <> CONNECTION_OK) then
print "Connection to database failed: "; *PQerrorMessage(conn)
PQfinish(conn)
end 1
end if
res = PQexec(conn, "SELECT * FROM pg_database")
? PQresultStatus(res)
if (PQresultStatus(res) <> PGRES_TUPLES_OK) then
print "Command failed: "; *PQerrorMessage(conn)
PQclear(res)
PQfinish(conn)
end 1
end if
nFields = PQnfields(res)-1
for i = 0 to nFields
print *PQfname(res, i),
next
print
print
for i = 0 to PQntuples(res)-1
for j = 0 to nFields
print *PQgetvalue(res, i, j),
next
print
next
PQclear(res)
PQfinish(conn)
end 0