ProcessMIX Guide
  • Platform Overview
    • Introduction
    • Platform Purpose
    • Main Concepts
      • Organization Structure
      • Visual Language
      • Project Development Environment (IDE)
      • Deployment and Integration
      • Administration and Troubleshooting
    • First Steps
    • Change Log
      • 5.0.0
      • 5.0.5
      • 5.0.5.1
      • 5.0.5.2
      • 5.0.5.3
      • 5.0.5.4
  • Language Reference Guide
    • Overview
    • Data Structures and Types
      • Core Types (pdk.core)
      • Dictionary (pdk.asset.dictionary)
      • Scorecard (pdk.asset.scorecard)
      • Blockchain (pdk.blockchain)
      • Exceptions (pdk.ex)
      • Input/Output (pdk.io)
      • JSON Web Token (pdk.jwt)
      • Networking (pdk.net)
      • HTTP (pdk.net.http)
      • SOAP/Web Services (pdk.net.soap)
      • XML/DOM (pdk.net.xml)
      • S3 (pdk.s3)
      • SQL (pdk.sql)
      • Postgres (pdk.db.postgre)
      • Util (pdk.util)
      • Default Data Structure Field Values
    • Flows
      • Variables
        • Local Flow Variables
        • Node Variables
      • Flow Node Types
        • Core Nodes
          • In
          • Out
          • Assign
          • If
          • Switch
          • Iterator
          • Function Call
          • Subflow
          • Raise Exception
          • Exception Handler
          • Validator
        • Connector Nodes
          • Database Begin Transaction
          • Database Commit Transaction
          • Database Rollback Transaction
          • Database Query Executor
          • EVM Blockchain Functions
          • EVM Blockchain Smart Contract Functions
          • REST Service Executor
          • SOAP Service Executor
          • S3 Connector
          • SMB Connector
      • Expressions
      • Built-In Functions
        • Expression functions
          • pdk.util.Any
          • pdk.util.Array
          • pdk.util.Blockchain
          • pdk.util.Cast
          • pdk.util.Codec
          • pdk.util.Crypto
          • pdk.util.Date
          • pdk.util.File
          • pdk.util.Json
          • pdk.util.JWT
          • pdk.util.Map
          • pdk.util.Math
          • pdk.util.String
          • pdk.util.Util
        • Node functions
          • pdk.flow.Any
          • pdk.flow.Array
          • pdk.flow.File
          • pdk.flow.JsonArray
          • pdk.flow.JsonObject
          • pdk.flow.HttpRequest
          • pdk.flow.HttpResponse
          • pdk.flow.Logger
          • pdk.flow.Map
          • pdk.flow.Xml
            • pdk.flow.xml.XmlAttr
            • pdk.flow.xml.XmlElement
            • pdk.flow.xml.XmlNode
            • pdk.flow.xml.XmlDocument
            • pdk.flow.xml.XmlDocumentType
            • pdk.flow.xml.XmlDOMConfiguration
            • pdk.flow.xml.XmlDOMImplementation
            • pdk.flow.xml.XmlProcessingInstruction
            • pdk.flow.xml.XmlTypeInfo
            • pdk.flow.xml.XmlCharacterData
            • pdk.flow.xml.XmlText
            • pdk.flow.xml.XmlNamedNodeMap
          • pdk.node.BlockchainEth
          • pdk.node.S3
          • pdk.node.Smb
      • Exceptions
        • Checked Exceptions
        • Runtime Exceptions
    • Assets
      • Dictionary
      • Decision Table
      • Scorecard
      • PMML
    • Connectors
      • DB Connector
        • Prepared Query
        • Dynamic Query
        • Query input parameters
        • Stored Procedure
      • REST Connector
      • SOAP Connector
      • S3 Connector
      • SMB Connector
      • EVM Blockchain Connector
    • Global Variables
    • Appendices
      • Overview of Database Transactions
      • Reserved Words
  • Project Development Environment (IDE)
    • Project Explorer Panel
    • Flow Builder
    • Flow Node Editor
    • Data Structure Builder
    • Connector Builders
      • REST Connector Builder
      • SOAP Connector Builder
      • DB (Database) Connector Builder
      • EVM Blockchain Connectors Builder
      • S3 Connector Builder
    • Asset Builders
      • Dictionary Builder
      • Decision Table Builder
      • Scorecard Builder
      • PMML Asset Builder
    • Global Variables Panel
    • Expression Editor
    • Project Deployment and Execution
    • Cron Expression Generator
    • Test Helper
    • Debugging the Project
    • DB transactions
    • Team Collaboration Tools
      • Version Control
      • Conflict Resolver
    • Selectors
    • Error Panel
    • Local History
  • Home and Administration Guide
    • Organization and Subscription
    • Organization Team
    • Repositories and Projects
    • Environments
    • Deployments
    • Database Provisioning
    • Roles and Permissions
  • Logs and Troubleshooting
    • Request/Call Logs
    • Deployment Logs
    • Application Logs
  • Appendix: Example Project
    • Risk Mitigation Solution
