v2026.6.4
All Bundles
Bundle ODBC database access layer. Connection manages database sessions; Statement and ParameterStatement execute SQL queries; ResultSet iterates over rows and extracts typed column values. Compile with -lib odbc.

Connection

ODBC database connection

Operations

Close #

Closes a connection

method : public : Close() ~ Nil

Commit #

Commits the current transaction.

method : public : Commit() ~ Bool

Return

TypeDescription
Booltrue if successful

CreateParameterStatement #

Create a parametrized SQL statement

method : public : CreateParameterStatement(sql:String) ~ ParameterStatement

Parameters

NameTypeDescription
sqlStringSQL statement

Return

TypeDescription
ParameterStatementresult set

Example

conn := Database.ODBC.Connection->New("mydsn", "user", "pass");
if(conn->IsOpen()) {
  stmt := conn->CreateParameterStatement("INSERT INTO users(name,age) VALUES(?,?)");
  stmt->SetVarchar(1, "Alice"); # bind first parameter
  stmt->SetInt(2, 30);          # bind second parameter
  stmt->Update();
  conn->Close();
};

GetColumns #

Gets column information for a table as name:type pairs.

method : public : GetColumns(table:String) ~ String[]

Parameters

NameTypeDescription
tableStringtable name

Return

TypeDescription
Stringarray of column descriptors (name:type), or Nil on failure

Example

conn := Database.ODBC.Connection->New("mydsn", "user", "pass");
if(conn->IsOpen()) {
  cols := conn->GetColumns("users"); # get column descriptors
  each(c in cols) { cols[c]->PrintLine(); };
  conn->Close();
};

GetLastError #

Gets the last error message from the connection.

method : public : GetLastError() ~ String

Return

TypeDescription
Stringerror message string, or empty if no error

Example

conn := Database.ODBC.Connection->New("mydsn", "user", "pass");
if(conn->Update("BAD SQL") < 0) {
  conn->GetLastError()->PrintLine(); # print connection error
};
conn->Close();

GetTables #

Gets the list of table names in the data source.

method : public : GetTables() ~ String[]

Return

TypeDescription
Stringarray of table names, or Nil on failure

Example

conn := Database.ODBC.Connection->New("mydsn", "user", "pass");
if(conn->IsOpen()) {
  tables := conn->GetTables(); # list all tables
  each(t in tables) { tables[t]->PrintLine(); };
  conn->Close();
};

IsOpen #

Check rather a connect is open

method : public : IsOpen() ~ Bool

Return

TypeDescription
Booltrue if connected, false otherwise

Example

conn := Database.ODBC.Connection->New("mydsn", "user", "pass");
if(conn->IsOpen()) { # verify connection succeeded
  "Connected!"->PrintLine();
  conn->Close();
};

New # constructor

Constructor

New(ds:String, username:String, password:String)

Parameters

NameTypeDescription
dsStringODBC data source
usernameStringODBC connection name
passwordStringODBC connection password

Example

conn := Database.ODBC.Connection->New("mydsn", "admin", "pass");
if(conn->IsOpen()) {
  rs := conn->Select("SELECT name FROM users");
  while(rs->Next()) { rs->GetVarchar(1)->PrintLine(); };
  rs->Close();
  conn->Close();
};

New # constructor

Constructor using a connection string

New(conn_str:String)

Parameters

NameTypeDescription
conn_strStringODBC connection string (e.g. "Driver={SQL Server};Server=localhost;Database=mydb;Uid=user;Pwd=pass;")

Example

cs := "Driver={SQLite3};Database=app.db;";
conn := Database.ODBC.Connection->New(cs); # connect via connection string
if(conn->IsOpen()) {
  conn->Update("CREATE TABLE IF NOT EXISTS log (msg VARCHAR(255))");
  conn->Close();
};

Rollback #

Rolls back the current transaction.

method : public : Rollback() ~ Bool

Return

TypeDescription
Booltrue if successful

Select #

Executes a SQL select statement

method : public : Select(sql:String) ~ ResultSet

Parameters

NameTypeDescription
sqlStringSQL statement

Return

TypeDescription
ResultSetresult set

Example

conn := Database.ODBC.Connection->New("mydsn", "user", "pass");
if(conn->IsOpen()) {
  rs := conn->Select("SELECT id, name FROM users"); # execute query
  while(rs->Next()) {
    rs->GetVarchar("name")->PrintLine();
  };
  rs->Close();
  conn->Close();
};

SetAutoCommit #

Sets autocommit mode. When false, changes must be explicitly committed.

method : public : SetAutoCommit(enable:Bool) ~ Bool

Parameters

NameTypeDescription
enableBooltrue for autocommit, false for manual transaction control

Return

TypeDescription
Booltrue if successful

Example

conn := Database.ODBC.Connection->New("mydsn", "user", "pass");
conn->SetAutoCommit(false); # start manual transaction
conn->Update("DELETE FROM temp_log");
conn->Commit(); # commit changes
conn->Close();

Update #

Executes a SQL update statement

method : public : Update(sql:String) ~ Int

Parameters

NameTypeDescription
sqlStringSQL statement

Return

TypeDescription
Intresult code

Example

conn := Database.ODBC.Connection->New("mydsn", "user", "pass");
if(conn->IsOpen()) {
  rc := conn->Update("INSERT INTO log(msg) VALUES ('hello')");
  "rows affected: {$rc}"->PrintLine();
  conn->Close();
};