Embedded SQL in Python

Jonsm (jonsm@aol.com)
3 Mar 1995 21:24:34 -0500

Has any work been done with allowing embedded SQL in Python scripts? An
example embedded SQL statement looks like:
SELECT name INTO :my_name FROM segments WHERE segment =
:my_segment ;
This statement reads from database table 'segments' and selects the column
'name' into the local variable 'my_name'. The WHERE restriction is
determined at run-time from the my_segment variable. The variables with
the colon in front of them are local Python variables which receive the
input/output from the SQL statement.

There are three main means for integrating SQL into a language: direct,
embedded support like Powerbuilder (this is nice), indirect embedded
support through a pre-processor, or database API support . The downside to
API support is that it takes about 30 lines of tedious C code to equal
each line of embedded SQL. One of my apps has a 1000 lines of embedded SQL
which would expand to 30K lines of C.

It would be real nice to see embedded SQL syntax supported directly in
Python. The Python interpreter would then convert the embedded SQL into
calls to a database API library along the lines of ODBC. All of the issues
of variable type conversion and binding would be handled by the
interpreter.

Jon Smirl, jonsm@aol.com