sql_run Interface

interface

Tokenise one source line. Always succeeds for well-formed tokens; reports SQR_INVALID with errmsg (carrying the offending column) for an unterminated string or a stray character. toks(1:ntok) are the tokens; a trailing TK_EOF is not appended (callers use ntok). Parse one statement. Recursive descent into sql_stmt_t. A trailing ; is permitted. Reports SQR_INVALID with a column-anchored errmsg on a syntax error. Execute one parsed statement against an open database, choosing an index-driven or scan-driven plan as appropriate, and fill res. Engine errors propagate through stat/errmsg. db is target because the transaction façade the executor calls needs it. Convenience: lex + parse + execute one source line. Equivalent to sql_parse then sql_exec. Render a result to a formatted unit: an aligned table for a SELECT, a "N row(s)" line for DML, or the message for DDL. Used by the REPL; tests inspect sql_result_t directly instead.


public module subroutine sql_run(db, text, res, stat, errmsg)

Arguments

Type IntentOptional Attributes Name
type(db_t), intent(inout), target :: db

Open database handle

character(len=*), intent(in) :: text

Source line

type(sql_result_t), intent(out) :: res

Execution result

integer, intent(out), optional :: stat

SQR_OK or an error code

character(len=*), intent(inout), optional :: errmsg

Failure detail