• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • CSPro Statements and Functions
    • Templated Reporting System
    • HTML and JavaScript Integration
    • Action Invoker
      • Overview
      • Execution Environments
      • Security and Formatting Options
      • Base Actions
      • Application Namespace
      • Clipboard Namespace
      • Data Namespace
      • Dictionary Namespace
      • File Namespace
      • Hash Namespace
      • Localhost Namespace
      • Logic Namespace
      • Message Namespace
      • Path Namespace
      • Settings Namespace
      • Sqlite Namespace
        • Sqlite Action Invoker Namespace
        • Sqlite.close Action
        • Sqlite.exec Action
        • Sqlite.open Action
        • Sqlite.rekey Action
        • SQLite Callback Functions
        • Sqlite Action Examples: Data Sources
        • Sqlite Action Examples: Paradata
      • System Namespace
      • UI Namespace
    • Appendix
  • <CSEntry>
  • <CSBatch>
  • <CSTab>
  • <DataViewer>
  • <TextView>
  • <TblView>
  • <CSFreq>
  • <CSDeploy>
  • <CSPack>
  • <CSDiff>
  • <CSConcat>
  • <Excel2CSPro>
  • <CSExport>
  • <CSIndex>
  • <CSReFmt>
  • <CSSort>
  • <ParadataConcat>
  • <ParadataViewer>
  • <CSCode>
  • <CSDocument>
  • <CSView>
  • <CSWeb>

SQLite Callback Functions

When executing a query on a SQLite database using the Sqlite.exec action or the sqlquery function, it is possible, from SQLite, to call back into CSPro to execute some logic functions or user-defined functions.
Calling CSPro Logic Functions
The following CSPro logic functions are available for use in SQL queries:
Logic Function NameSQLite Function Name
timestringcspro_timestring
For example, this SQL query would return a formatted string containing the date and time of the first CSPro release using the timestring logic function:
SELECT cspro_timestring("%c", 957528000);
Calling User-Defined Functions
When defining a user-defined function, adding the directive sql after the function keyword indicates that the SQL query can call back into CSPro logic. These functions can accept numeric or string arguments as part of the query, and can return values of those types.
For example, this function is marked with sql:
function sql string SumNumbers(numeric value1, numeric value2)
   
exit maketext("The sum of %v and %v is %v.", value1, value2, value1 + value2);
end;
This function can then be called as part of a SQL query:
-- result: The sum of 12.1 and 4.2 is 16.3.
SELECT SumNumbers(12.1, 4.2);
See also: Sqlite Action Invoker Namespace, Sqlite.exec Action, sqlquery Function