[PYTHON DB-SIG] RE: Looking for examples of oracledb usage

Greg Stein gstein@microsoft.com
Thu, 17 Apr 1997 18:16:43 -0700

The :N syntax uses database facilities for "binding" the parameter
values to the SQL statement, while the form you mention is simply
altering the SQL statement that gets sent to the database. There are
several benefits to using parameter binding:

1)	you don't need to worry about escaping string values
2)	certain types of values *can't* be specified in the SQL
statement (typically, LONG/BLOB/IMAGE.. whatever you want to call it)
3)	you can actually achieve higher efficiencies using parameter
binding. The standard sequence of operations with a database is: parse
the statement, bind parameters, execute the statement, fetch the
results. With parameter binding, you can fill in values to the bound
memory and re-execute the statement (skipping the parse/bind steps). By
altering the SQL string, you have to go through all the steps again. The
parse step is surprisingly expensive!

You will see the use of "?" in some database interfaces rather than the
:N syntax (which comes from Oracle, actually). The :N variety was chosen
because binding positionally is quite handy in a variety of contexts.

I hope that clears things up!


	-----Original Message-----
	From:	Daniel Larsson
	Sent:	Thursday, April 17, 1997 1:17 PM
	To:	python-list@cwi.nl
	Subject:	Re: Looking for examples of oracledb usage

	 Anthony Baxter wrote in article
	>something like
	>curs.execute("select * from db where blah = :1 and foo =
	>works for me.

	In general, how does this differ from using the standard string

	curs.execute("select * from db where blah = %d and foo = %d" %
(123, 456))

	(I assume these examples are equivalent, but I'm asking for the

	>>>> Roy Smith wrote
	>> I'm looking for example of python code that uses the oracledb
	>> I've got simple stuff working, but havn't yet figured out how
to do
	>> variable binding in an execute call.  The documentation says,
	>> are specified in a database-specific notation that is based
on the
	>> in the parameter tuple (position-based rather than
name-based)", but
	>> not quite sure what all that means.

DB-SIG  - SIG on Tabular Databases in Python

send messages to: db-sig@python.org
administrivia to: db-sig-request@python.org