-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyinfodb.py
37 lines (28 loc) · 975 Bytes
/
pyinfodb.py
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
import os
import informixdb
# NEED informix libs c esql
# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$INFORMIXDIR/lib:$INFORMIXDIR/lib/esql
def errorhandler(connection, cursor, errorclass, errorvalue):
print "errorclass: "+str(errorclass)
print "errorvalue: "+str(errorvalue)
#def dbconn(dbname, dbuser, dbpass):
def dbconn(creds):
(dbname, dbuser, dbpass) = creds
conn = informixdb.connect(dbname, user=dbuser, password=dbpass)
conn.autocommit = True
return conn
def select_all(conn, table):
cursor = conn.cursor()
sql = "SELECT * FROM"+table
cursor.execute(sql)
all = cursor.fetchall()
for record in all:
print record, "\n"
def delete_all(conn, table):
cursor = conn.cursor()
sql = "DELETE FROM "+table
cursor.execute(sql)
def serverinfo(conn):
print "python INFORMIXDB version "+ informixdb.version
print "driver name : " +conn.driver_name
print "driver version : "+conn.driver_version