Types
An example of a connection string:
"DSN=sql-server;UID=aladdin;PWD=sesame"
where DSN is your ODBC Data Source Name, UID is a database user id and PWD is the password for that user. These are usually the attributes required in the connection string, but some drivers have other driver specific attributes, for example
"DSN=Oracle8;DBQ=gandalf;UID=aladdin;PWD=sesame"
where DBQ is your TNSNAMES.ORA entry name e.g. some Oracle specific configuration attribute.
All options has default values.
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.
The default timeout is infinity
>If the option binary_strings is turned on all strings will be returned as binaries and strings inputted to param_query will be expected to be binaries. The user needs to ensure that the binary is in an encoding that the database expects. By default this option is turned off.
As default result sets are returned as a lists of tuples. The TupleMode
option still exists to keep some degree of backwards compatibility. If the option is set to off, result sets will be returned as a lists of lists instead of a lists of tuples.
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.
Note
Turning the scrollable_cursors option off is noted to make old odbc-drivers able to connect that will otherwise fail.
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.
Note
For more information about the ConnectStr
see description of the function SQLDriverConnect in [1].
The extended_errors
option enables extended ODBC error information when an operation fails. Rather than returning {error, Reason}
, the failing function will return {error, {ODBCErrorCode, NativeErrorCode, Reason}}
. Note that this information is probably of little use when writing database-independent code, but can be of assistance in providing more sophisticated error handling when dealing with a known underlying database.
-
ODBCErrorCode
is the ODBC error string returned by the ODBC driver.
-
NativeErrorCode
is the numeric error code returned by the underlying database. The possible values and their meanings are dependent on the database being used.
-
Reason
is as per the Reason
field when extended errors are not enabled.
Note
The current implementation spawns a port program written in C that utilizes the actual ODBC driver. There is a default timeout of 5000 msec for this port program to connect to the Erlang ODBC application. This timeout can be changed by setting an application specific environment variable 'port_timeout' with the number of milliseconds for the ODBC application. E.g.: [{odbc, [{port_timeout, 60000}]}] to set it to 60 seconds.