|
From: Michael W. <wa...@tr...> - 2002-07-04 16:22:43
|
And here is a simple example using the DBAPI wrapper.
#!/usr/local/bin/python
# run via cron
# purge pop before smtp records past an expiry time from virtual.pbsp
# send basic statistics to root
from pyPgSQL import PgSQL
## delete aged records
purge_age = 43200 # seconds (43200 = 12 hours)
query_string = 'delete from pbsp where extract(epoch from (now() -
since)) >= %d' % (purge_age,)
dsn = 'localhost::virtual' #dsn =
'host:port:database:username:password' some can be blank
db = PgSQL.connect(dsn)
cursor = db.cursor()
cursor.execute(query_string)
db.commit()
## spit out a simple report
query_string = """select mailbox_idnr as id, count(*) as msg_count,
sum(messagesize) as msg_size,
userid from messages, users where user_idnr = mailbox_idnr
group by mailbox_idnr, users.userid"""
cursor.execute(query_string)
result = cursor.fetchall()
print "System email statistics\n"
print "%-5s %5s %10s %s" % ('ID','Count','Size/K', 'Account')
for row in result:
print "%-5s %5s %10s %s" % (row.id, row.msg_count,
int(row.msg_size) / 1000, row.userid)
At 09:10 AM 7/4/2002 -0700, bob ackerman wrote:
>On Wednesday, July 3, 2002, at 08:53 PM, Ricardo Rivaldo wrote:
>
>>Does anyone have a sample source code on how to use pyPgSQL ? Please send
>>me if you have !
>>
>>Rivaldo
>
>i import it, but i use the lowlevel libpq, not the higher level wrapper:
>
>from pyPgSQL import libpq
>
>db = libpq.PQconnectdb('dbname=shopip')
> qry = "SELECT * from %s" % tbl_name
>qrslt = db.query(qry)
>for x in range(qrslt.ntuples):
> for y in range(qrslt.nfields):
> data_val = qrslt.getvalue(x,y)
>
>you could of course look at documentation? in Python library docs?
>
>hth
>
>pob
>
>
>
>-------------------------------------------------------
>This sf.net email is sponsored by:ThinkGeek
>Caffeinated soap. No kidding.
>http://thinkgeek.com/sf
>_______________________________________________
>Pypgsql-users mailing list
>Pyp...@li...
>https://lists.sourceforge.net/lists/listinfo/pypgsql-users
>
>
|