module resource::jdbc::JDBC
Usage
import resource::jdbc::JDBC;
Dependencies
import Type;
import Map;
import String;
import List;
import Set;
function registerJDBCClass
Given the name of a JDBC driver class, register it so it can be used in connections.
void registerJDBCClass(str className)
function mysqlConnectString
Generate a MySQL connect string.
str mysqlConnectString(map[str,str] properties)
data Connection
JDBC Connection type.
data Connection
= jdbcConnection(int id)
;
function createConnection
Create a connection based on the given connection string.
Connection createConnection(str connectString)
function closeConnection
Close the given connection.
void closeConnection(Connection connection)
function getTableTypes
Get the types of tables available through this connection.
list[str] getTableTypes(Connection connection)
data JDBCType
The JDBC types that could be assigned to various columns.
data JDBCType
= array()
| bigInt()
| binary()
| bit()
| blob()
| boolean()
| char()
| clob()
| dataLink()
| date()
| decimal()
| distinct()
| double()
| float()
| integer()
| javaObject()
| longNVarChar()
| longVarBinary()
| longVarChar()
| nChar()
| nClob()
| null()
| numeric()
| nVarChar()
| other()
| \real()
| ref()
| rowId()
| smallInt()
| sqlXML()
| struct()
| time()
| timeStamp()
| tinyInt()
| varBinary()
| varChar()
;
data Column
A column in a table or view.
data Column
= column(str columnName, JDBCType columnType, bool nullable)
;
data Table
A table in a database.
data Table
= table(str tableName, list[Column] columns)
;
function getTableNames
Get the tables visible through this connection (just names).
set[str] getTableNames(Connection connection)
function getTables
Get the tables visible through this connection (with column info).
set[Table] getTables(Connection connection)
function getViews
Get the tables visible through this connection (with column info).
set[Table] getViews(Connection connection)
function getTable
Get the Table metadata for a named table.
Table getTable(Connection connection, str tableName)
function getView
Get the Table metadata for a named view.
Table getView(Connection connection, str viewName)
data RuntimeException
An exception thrown when we try to translate (or otherwise use) a JDBC type with no Rascal equivalent.
data RuntimeException
= unsupportedJDBCType(JDBCType jdbcType)
;
function jdbc2RascalType
Get the Rascal type (as a symbol) for the given JDBC type.
Symbol jdbc2RascalType(array())
Symbol jdbc2RascalType(bigInt())
Symbol jdbc2RascalType(binary())
Symbol jdbc2RascalType(bit())
Symbol jdbc2RascalType(blob())
Symbol jdbc2RascalType(boolean())
Symbol jdbc2RascalType(char())
Symbol jdbc2RascalType(clob())
Symbol jdbc2RascalType(dataLink())
Symbol jdbc2RascalType(date())
Symbol jdbc2RascalType(decimal())
Symbol jdbc2RascalType(distinct())
Symbol jdbc2RascalType(double())
Symbol jdbc2RascalType(float())
Symbol jdbc2RascalType(integer())
Symbol jdbc2RascalType(javaObject())
Symbol jdbc2RascalType(longNVarChar())
Symbol jdbc2RascalType(longVarBinary())
Symbol jdbc2RascalType(longVarChar())
Symbol jdbc2RascalType(nChar())
Symbol jdbc2RascalType(nClob())
Symbol jdbc2RascalType(JDBCType::null())
Symbol jdbc2RascalType(numeric())
Symbol jdbc2RascalType(nVarChar())
Symbol jdbc2RascalType(other())
Symbol jdbc2RascalType(JDBCType::\real())
Symbol jdbc2RascalType(ref())
Symbol jdbc2RascalType(rowId())
Symbol jdbc2RascalType(smallInt())
Symbol jdbc2RascalType(sqlXML())
Symbol jdbc2RascalType(struct())
Symbol jdbc2RascalType(time())
Symbol jdbc2RascalType(timeStamp())
Symbol jdbc2RascalType(tinyInt())
Symbol jdbc2RascalType(varBinary())
Symbol jdbc2RascalType(varChar())
data NULLable
Represents values which may or may not be null.
data NULLable[&T]
= NULL()
| notNULL(&T item)
;
function loadTable
Load the contents of a table.
set[&T] loadTable(type[&T] resType, Connection connection, str tableName)
This will turn the contents into a set, which by its nature will remove any duplicates and discard any order. To maintain duplicates, or the order inherent in the table, use loadTableOrdered instead.
function loadTable
Load the contents of a table.
set[value] loadTable(Connection connection, str tableName)
This will turn the contents into a set, which by its nature will remove any duplicates and discard any order. To maintain duplicates, or the order inherent in the table, use loadTableOrdered instead. This versions uses no type information, meaning that it returns a set of values.
function loadTableOrdered
Load the contents of a table.
list[&T] loadTableOrdered(type[&T] resType, Connection connection, str tableName)
This maintains order and duplicates, but does not provide access to the relational operations provided by loadTable.
function loadTableOrdered
Load the contents of a table.
list[value] loadTableOrdered(Connection connection, str tableName)
This maintains order and duplicates, but does not provide access to the relational operations provided by loadTable. Also, with no type information, this version returns a list of values.
function allTableSchemas
Prints all available schemas.
str allTableSchemas(str moduleName, loc uri)
The JDBC tables schema should be given as: jdbctables+connect-string
where connect-string
is the database-specific information needed to connect,
encoded as a URI, for instance: jdbctables+mysql://localhost/bugs?user=my_user_name&password=my_password
function tableSchema
str tableSchema(str moduleName, loc uri)
function format
str format(Symbol s)