Skip to main content

ExecSQLData

function ExecSQLData(const aDataSet: TvxClientDataSet;
const aSQL: string): boolean;

Example

procedure ScriptEvent(var Value: variant);
begin
if ExecSQLData(Data,
'select ItemID, Status from ExampleQueue where Status = ''Ready''') then
Value := Data.RecordCount
else
Value := Null;
end;

Usage

ExecSQLData rebinds a client dataset to the Velox Data connection and opens the supplied SQL in a transaction.

Parameters

NameTypeDescription
aDataSetTvxClientDataSet, const referenceExisting mutable client dataset to close, clear, rebind and open. const prevents reassignment of the reference; it does not make the object immutable.
aSQLstring, constSQL expected to return a cursor on the Velox Data connection. Parameter recognition is disabled.

Returns

True after aDataSet.Active := True succeeds; False after a caught exception. Success means the cursor opened, not that any transaction committed or any rows exist.

Errors

All exceptions are logged and suppressed into False. There is no explicit close or rollback in the handler, so the dataset and transaction can retain the state reached before failure. Inspect aDataSet.Active and the Velox log before deciding how to recover.

Security and data safety

With ParamCheck := False, values embedded in SQL are not parameterised. Avoid concatenating untrusted data and remember that the exact SQL is logged. Use bounded queries where possible because opening a large cursor can consume memory and hold locks.

Additional Technical Info

Despite its name, ExecSQLData does not call the non-query ExecSQL operation. It destructively rebinds a supplied client dataset to the Velox Data (SQLD) connection, starts or joins a transaction, and opens the SQL as a result dataset.

The dataset and SQL are fictional. The example is source-reviewed and was not executed.

Implementation

The method closes aDataSet, sets SQLDataSet.ParamCheck := False, clears FieldDefs, assigns gSystemConnection.SQLD, starts or reuses its Velox transaction, sets SQLDataSet.CommandText, logs the statement and sets Active := True.

Setting Active opens a dataset. It is not equivalent to Delphi TSQLQuery.ExecSQL for update/insert/delete statements. Use ExecSQL for a non-query SQL command.

Side effects

The caller's prior cursor, field definitions, SQL connection, command and edit state are discarded. The opened cursor remains attached to the shared SQLD connection. The method may also start a transaction and logs the full SQL text.

Performance and concurrency

Opening is synchronous. Row fetching behaviour depends on the underlying client dataset and driver; RecordCount can require additional work. The live dataset and connection are mutable execution-context objects and are not safe for concurrent rebinding.

Related entries

  • GetData opens SQLD without explicitly starting a transaction in this wrapper.
  • ExecSQL runs non-query SQL and leaves completion to the flow.
  • Datasets covers cursor and object-lifetime rules.

External references

Created 2026-07-15