Skip to content

Validation Engine

Shashank Patil edited this page Jul 26, 2026 · 1 revision

Validation Engine

The Generic SQL API Framework includes a built-in validation engine that verifies every request before executing a SQL query. This helps prevent invalid requests, improve reliability, and reduce runtime errors.


Validation Flow

Every request follows this validation process:

Client Request
      │
      ▼
JSON Validation
      │
      ▼
Query Validation
      │
      ▼
Parameter Validation
      │
      ▼
Security Checks
      │
      ▼
Execute SQL
      │
      ▼
Return Response

Request Validation

The framework first validates the incoming JSON request.

Example:

{
    "query": "customers"
}

Checks performed:

  • Request is valid JSON
  • Required properties exist
  • Property names are valid
  • Request is not empty

Query Validation

The framework verifies that the requested SQL file exists.

Example:

{
    "query": "customers"
}

The framework checks:

queries/customers.sql

If the file does not exist:

{
    "success": false,
    "message": "Query file not found."
}

Parameter Validation

Parameterized queries require matching input values.

SQL:

SELECT *
FROM CustomerTable
WHERE CustomerID = :CustomerID;

JSON:

{
    "query": "customer_by_id",
    "parameters": {
        "CustomerID": 101
    }
}

If a required parameter is missing:

{
    "success": false,
    "message": "Missing required parameter: CustomerID"
}

Data Type Validation

The framework validates parameter types before execution.

Example:

{
    "parameters": {
        "CustomerID": "ABC"
    }
}

If the query expects an integer, validation fails.


Pagination Validation

The framework validates pagination values.

Example:

{
    "pagination": {
        "page": 1,
        "pageSize": 50
    }
}

Validation rules:

  • Page must be greater than 0
  • Page size must be greater than 0
  • Maximum page size depends on framework configuration

Sorting Validation

Example:

{
    "sorting": {
        "column": "CustomerName",
        "direction": "ASC"
    }
}

Checks:

  • Column exists
  • Direction is either ASC or DESC

Filter Validation

Example:

{
    "filters": {
        "City": "Bangalore"
    }
}

Validation includes:

  • Allowed filter fields
  • Supported operators
  • Valid values

Security Validation

Before executing SQL, the framework performs security checks such as:

  • Preventing SQL injection through parameterized queries
  • Rejecting invalid or malformed requests
  • Restricting execution to registered SQL files

Validation Response

Successful validation:

{
    "success": true
}

Validation error:

{
    "success": false,
    "message": "Validation failed."
}

Best Practices

  • Always use parameterized queries.
  • Validate user input before sending requests.
  • Use meaningful parameter names.
  • Keep SQL queries simple and maintainable.
  • Test validation scenarios during development.

Next Steps

Now that you understand request validation, continue with:

  • Query Examples
  • Response Format
  • Error Handling
  • Framework Architecture

Clone this wiki locally