> I'm trying to create an insert statement into tables like the 
> following using parameter bindings:
[...]
>         cursor.execute("INSERT INTO 
> load_data(user_data,user_number) values(?,?)", [val1,val2]) 

using sapdb.sql:

session = sapdb.sql.connect (...)
insertStmt = session.prepare ("""INSERT INTO 
 load_data(user_data,user_number) values(?,?)""")
for line in open (fname)
    data, number = splitline (line)
    insertStmt.execute ([data, int (number)]

alternative using sapdb.sql:
session = sapdb.sql.connect (...)
insertStmt = session.prepare ("""INSERT INTO 
 load_data(user_data,user_number) values(?,?)""")
insert = insertStmt.execute # insert is now a callable object
for line in open (fname)
    data, number = splitline (line)
    insert ([data, int (number)])

using sapdb.dbapi:
session = sapdb.dbapi.connect (...)
cursor = session.cursor ()
for line in open (fname):
    data, number = splitline (line)
    cursor.execute ("""INSERT INTO  load_data(user_data,user_number) 
        values(?,?)""", 
        ([data, int (number)])

Annotations:

- be sure to convert the values to the right type, otherwise, the right
  exception will appear, but from the wrong line (yes, that's a bug)
- setTypeTranslations allows you you automatically translate output values
  of a cursor (say, from MaxDB date string to Python date class), but is of
  no use for input values
- setinputsizes is not necessary for MaxDB
- insertStmt.getDescription () will describe the types of the input parameters
  (if you want to create a generic string2sql filter)

Daniel Dittmar

-- 
Daniel Dittmar
SAP Labs Berlin
[EMAIL PROTECTED]


-- 
MaxDB Discussion Mailing List
For list archives: http://lists.mysql.com/maxdb
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to