rawSQL
(plugins.rawSQL)
Overview
The rawSQL plugin allows developers to execute raw SQL commands and manage advanced database interactions within Servoy. It is intended for scenarios where built-in APIs are insufficient and should be used cautiously to avoid data integrity or performance issues. This plugin supports SQL execution, stored procedure handling, cache management, and data change notifications.
Developers can use executeSQL to run custom SQL queries or updates, and executeStoredProcedure to call stored procedures with input and output arguments. The flushAllClientsCache function ensures that database changes are propagated across clients, while notifyDataChange informs clients of record updates or deletions based on primary keys. Additionally, getException provides detailed error information for debugging failed operations.
Careful usage of this plugin enables powerful database operations while maintaining system stability.
Properties
servoy.rawSQL.allowClientCacheFlushes
In case of performance problem you might want to disable this (true/false)
Methods Summarized
Execute any SQL asynchronously with prepared statement parameters.
Execute a stored procedure, return all created result sets.
Execute a stored procedure.
Execute a stored procedure asynchronously without explicit direction types.
Execute a stored procedure asynchronously with specified parameter directions and types.
If the result from a function was false, it will return the exception object.
Notify clients about changes in records, based on pk(s).
Methods Detailed
executeSQL(serverName, sql)
Execute any SQL, returns true if successful.
Parameters
Returns: Boolean True if the SQL execution was successful; false otherwise.
Sample
executeSQL(serverName, sql, sql_args)
Execute any SQL, returns true if successful.
Parameters
String serverName the name of the server
String sql the sql query to execute
Array sql_args the arguments for the query
Returns: Boolean True if the SQL execution was successful; false otherwise.
Sample
executeSQLAsync(serverName, sql)
Execute any SQL asynchronously. Returns a Promise object that resolves to a Boolean indicating whether the SQL executed successfully, or rejects with an error message if it fails.
Example using the <em>example_data.employees</em> datasource:
Parameters
String serverName the logical DB server name (e.g.
example_data)String sql the SQL statement to execute
Returns: Promise a Promise resolving to true on success or false on a non-exceptional failure
executeSQLAsync(serverName, sql, sql_args)
Execute any SQL asynchronously with prepared statement parameters. Returns a Promise object that resolves to a Boolean indicating success, or rejects with an error message if an exception occurs.
Example inserting a new employee:
Parameters
String serverName the logical DB server name (e.g.
example_data)String sql the SQL statement with placeholders
Array sql_args the array of parameter values
Returns: Promise a Promise resolving to true on success or false on a non-exceptional failure
executeStoredProcedure(serverName, procedureDeclaration, arguments, maxNumberOfRowsToRetrieve)
Execute a stored procedure, return all created result sets.
Parameters
Returns: Array the result sets created by the procedure.
Sample
executeStoredProcedure(serverName, procedureDeclaration, arguments, inOutDirectionality, maxNumberOfRowsToRetrieve)
Execute a stored procedure.
Parameters
String serverName ;
String procedureDeclaration ;
Array arguments ;
Array inOutDirectionality ;
Number maxNumberOfRowsToRetrieve ;
Returns: JSDataSet a dataset with output (in case of output data) or the last result set executed by the procedure.
Sample
executeStoredProcedureAsync(serverName, procDecl, args, maxRows)
Execute a stored procedure asynchronously without explicit direction types. Returns a Promise object that resolves to an array of JSDataSet containing all result sets, or rejects with an error message on failure.
Example listing employees in a department:
Parameters
String serverName the logical DB server name (e.g.
example_data)String procDecl the JDBC stored procedure declaration
Array args the array of procedure arguments
Number maxRows the maximum number of rows to retrieve for a SELECT inside the procedure
Returns: Promise a Promise resolving to an array of JSDataSet on success
executeStoredProcedureAsync(serverName, procDecl, args, inOutTypes, maxRows)
Execute a stored procedure asynchronously with specified parameter directions and types. Returns a Promise object that resolves to a JSDataSet containing the result set, or rejects with an error message on failure.
Example calculating age from birth year:
Parameters
String serverName the logical DB server name (e.g.
example_data)String procDecl the JDBC stored procedure call string
Array args the array of input/output parameter values
Array inOutTypes the SQL Types for input/output parameters
Number maxRows the maximum number of rows to fetch from a SELECT inside the procedure
Returns: Promise a Promise resolving to a JSDataSet on success
flushAllClientsCache(serverName, tableName)
Flush cached database data. Use with extreme care, its affecting the performance of clients! This method will take into account tenants, just like databroadcast from user interface.
Parameters
Returns: Boolean True if the cache was successfully flushed; false otherwise.
Sample
getException()
If the result from a function was false, it will return the exception object.
Returns: Exception The exception object if the result from a function was false, or null if no exception occurred.
Sample
notifyDataChange(serverName, tableName, pksDataset, action)
Notify clients about changes in records, based on pk(s). Use with extreme care, its affecting the performance of clients! This method will take into account tenants, just like databroadcast from user interface.
Parameters
Returns: Boolean True if the data change notification was successfully sent; false otherwise.
Sample
Last updated
Was this helpful?