Powered by GitBook
On this page
  • SQL
  • Input Parameters
  1. Language Reference Guide
  2. Connectors
  3. DB Connector

Dynamic Query

PreviousPrepared QueryNextQuery input parameters

Last updated 4 months ago

Dynamic query allows the creation of SQL queries on the fly, enabling flexibility in constructing complex queries based on changing criteria, user input, or business logic. This can involve adding or removing conditions, altering select columns, or changing table names.

The advantages of dynamic queries include flexibility, as they allow applications to adapt to changing requirements, user preferences, or evolving data conditions. However, they may also introduce risks like SQL injection if not handled securely. Therefore, precautions are essential to ensure the safety and reliability of dynamically generated queries in applications.

Dynamic queries assist in resolving functionalities, such as creating a REST service for a UI table. Such a service needs to provide the possibility of using a variable number of options for ordering.

select * from "orders" 
    where "createdAt" >= '01-01-2020' and "createdAt" < '01-01-2024'
    order by "name" desc, "createdAt" asc, "type" desc
        limit 20 offset 10

SQL

SQL should be defined and configured at runtime. The best scenario is to use flow local variable.

Placeholders for variables should be enclosed by curly brackets.

ordersQuery :: String = 'select * from "orders"' //FLOW local variable

supplierId - input parameter

1. Add WHERE clause
dateFrom :: String = '01-01-2020' //FLOW local variable
dateTo :: String = '01-01-2024' //FLOW local variable

ordersQuery = ordersQuery +
    ' where "supplierId" = {supplierId} 
        and "createdAt" >= ' + dateFrom + 
      ' and "createdAt" < ' + dateTo

2. Add ORDER BY 
nameOrderType :: String = 'desc' //FLOW local variable
createdAtOrderType :: String = 'asc' //FLOW local variable
typeOrderType :: String = 'desc' //FLOW local variable

ordersQuery = ordersQuery +
    ' order by "name" ' + nameOrderType +
    ' order by "createdAt" ' + createdAtOrderType +
    ' order by "type" ' + typeOrderType
    
3. Add LIMIT and OFFSET
limitValue :: Integer = 20
offsetValue :: Integer = 10 

ordersQuery = ordersQuery + 
    ' limit ' + limitValue + ' offset ' + offsetValue

Input Parameters

All input parameters are optional. System maps provided values into placeholders defined in the sql query string.

The parameter name is indicated by the text enclosed within curly brackets { }. The name should consist only of letters, digits, and underscore characters, , and must start with a letter.

ordersQuery :: String = 'select * from "orders"' //FLOW local variable

1. Add WHERE clause
ordersQuery = ordersQuery +
    ' where "createdAt" >= {dataFrom} and "createdAt" < {dataTo}'
    
dataFrom, dataTo - variables that will be defined during flow execution

All detailed information on the .

Query Input Parameters page
pdk.core.String