Function documentationConverting Date and Time Values Locate this document in the navigation structure

 

The sdb.dbapi module implements the functions that the Python Database API Specification v2.0 recommends for date and time conversions.

Features

Converting Python Values -> SAP MaxDB Values

Function

Return Value (SAP MaxDB Data Type)

Date (year, month, day)

DATE

Time (hour, minute, second)

TIME

Timestamp (year, month, day, hour, minute, second, micros = 0)

TIMESTAMP

DateFromTicks (ticks)

DATE

TimeFromTicks (ticks)

TIME

TimestampFromTicks (ticks)

TIMESTAMP

Converting SAP MaxDB Values -> Python Values

Function

Return Value (Python Data Type)

dateTuple

(year, month, day)

timeTuple

(hour, minute, second)

timestampTuple

Tuple in the same format as the return value for time.localtime ()

dateVal

Number of seconds since epoch

timeVal

Number of seconds since epoch

timestampVal

Number of seconds since epoch

DateFormat (formatString)

Date formatted according to time.strftime

TimeFormat (formatString)

Time formatted according to time.strftime

TimestampFormat (formatString)

Time stamp formatted according to time.strftime

Registering Conversion Functions Using Cursors or Connection Objects

Callable Object

Description

cursor.setTranslation ([None,sdb.dbapi.dateTuple,sdb.dbapi.DateFormat('%Y-%m-%d')])

You transfer a list in which you specify a function for data conversion for every column. If no data conversion is to be performed for a column, transfer the None object at the position of the column in question.

cursor.setTypeTranslation ({'Date': sdb.dbapi.dateTuple,'Time': sdb.dbapi.timeTuple,'Fixed':str})

You transfer a dictionary. Enter the same type name as a key, as is issued by the sdb.sql.SapDB_ResultSet.getDescription method.

As values, enter the functions for data conversion. The system uses these functions for all columns of a certain SQL data type.

connection.setTypeTranslation ({Date': sdb.dbapi.dateTuple,'Time': sdb.dbapi.timeTuple,'Fixed':str})

You transfer a dictionary that has the same structure as the parameter for cursor.setTypeTranslation. For each new cursor object, call the setTypeTranslation method with the dictionary as the parameter.

More Information

http://www.python.org