Fantom

 

const class

sql::SqlService

sys::Obj
  sql::SqlService : sys::Service

SqlService is the interface to a relational database. It is const and all state is stored as thread local variables.

Slots

autoCommitSource

Bool autoCommit

The auto-commit state of this database. If true, each statement is committed as it is executed. If false, statements are grouped into transactions and committed when commit

closeSource

Void close()

Close the database. A call to close may not actually close the database. It depends on how many times open has been called for the current thread. The database will not be closed until close has been called once for every time that open has been called.

commitSource

Void commit()

Commit all the changes made inside the current transaction.

connectionSource

const Str connection

The database specific string used to connect to the database.

dialectSource

const Dialect dialect

The database dialect for this service.

isClosedSource

Bool isClosed()

Test the closed state of the database.

logSource

const static Log log := Log.get("sql")

Standard log for the sql service

makeSource

new make(Str connection := "", Str? username := "", Str? password := "", Dialect dialect := GenericDialect())

Make a new SqlService.

  • connection is the connection string. For java this is the jdbc url. For .NET this is the connection string.
  • username is the username for the database login.
  • password is the password for the database login.
  • dialect is the database specific dialect implementation. If not specified then GenericDialect is used.
onStartSource

override Void onStart()

openSource

This open()

Open the database. This opens a connection to the database for the calling thread. A database must be open before it can be accessed. open may be called multiple times. Each time open is called, a counter is incremented. The database will not be closed until close has been called for each call to open. Return this.

passwordSource

const Str? password

The password used to connect to this database.

rollbackSource

Void rollback()

Undo any changes made inside the current transaction.

sqlSource

Statement sql(Str sql)

Create a statement for this database.

tableExistsSource

Bool tableExists(Str tableName)

Does the specified table exist in the database?

tableRowSource

Row tableRow(Str tableName)

Get a default row instance for the specified table. The result has a field for each table column.

tablesSource

Str[] tables()

List the tables in the database. Returns a list of the table names.

usernameSource

const Str? username

The username used to connect to this database.