Databases

CSQL

Execute SQL over local Catalyst tables and deliver result rows to a delegate.

C++23 mc/CSQL.h
#include <mc/CSQL.h>

The delegate is borrowed and must outlive the CSQL instance. Positional rows use cvec; setMapped(true) selects named cmap rows.

Use parameter vectors for data values. This is Catalyst’s local SQL interface; CDB connects to PostgreSQL.

Jump to a declaration · 11

CSQLDelegate

Methods

handle

virtual void handle(cvec& row);
virtual void handle(cmap& row);

Receives a borrowed result row during execute(). Positional mode calls the vector overload, and mapped mode calls the map overload; override the form selected by setMapped() and copy any values needed later.

CSQL

class CSQL

Methods

CSQL

CSQL(CSQLDelegate* delegate, const cstr& dbPath, bool create);
CSQL(const CSQL&) = delete;

Opens or creates a local database and its schema catalog. The delegate is borrowed and receives rows when queries execute.

setMapped

void setMapped(bool flag);

Selects map callbacks when true and positional vector callbacks when false.

execute

void execute(const cstr& sql);
void execute(const cstr& sql, const cvec& params);

Executes SQL and delivers result rows synchronously to the delegate. Parameterized statements accept ? or one-based $n placeholders; supplied values are bound as data.

insert

void insert(const cstr& sql, cvec& data);

Executes a batch insertion from a vector of row vectors. Values may be moved from data; do not rely on the input rows remaining intact afterwards.

insertCSV

void insertCSV(const cstr& sql, const cstr& csv, bool header = false);

Imports CSV text using the insertion statement. header = true treats the first row as a header rather than data.

insertCSVFile

void insertCSVFile(const cstr& sql, const cstr& path, bool header = false);

Reads a CSV file and imports it using the insertion statement. header = true skips the first CSV row as a header.