This application provides an Erlang interface to communicate with relational SQL-databases. It is built on top of Microsofts ODBC interface and therefore requires that you have an ODBC driver to the database that you want to connect to.
The functions
Alas some drivers only support sequential traversal of the
result set, e.i. they do not support what in the ODBC world is
known as scrollable cursors. This will have the effect that
functions such as
Here follows type definitions that are used by more than one function in the ODBC API.
The type
commit(Ref, CommitMode) is the same as
commit(Ref, CommitMode, infinity). If the
timeout expires the client will exit with the reason
timeout.
connection_reference() - as returned by connect/2
time_out() = milliseconds() | infinity
milliseconds() = integer() >= 0
common_reason() = connection_closed | term() - some kind of
explanation of what went wrong
string() = list of ASCII characters
col_name() = string() - Name of column in the result set
col_names() - [col_name()] - e.g. a list of the names of the
selected columns in the result set.
row() = {value()} - Tuple of column values e.g. one row of the
result set.
value() = null | term() - A column value.
rows() = [row()] - A list of rows from the result set.
result_tuple() =
{updated, n_rows()} | {selected, col_names(), rows()}
n_rows() = integer() - The number of affected rows for UPDATE,
INSERT, or DELETE queries. For other query types the value
is driver defined, and hence should be ignored.
odbc_data_type() = sql_integer | sql_smallint | sql_tinyint |
{sql_decimal, precision(), scale()} |
{sql_numeric, precision(), scale()} |
{sql_char, size()} | {sql_varchar, size()} | {sql_float, precision()} |
{sql_float, precision()} | sql_real | sql_double | sql_bit | atom()
precision() = integer()
scale() = integer()
size() = integer()
The error handling strategy and possible errors sources are
described in the Erlang ODBC
Commits or rollbacks a transaction. Needed on connections where automatic commit is turned off.
Opens a connection to the database. The connection is associated with the process that created it and can only be accessed through it. This function may spawn new processes to handle the connection. These processes will terminate if the process that created the connection dies or if you call disconnect/1.
If automatic commit mode is turned on, each query will be considered as an individual transaction and will be automatically committed after it has been executed. If you want more than one query to be part of the same transaction the automatic commit mode should be turned off. Then you will have to call commit/3 explicitly to end a transaction.
As default result sets are returned as a lists of
tuples. The
Scrollable cursors are nice but causes some overhead. For some connections speed might be more important than flexible data access and then you can disable scrollable cursor for a connection, limiting the API but gaining speed
If trace mode is turned on this tells the ODBC driver to write a trace log to the file SQL.LOG that is placed in the current directory of the erlang emulator. This information may be useful if you suspect there might be a bug in the erlang ODBC application, and it might be relevant for you to send this file to our support. Otherwise you will probably not have much use of this.
For more information about the
Closes a connection to a database. This will also
terminate all processes that may have been spawned
when the connection was opened. This call will always succeed.
If the connection can not be disconnected gracefully it will
be brutally killed. However you may receive an error message
as result if you try to disconnect a connection started by another
process.
Queries the database to find out the ODBC data types of the
columns of the table
Returns the first row of the result set and positions a cursor at this row.
Returns the last row of the result set and positions a cursor at this row.
Returns the next row of the result set relative the
current cursor position and positions the cursor at this
row. If the cursor is positioned at the last row of the
result set when this function is called the returned value
will be
Executes a parameterized SQL query. For an
example see the
Use the function describe_table/[2,3] to find out which
ODBC data type that is expected for each column of that
table. If a column has a data type that is described with
capital letters, alas it is not currently supported by the
param_query function. Too know which Erlang data type
corresponds to an ODBC data type see the Erlang to ODBC
data type
Returns the previous row of the result set relative the current cursor position and positions the cursor at this row.
Starts the odbc application. Default type
is temporary.
Stops the odbc application.
Executes a SQL query or a batch of SQL queries. If it
is a SELECT query the result set is returned, on the format
Some drivers may not have the information of the number
of affected rows available and then the return value may
be
The list of column names is ordered in the same way as the
list of values of a row, e.g. the first
Executes a SQL SELECT query and associates the result set
with the connection. A cursor is positioned before the first
row in the result set and the tuple
Some drivers may not have the information of the number of
rows in the result set, then
Selects
[1]: Microsoft ODBC 3.0, Programmer's Reference and SDK Guide
See also http://msdn.microsoft.com/