[Tutor] Re: Question on open and read html files and psycopg

Lee Harr missive at hotmail.com
Wed Sep 15 23:44:04 CEST 2004

Please wrap your long lines at < 75 characters ...

>As for psycopg...
>My code was based on python and pg module and I wanna to switch to DB-API, 
>such as psycopg. I
>  havn't really tried psycopg examples yet? BTW, where to get them?

The examples come with the psycopg distribution.
If you have not downloaded that and looked through
it and read the instructions included with it, I am not
quite sure why you are asking here first.

>You mean try connecting with
>  psycopg? Just to correct my previous mail, psycopg has not been installed 
>yet because there seems
>  to have some stuffs missing (postgresql header and etc) which stopped the 
>configuration, but
>  should be fixed in a day or two. So, I have not try psycopg yet.

Well. That seems like the first step. Maybe there are
pre-built packages available for your operating system.

>How to grab the query input from the user? Right now, the user have to type 
>in SQL statements
>  (SELECT * FROM ....)to search for data. Thats not what I want, I need the 
>grab the input from the
>  user (keywords) and match with the meta-data
>in the tables (postgresql) and return the results.
>  This is the part where I'm stucked.

Your code previously worked just fine to get the input
from the user through the web. Just instead of asking
for a complete SQL query (which would be a bad idea)
Just ask for keywords and build up a string from there.

You need to learn things one step at a time. If you do
not yet know how to create a string from other strings
you need to learn that first.

By the way. The code I posted yesterday was bogus...
some kind of bad mix between your code and my code.

This works w/ psycopg:

    # Now, we can get to the database...
    import psycopg
    db = psycopg.connect("dbname=test user=%s"%username)
    cursor = db.cursor()
    listOfResults = cursor.dictfetchall()

Sorry about that.

Tired of spam? Get advanced junk mail protection with MSN 8. 

More information about the Tutor mailing list