DBAL_pgsql.py :  » Business-Application » OpenRMS » openres-0.2.1 » client » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Business Application » OpenRMS 
OpenRMS » openres 0.2.1 » client » DBAL_pgsql.py
# 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"
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.