
Connection manages a logical connection to an SQL database.
Refer to the Sql docs for more details.
Slots
- autoCommit
-
Bool autoCommit
If auto commit is
true
, then each statement is executed immediately. Otherwise statements are executed inside a transaction which is terminated by a call tocommit
orrollback
. Auto commit defaults totrue
. - close
-
Bool close()
Close the connection. This method is guaranteed to never throw an
Err
. Return true if the connection was closed successfully orfalse
if closed abnormally. - commit
-
Void commit()
Commit all the changes made inside the current transaction.
- execute
-
Execute a SQL statement and if applicable return the number of rows modified.
-
private Bool getAutoCommit()
- isClosed
-
Bool isClosed()
Return if this connection has been closed.
-
new make()
Internal constructor.
- open
-
static Connection open(Str database, Str username, Str password)
Open a connection to a SQL database. Throw
Err
on failure.In a Java platform, the connection is opened using JDBC. The database Str specifies the
java.sql.Connection
URL. The JDBC driver class should be preloaded - the simplest mechanism is to add it to "sys.props". - prepare
-
Prepare a statement for use later with this connection.
- query
-
Obj[] query(Str sql, Type of := def)
Execute an SQL query which returns a relational table as a result. If
of
isnull
, the result is returned as aList
ofRows
. TheCols
are available fromList.of.fields
or ontype.fields
of each row instance. Ifof
is specified, then the result is returned as aList
of that type. Columns are mapped to the type's fields. If a column cannot be mapped to a field, then anSqlErr
is thrown. - queryEach
-
Void queryEach(Str sql, Type of, |Obj| each)
Execute an SQL query. For each row in the result, invoke the specified function
c
. Ifof
is null, theObj
passed to theeach
function will be of typeRow
. Otherwise theof
type specifies the row type passed to theeach
function. - rollback
-
Void rollback()
Undo any changes made inside the current transaction.
- tableRow
-
Get a default row instance for the specified table. The result has a field for each table column.
- tables
-
Str[] tables()
List the tables in the database. Returns a list of the table names.