inserting integer in Table

Thomas SMETS tsmets at altern.org
Mon Jul 24 19:54:48 EDT 2000


In PostgreSQL table is :
<snip>
test=> \d  test_blob_s;
Table    = test_blob_s
+----------------------------------+----------------------------------+-------+
|              Field               |              Type                |
Length|
+----------------------------------+----------------------------------+-------+
| filenumber                       | int4                            
|     4 |
| filename                         | varchar()                       
|   100 |
| filecontent                      | oid                             
|     4 |
+----------------------------------+----------------------------------+-------+
test=>
</snip>


Now I'm willing to insert in that table rows like this one :
<i>, <file_name_i>, <file_name_i_content>. 

Here's is the (not-so-running) code :

<snip>
#
#
# ############################################
import os, glob
from pg import DB

conn=DB('test')
conn.query("BEGIN WORK;")

i = 0
for name in glob.glob("*.jpg"):
    print "Name is ", name,
    try:
        conn.query("insert into test_blob_s  filenumber  values (" + i +
")")
        print " inserted"
    except TypeError,e:
            print '\nerror ', e, 'undefined'    
#    conn.query( "update test_blob_s set filename = '" + name + "')")
#    conn.query( "update test_blob_s set filecontent = '" +
lo_import(name) + "')")

    i = i + 1

conn.query(" COMMIT WORK;");

</snip>


of course I can't have it passing the insert of "i"
Could some one help ?

Thomas,





-- 

Thomas SMETS                           Phone : +32 (0)2 742. 05. 94.
Av. de la Brabançonne 133 / 3          e-mail : tsmets @altern.org
1030 Bruxelles

==== Quote of the day =========
You shouldn't wallow in self-pity.  But it's OK to put your feet in it
and swish them around a little.
		-- Guindon
 ======= End of Quote =========



More information about the Python-list mailing list