Skip to content
OCTAVIIUS DOCSCore & Studio 0.2.83
Integrations / 0.2.83

Protocol 4: scripts and multiple results

Result events, procedures, IN/OUT parameters, parameter arrays and system catalog.

Result boundaries and completion

A protocol 4 call can produce multiple result sets, messages and counts. Consumers preserve result_set_id boundaries and apply each set’s own metadata. result_set_complete ends a set; complete ends the call. Procedure output parameters and return status become final only at the latter boundary.

Events and completion

eventMeaning
resultRows from one result set, with result_set_id, columns and columns_meta.
row_countStatement without columns; odbc_row_count gives affected rows, or -1 for DDL.
messageInformation/PRINT, not a row set.
completeNormal global completion with final outputs and return_status.

result_set_complete:true ends only the current set; complete:true ends the whole call. Sequences span the cursor. Empty SELECTs still receive metadata and a set-end marker. Never mix rows from different result_set_id values, or confuse affected_rows, fetched row_count and packet counts. The same fetch/close routes and rules apply.

Structured procedure call

call and sql are mutually exclusive. Arguments have optional names, IN/OUT/INOUT directions, type, args and value. OUT starts NULL; INOUT supplies an initial value. The declaration must allow OUTPUT. Early close cancels the remaining call; it guarantees neither execution of every statement nor final outputs.

JSON
{"protocol_version":4,"database":"Atelier",
 "call":{"name":"dbo.Ajouter","arguments":[
  {"name":"entree","direction":"IN","type":"INT","value":3},
  {"name":"total","direction":"INOUT","type":"INT","value":2}
 ]},"batch_rows":8192,"batch_bytes":1048576}

Parameter arrays and bulk operations

Protocol 4 accepts parameter_sets for INSERT/UPDATE/DELETE: up to 10,000 sets within the global 2 MiB HTTP body. Names must exactly match parameters. on_error is stop or continue. processed_count counts attempted entries; parameter_status reports success/error/not_processed; affected_rows sums successful changes. Entries execute sequentially with per_statement atomicity.

An error, cancellation or transport loss may leave an already-written prefix. No automatic array replay, global rollback or incremental single-parameter streaming is offered. JSON/CSV ingestion and chunked file import are separate mechanisms, not implicit SQLPutData.

Catalog and management procedures

EXEC sys.sp_catalog @kind=@k,@object=@o returns a TEXT record column whose cells contain JSON strings; decode each cell with json.loads in Python. kind accepts types, databases, schemas, tables, columns, indexes, keys, procedures and procedure_columns. object filters canonical qualified names. Unauthorized objects are filtered; keys remains empty because key constraints do not exist.

Management procedures include sys.sp_users, sp_api_keys, sp_storage, sp_maintenance, sp_import, sp_ingest, sp_notebooks and sp_monitor. JSON payloads reuse existing operations and permissions; a dbo key gains no server administration. The downloadable contract provides detailed management formats.

JSON
{"protocol_version":4,"database":"Atelier",
 "sql":"EXEC sys.sp_catalog @kind=@k,@object=@o",
 "params":{"k":"columns","o":"dbo.ventes"}}

System procedure actions

ProcedureActions / parametersPermissions
sys.sp_catalogkind + object; no management payloadIdentity-filtered catalog.
sys.sp_monitorsnapshot; database/detail payloadFiltered user session; API keys refused.
sys.sp_userslist/save/delete/password; account payloadServer admin.
sys.sp_api_keyslist/create/revoke; key payloadServer admin.
sys.sp_storageapply; operation and fieldsServer admin.
sys.sp_maintenancelist/cancel/checkpoint/clear_cache/reclaim/vacuum/consolidate/auto; supported async tasksServer admin.
sys.sp_importstart/chunk/preview/run/status/cancelAdmin and job ownership.
sys.sp_ingestload; table/columns/rows or CSV payloadINSERT on target.
sys.sp_notebookslist/save/deleteOwning user session; API keys refused.

Except sp_catalog, formal arguments are action and payload. payload is a string containing a JSON object, supplied through binding, not a nested object substituted for SQL text. Management results use a TEXT json column containing the structured response. Management operations gain no invented OUTPUT parameters.

Explicit Python loop for protocol 4

This loop uses only the example client’s low-level HTTP method. It separates messages, row counts and result sets without retaining the entire result. Each set’s types decode its own rows. The caller supplies authorized SQL or call with protocol_version 4. The returned response is global complete; outputs must not be read sooner. This example does not implement automatic network recovery.

Python
from octaviius_http import decode_value

def execute_protocol4(client, request):
    request = dict(request, protocol_version=4)
    cursor = None
    try:
        packet = client.request(client.route("query"), request)
        while True:
            cursor = packet.get("cursor") or cursor
            if not packet.get("pending"):
                if packet.get("event") == "result":
                    metadata = packet["columns_meta"]
                    for row in packet.get("rows", []):
                        values = [decode_value(v, m) for v, m in zip(row, metadata)]
                        print(packet["result_set_id"], packet["columns"], values)
                elif packet.get("event") in ("message", "row_count"):
                    print(packet["event"], packet.get("odbc_row_count"), packet.get("messages"))
                if packet.get("complete"):
                    return packet
                sequence = packet["sequence"] + 1
            else:
                sequence = packet["next_sequence"]
            packet = client.request(client.route("fetch"), {
                "protocol_version": 4, "cursor": cursor, "sequence": sequence})
    finally:
        if cursor:
            client.request(client.route("close"), {"protocol_version": 4, "cursor": cursor})