# PostgreSQL Database Abstraction Layer for OpenRMS
import string
from pyPgSQL import PgSQL
import math
PgSQL.noPostgresCursor = 1
def connect (dsn, username, password):
dsnc = string.split(dsn, ':')
len_dsnc = len(dsnc)
if len_dsnc == 1:
dbase = dsnc[0]
dsn = "::%s:%s:%s" % (dsn, username, password)
elif len_dsnc == 3:
dbase = dsnc[2]
dsn = "%s:%s:%s" % (dsn, username, password)
else:
raise Exception, "Invalid DSN Value"
if dbase == None or dbase == "":
raise Exception, "No database specified"
return PgSQL.connect(dsn)
def GetRowDict(cursor):
raw_array = cursor.fetchone()
description = cursor.description
index = 0;
retval = {}
if raw_array == None:
return None
while (index < len(description)):
retval[description[index][0]] = raw_array[index]
index += 1
return retval
def parse(query):
return query
def RunProcedure(cursor, proc_name, args = []):
query = 'SELECT proc_name('
index = 0
while len(args) > index:
query += '%s'
index += 1
if len.args > index:
query += ', '
query += ')'
cursor.execute(query, args)
def bool(var):
global TRUE
global FALSE
if var and var != FALSE:
return TRUE
else:
return FALSE
def is_true(var):
global TRUE
if bool(var) == TRUE:
return True
else:
return False
TRUE = 't'
FALSE = 'f'
BEGIN = "BEGIN"
COMMIT = "COMMIT"
|