HomeWiki
HomeWiki
  1. DB
  • Back to home
  • 2. Connectivity
  • Introduction
  • Custom Script
  • Playground
  • Database Explorer
  • Log Stream
  • Direct Communication
  • Softone
    • Getting Started
  • Datapump
    • Getting Started
    • Crons
    • Legacy Windows Support
    • SDK
      • DB
        • _executeQuery
        • _executeStoreProcedure
        • _executeInsertQuery
        • _executeInsertQueriesInTransaction
      • Import
        • _productsImport
        • _categoriesImport
        • _brandsImport
        • _attributesImport
        • _attributeSetsImport
        • _unitsImport
        • _quantityImport
        • _customersImport
        • _contactsImport
        • _callsImport
        • _eventsImport
        • _tasksImport
        • _ordersImport
        • _usersImport
        • _customerSourceTagsImport
        • _productSourceTagsImport
      • Log
        • _logDebug
        • _logInfo
        • _logWarn
        • _logError
      • Web Requests
        • _httpGetJson
        • _httpPostJson
        • _httpPutJson
        • _httpDeleteJson
        • _httpPatchJson
      • Variables
        • _saveVariable
        • _getVariable
        • _deleteVariable
      • Blob
        • _blobConnect
        • _blobExists
        • _blobGet
        • _blobFind
      • Utils
        • _encodeBase64
        • _sleep
        • _getLastSyncDate
        • _updateLastSyncDate
        • _resetLastSyncDate
  1. DB

_executeStoreProcedure

Usage Documentation: _executeStoreProcedure JavaScript Function#

The _executeStoreProcedure function allows you to execute a stored procedure in a SQL Server database from within your JavaScript code. This function is useful when you need to invoke a predefined set of SQL operations encapsulated within a stored procedure, such as complex queries or database transactions.

Function Signature:#

Parameters:#

1.
spName (string):
Description: The name of the stored procedure that you want to execute in the SQL Server database.
Type: string
Example: "GetCustomerDetails"
2.
params (object):
Description: An object representing the parameters to pass to the stored procedure. The keys in the object represent the parameter names, and the values represent the corresponding parameter values.
Type: object
Example:

Return Value:#

Returns: A JSON-encoded string containing the result set from the stored procedure execution. Each row returned by the stored procedure is represented as an object within a JSON array, with the column names as keys and their corresponding values as the object values.

Example Usage:#

Detailed Explanation:#

1.
Stored Procedure Name (spName):
This is the name of the stored procedure in your SQL Server database. Make sure that the stored procedure exists and that you have the correct name.
2.
Parameters (params):
This is an object containing key-value pairs where the keys are the names of the parameters in the stored procedure, and the values are the values to pass to those parameters.
Ensure that the parameter names exactly match the names expected by the stored procedure, including any @ symbols.
3.
Executing the Stored Procedure:
When you call _executeStoreProcedure, the function will connect to your database, execute the specified stored procedure with the provided parameters, and return the result set as a JSON-encoded string.
4.
Handling the Result:
After executing the stored procedure, the function returns the result as a JSON string. You can parse this string using JSON.parse() to convert it into a JavaScript object or array for further manipulation.

Use Cases:#

Data Retrieval: Use this function to retrieve data from the database, such as fetching customer details, order history, or any other data stored in your database.
Complex Database Operations: When your application needs to perform complex database operations that are encapsulated in a stored procedure, such as inserting, updating, or deleting data, you can use _executeStoreProcedure to handle these operations.
Transactional Operations: If your stored procedure handles transactions (e.g., commits or rollbacks), this function can be used to trigger those transactions safely from your application.

Important Considerations:#

Error Handling: Ensure that you handle potential errors in your stored procedures. If the stored procedure encounters an error, you should catch and manage the error in your JavaScript code.
SQL Injection: By using parameters in the params object, you reduce the risk of SQL injection attacks. Always validate and sanitize input data before passing it to the stored procedure.
This function provides a powerful way to interact with your database using stored procedures, enabling you to execute complex SQL logic directly from your JavaScript code.
Previous
_executeQuery
Next
_executeInsertQuery
Built with