[DB-SIG] Insert for Oracledb
Victoria White
white@fnal.gov
Fri, 21 Nov 1997 08:37:26 -0600
Cary,
Yes, thank you for your response. That indeed does work, however I put that into the category of 'hardcoding the values into the sql string' - since you basically explicitly
convert to ASCII with str() and insert into the sql string. I had hoped that I could use
execute(sqlstring, [params...]) as documented in the DBI document with params presented as one (or more) parameters giving basically a List of Tuples (or arrays of values) to be
"bound" to the input column names given, in some Oracle-specific/binding magic format, in the sql string. However, I find that a) only one param is permitted with the oracledb
implementation and
b) I cannot find the secret way to "bind" the List of Tuples into the sql command - not even for a single record insert, although I really want it to work for a whole list of tuples.
It is probably extremely simple and just that I don't understand the notation
involved in specifying the sqlstring and its column names to be bound.
However, I do appreciate your response and am interested to find another living soul using this package.
Vicky
Cary Collett wrote:
> Vicky,
>
> Here's a quick, dirty example...
>
> >>> import oracledb
> >>> cobj = oracledb.oracledb('foo/bar')
> >>> cu = cobj.cursor()
> >>> a = (1,11714,10,0,'Bob')
> >>> qs = "INSERT INTO ppiOrder (orderID,accountID,amount,discountPercent,salesRepName) VALUES (" + str(a[0]) + "," + str(a[1]) + "," + str(a[2]) + "," + str(a[3]) + ",'" + a[4] + "')"
> >>> qs
> "INSERT INTO ppiOrder (orderID,accountID,amount,discountPercent,salesRepName) VALUES (1,11714,10,0,'Bob')"
> >>> cu.execute(qs)
> 1
> >>> cobj.rollback()
>
> You might also have your program send the query string to the stdout
> or stderr to see what it looks like. Try it in sqlplus, it will
> give you a little bit better error diagnostics.
>
> Hope this helps,
>
> Cary
>
> >
> > Please can someone send me a working code sample of how they
> > successfully used the oracledb module (from Digital Creations) to insert
> > one or more rows into an oracle database, preferably based on a List of
> > previously constructed Tuples.
> > I have looked at the example posted by Andrew Kuchling (for Solid), and
> > read most of the past email, including a discussion about binding of
> > variables using the :N notation. However, although I can query the
> > database I have had no success at inserting rows, except by hardcoding
> > the values into the sql string.
> > Whatever I try I seem to get Parse errors, or too many arguments, or
> > sql not properly terminated, or missing parens, or something! - even
> > for 1 row.
> > There seems to be very little activity on this SIG, with no updates to
> > database API documentation since 1996! Is there really no-one out
> > there using this stuff, for Oracle?
> > Would appreciate help
> > Vicky White
> >
> >
> > _______________
> > DB-SIG - SIG on Tabular Databases in Python
> >
> > send messages to: db-sig@python.org
> > administrivia to: db-sig-request@python.org
> > _______________
> >
_______________
DB-SIG - SIG on Tabular Databases in Python
send messages to: db-sig@python.org
administrivia to: db-sig-request@python.org
_______________