 
 |
You Are Here: SAP DB > 7.3 > Interfaces > Python DB API
Module sapdbapi (Python DB API 2.0)
General Information
Connect Syntax
Data Conversion
LONG Handling
General Information
Version: 7.3.0
Compatible with SAP DB Version: 7.*.*
Author: SAP AG, http://www.sapdb.org/
Bug Reports to: sapdb.general@listserv.sap.com
Implements: The Python DB API 2.0
Connect Syntax
connect (user, password, database,
host = '', **config)
| Parameter |
Notes |
user |
Parameter is case sensitive. |
config |
May contain the following keyword parameters:
autocommit |
Possible values:
on and off . |
sqlmode |
Possible values:
internal (default value) and oracle
In ORACLE mode, the SQL dialect is compatible with ORACLE 7. |
isolation |
Specify the isolation level as an integer.
For more details please see SQL Reference => Transactions => CONNECT statement. |
timeout |
Specify the command timeout in seconds.
For more details please see SQL Reference => Transactions => CONNECT statement. |
|
Data Conversion
sapdbapi implements the recommended functions to convert Python values into the SAP DB internal format.
- Date (year, month, day)
- Time (hour, minute, second)
- Timestamp (year, month, day, hour, minute, second, micros = 0)
- DateFromTicks (ticks)
- TimeFromTicks (ticks)
- TimestampFromTicks (ticks)
Furthermore, sapdbapi exports callable objects to translate SAP DB
internal values to Python values:
dateTuple: Returns the tuple (year, month, day)
timeTuple: Returns the tuple (hour, minute, second)
timestampTuple: Returns a tuple in the same format as time.localtime ()
dateVal: Returns the no. of seconds since epoch
timeVal: Returns the no. of seconds since epoch
timestampVal: Returns the no. of seconds since epoch
DateFormat (formatString): Returns date formatted by using time.strftime
TimeFormat (formatString): Returns time formatted by time.strftime
TimestampFormat (formatString): Returns timestamp formatted by time.strftime
The following callable objects can be registered with a Cursor object or with a Connection object.
Please note that only newly created objects will use this translation.
- Registering with a Cursor by position:
cursor.setTranslation ([
None,
sapdbapi.dateTuple,
sapdbapi.DateFormat('%Y-%m-%d')])
- Registering with a Cursor by type:
cursor.setTypeTranslation ({
'Date': sapdbapi.dateTuple,
'Time': sapdbapi.timeTuple,
'Fixed': str})
- Registering with a Connection by type:
connection.setTypeTranslation ({
'Date': sapdbapi.dateTuple,
'Time': sapdbapi.timeTuple,
'Fixed': str})
LONG Handling
Output: LONG columns are returned as instances of
SapDB_LongReader. This class
implements the read () method similar to a file stream.
Input: LONG parameters can be written by using a string or by using a callable
object similar to file.read.
|
|
|