db-commit
db-commit
Synopsis
Commits the current transaction.
Usage
(db-commit connection_id)
Returns
committed
Where
-
connection_id is string: the connection identifier.
-
committed is boolean: true if transaction was committed, false otherwise.
Description
Commits the current transaction of the connection identified by connection_id.
Exceptions
-
"SQLException": when the current transaction can not be committed.
Examples
Related functions
db-connect
db-connect
Synopsis
Opens a database connection.
Usage
(db-connect
"driver" => driver
"url" => url
"username" => username
"password" => password
"auto-commit" => auto_commit
)
Returns
connection_id
Where
-
driver is string[0..1]: the JDBC driver class name.
-
url is string: the JDBC url to access the database.
-
username is string[0..1]: the username to establish the connection.
-
password is string[0..1]: the user's password.
-
auto_commit is boolean[0..1]: when true, the current transaction is committed after each call to db-execute function. By default its value is false.
-
connection_id is string: the connection identifier.
Description
Establishes a connection to the database specified by the url paramater with the given username and password. It returns a connection identifier that is required in subsequent operations.
Exceptions
-
"SQLException": when a connection to the database can not be established.
Examples
(db-connect
"driver" => "oracle.jdbc.driver.OracleDriver"
"url" => "jdbc:oracle:thin:@oracle:1521:demo"
"username" => "scott"
"password" => "tiger"
"auto-commit" => true
)
"7f88ba0323134fcc872bf15958c32a83"
Related functions
db-disconnect
db-disconnect
Synopsis
Closes a database connection.
Usage
(db-disconnect connection_id)
Returns
closed
Where
-
connection_id is string: the connection identifier.
-
closed is boolean: true if the connection was closed or false otherwise.
Description
Closes the given database connection.
Exceptions
-
"SQLException": when the connection can not be closed.
Examples
Related functions
db-execute
db-execute
Synopsis
Executes a SQL statement.
Usage
(db-execute
connection_id
sql
"parameters" => parameters
"max-rows" => max_rows
)
Returns
result
Where
-
connection_id is string: the connection identifier.
-
sql is string: the sql statement to execute. It can be any statement supported by the JDBC driver. The statement can contain parameters represented by brackets. The value inside the brackets is the name of the parameter.
-
parameters is list[0..1]: a list containing the values of the parameters of the statament.
-
max_rows is number[0..1]: the maximum number of rows that will be returned. When max_rows is zero this functions will return all rows available.
-
result is object: a list containing the data returned by the SELECT statement or the number of rows modified by the sql statement.
Description
Executes the specified sql statament using the connection identified by connection_id. If sql is a SELECT statement then result will be a list containing the rows returned by the query. When sql is a change statement (INSERT, UPDATE or DELETE) this function will return the number of rows that were modified.
Exceptions
-
"SQLException": when the statement can not be executed.
Examples
(db-execute conn "select * from dual")
(("DUMMY" => "X"))
(db-execute
conn
"update emp set salary = salary * {factor}"
"parameters" => ("factor" => 1.2)
)
341
(db-execute
conn
"select * from emp where name = {emp}"
"parameters" => ("emp" => "JOHN")
"max-rows" => 2
)
(
(
"EMP_ID" => "23"
"NAME" => "JOHN"
"SURNAME" => "CONNOR"
)
(
"EMP_ID" => "36"
"NAME" => "JOHN"
"SURNAME" => "WALKER"
)
)
db-rollback
db-rollback
Synopsis
Rollbacks the current transaction.
Usage
(db-rollback connection_id)
Returns
rollbacked
Where
-
connection_id is string: the connection identifier.
-
rollbacked is boolean: true if transaction was aborted, false otherwise.
Description
Rollbacks the current transaction of the connection identified by connection_id.
Exceptions
-
"SQLException": when the current transaction can not be aborted.
Examples
Related functions