Additional Information for Python
This section covers these topics:
Type Mappings for Python Applications
There are mappings between python-oracledb types (as available through the language extension module) and TimesTen SQL types.
Table 3-1 documents mappings between python-oracledb types (as available through the language extension module) and TimesTen SQL types.
Note:
Additional TimesTen SQL types can be mapped to these python-oracledb types as a result of TimesTen implicit data type conversions. See Data Type Conversion in Oracle TimesTen In-Memory Database SQL Reference.
For the latest information about data type support in the current release, refer to
the README.md
file at TimesTen Python Samples.
Table 3-1 Type Mappings for python-oracledb
python-oracledb Type | TimesTen Type |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Failure Modes for Python
There are several failure modes for Python.
Be aware of the following:
-
Error messages may differ slightly from those produced by Oracle under the same conditions.
-
For the Python method
Cursor.executemany()
, TimesTen ignores thebatcherrors
option and therefore supports only the defaultbatcherrors=false
setting. An error is always returned if any row in the batch encounters an error. (By contrast, Oracle Database supportsbatcherrors=true
, in which case success is always returned if any row in the batch is successful.) Also, against a TimesTen database, if multiple errors are encountered in a batch, TimesTen makes no attempt to order the errors as they would be ordered if encountered against an Oracle database.
Python Sample: Connect to TimesTen and Execute SQL
This sample program does the following:
-
Connects to a TimesTen database.
-
Creates a table named
employees
. -
Inserts three rows into the table.
-
Selects and displays the rows.
-
Drops the table.
-
Disconnects from the database.
import oracledb
def run():
try:
oracledb.init_oracle_client();
connection = oracledb.connect(
user='appuser',
password='password',
dsn='localhost/sampledb:timesten_direct')
cursor = connection.cursor()
cursor.execute('''
CREATE TABLE employees(first_name VARCHAR2(20), last_name VARCHAR2(20))''')
print('Table created')
values = [['ROBERT', 'ROBERTSON'], ['ANDY', 'ANDREWS'], ['MICHAEL', 'MICHAELSON']]
cursor.executemany('INSERT INTO employees VALUES (:1, :2)', values)
print('Inserted', len(values), 'employees into the table')
cursor.execute('''
SELECT first_name, last_name FROM employees''')
for fname, lname in cursor:
print('Selected employee:', fname, lname)
cursor.execute('DROP TABLE employees')
print('Table dropped')
cursor.close()
connection.close()
print('Connection closed')
except Exception as e:
print('An error occurred', str(e))
run()
Running this sample program to connect to a TimesTen database should return the following output:
Table created
Inserted 3 employees into the table
Selected employee: ROBERT ROBERTSON
Selected employee: ANDY ANDREWS
Selected employee: MICHAEL MICHAELSON
Table dropped
Connection closed
See Task 4: Configure Connections for TimesTen for information on the Easy Connect method used to connect to the database in the sample program.