The sql module provides helper functions for working with the database directly.

Functions

FunctionParametersReturn ValueDescription
convert_date_to_planta_time(date, date_format=%d.%m.%Y)date: String containing a date

date_format: A valid date format string
The date converted to amount of days since 01.01.1970Converts a readable date into the format used by PLANTA date fields
convert_planta_time_to_date(planta_time, date_format=%d.%m.%Y)planta_time: Days since 01.01.1970

date_format: A valid date format string
A readable date as defined by the formatConverts the PLANTA internal date format to a readable string
get_sql_date_format(planta_time)planta_time: Days since 01.01.1970Returns a string to be used in an sql statementConverts the days since 01.01.1970 to a proper date string and then adds the dbms related code to make it valid sql
sanitize_value(value)value: A value you want to insert into a SQL statementA sanitized version of the valueSanitizes a string that will later be formatted into an sql statement. Useful for preventing SQL injections or putting UUID objects into a statement

Examples

Converting a planta time to a date string

from ppms.sql import convert_planta_time_to_date
from ppms.constants import SYS_VAR_TODAY

today = ppms.uvar_get(SYS_VAR_TODAY)
today_as_date_string = convert_planta_time_to_date(planta_time=today)

ppms.ui_message_box('Today is {}'.format(today_as_date_string))
PY