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

_executeQuery

Documentation: Usage of _executeQuery Function#

Overview:#

The _executeQuery function allows you to execute a SQL query directly from your JavaScript code. The function sends the query to the database and returns the result set as a JSON-encoded string. This function is particularly useful for retrieving data from a database within your on-premise environment.

Function Signature:#

Parameters:#

query: A string representing the SQL query that you want to execute. This must be a valid SQL statement (e.g., SELECT, UPDATE, INSERT, etc.). The query should not be empty or null.

Return Value:#

string: The function returns a JSON-encoded string containing the result set of the executed query. Each row from the result set is converted into a JSON object, with the column names as keys and their corresponding values as the object values.

Error Handling:#

Ensure that the query parameter is a valid and properly formatted SQL statement. If the query is invalid or empty, the function may not execute correctly, and you will need to handle errors in your JavaScript code.

Example Usage:#

1. Basic Example: Fetching Data#

This example demonstrates how to use _executeQuery to fetch data from a database.

2. Error Handling Example: Handling Invalid Queries#

It's essential to handle cases where the query might be invalid.

Best Practices:#

Always validate your SQL queries before passing them to _executeQuery to avoid errors.
Parse the JSON response using JSON.parse() to convert the JSON string into JavaScript objects for further manipulation.
This documentation should help you effectively use the _executeQuery function in your JavaScript code to interact with your database and handle the results.
Previous
Legacy Windows Support
Next
_executeStoreProcedure
Built with