[mod_python] newbie question regarding postgresql

Johnny Morano johnny.morano at vlaanderen.be
Fri Apr 19 10:39:03 EST 2002


hey all,

I'm trying to make a python script for database connection, but it doesn't 
seem to work in mod_python, although it runs fine on the command line.
Can anyone see my big mistake?

--begin-code---
from mod_python import apache
import pgdb

def s(req):
        nHost='localhost'
        nDbname='netdoc'
        readUser='nd_read'

        con = pgdb.connect(dsn=nHost+':'+nDbname, user=readUser)
        curs = con.cursor()
        curs.execute(""" SELECT relname as tablename
                         , pg_get_userbyid(relowner) AS tableowner
                         , relhasindex as hasindexes
                         , relhasrules as hasrules
                         , reltriggers as hastriggers
                         , pg_class.oid
                         , description as table_description
                         , relacl
                      FROM pg_class
                      LEFT OUTER JOIN pg_description on (   pg_class.oid = 
pg_description.objoid
                                                      AND 
pg_description.objsubid = 0)
                     WHERE (  relkind = 'r'::"char"
                           OR relkind = 's'::"char"
                           )
                       AND relname NOT LIKE 'pg_%' """)
        rows = curs.fetchall()
        x = "the table names: \n"
        for row in rows:
                x += "\t" + row[0] + "\n"
        return x
---end-code---

thanx !
-- 
Johnny Morano - Linux Consultant
___________________________________________________ 
 Ministerie Vlaamse Gemeenschap                    |
 Koning Albert II-laan, 7 (610) 1210 Brussel       |
 tel: 02/5531319 mail: johnny.morano at vlaanderen.be |



More information about the Mod_python mailing list