[DB-SIG] Re: Probelem with inserting into postgres database using python

Mubaraka Arif marif@alvin.stmarytx.edu
Thu, 28 Feb 2002 02:59:20 -0600


>> hey Kelvin,
>> 
>> Thanks for providing sample code accessing postgres database thru
>> python interface. Earlier , i was using the "pg" module which worked
>> fine , but it would not allow cursor handling. But yr approach thru
>> "pgdb" interface uses the cursor mechanisms , so I shall include it 
>> in my development too.
>> 
>> Thanks and I appreciate yr help !
>> 
>> Mubaraka Arif
>> Data Management Software Developer
>> St, Mary's UNiversity, TX
>> Administrative Technology and Information Services
>> ph: (210)- 525-8056
>> email - marif@alvin.stmarytx.edu
>> 
>> On 2002.02.27 12:31 Kevin Cole wrote:
>> > Hi,
>> >
>> > I've attached an example of how to insert with Python.  I stripped
>> > down
>> > an application that I wrote.  It may not be the most efficient way
>> to
>> > do
>> > things but it appears to work fine for us.
>> >
>> > I hope it helps you.
>> > --
>> >  Kevin Cole, RHCE, Linux Admin  |  E-mail:  
>> kjcole@gri.gallaudet.edu
>> >  Gallaudet Research Institute   |  WWW:
>> > http://gri.gallaudet.edu/~kjcole/
>> >  Hall Memorial Bldg  S-419      |  Voice:   (202) 651-5135
>> >  Washington, D.C.  20002-3695   |  FAX:     (202) 651-5746
>> >
>> > #!/usr/bin/env python
>> > from sys         import *               # Which OS are we using?
>> > import os                               # Operating system 
>> functions
>> > import os.path                          # Ditto
>> > import pgdb                             # PostgreSQL interface
>> >
>> > bookstore = pgdb.connect("localhost:boox")	# Open the "boox"
>> > database
>> > newz = bookstore.cursor()			# Establish a
>> > "cursor"
>> >
>> > 
>> #########################################################################
>> > # DELETED: Gather data from web form, error-check it, make sure the
>> > ID	#
>> > # field is unique, etc, 
>> etc.						 > #
>> > 
>> #########################################################################
>> >
>> > inst = replace(title, "'", "''")		# Escape all single
>> > quotes
>> > insw = replace(author, "'", "''")
>> > insk = replace(keywords, "'", "''")
>> > insa = replace(abstract, "'", "''")
>> > values = (id,yr,issue,page,article,inst,insw,insk,insa,pdf,touched)
>> > insert = "insert into newz values
>> > (%s,%s,%s,%s,%s,'%s','%s','%s','%s','%s','%s');"
>> > newz.execute(insert % (values))
>> > boox.commit()
>> >
>> 
>> 
> 
> _______________________________________________
> DB-SIG maillist  -  DB-SIG@python.org
> http://mail.python.org/mailman/listinfo/db-sig
>