### odbcinst.ini Driver Configuration Example Source: https://github.com/lurcher/unixodbc/blob/master/doc/AdministratorManual/odbcinst.html This is an example of how to configure a driver in the odbcinst.ini file. The Driver and Setup paths point to the ODBC driver and setup libraries. The FileUsage entry is important for the odbcinst program. ```ini [PostgreSQL] Description = PostgreSQL driver for Linux & Win32 Driver = /usr/local/lib/libodbcpsql.so Setup = /usr/local/lib/libodbcpsqlS.so FileUsage = 1 ``` -------------------------------- ### Configure, Compile, and Install Qt Source: https://github.com/lurcher/unixodbc/blob/master/doc/AdministratorManual/unixODBCsetup.html These commands are used to configure, compile, and install the Qt toolkit from its source directory. Ensure you have the necessary development tools installed. ```bash ./configure ``` ```bash make ``` ```bash make install ``` -------------------------------- ### Build and Install from Source Source: https://github.com/lurcher/unixodbc/blob/master/doc/AdministratorManual/index.html After configuring, use these standard commands to build and install unixODBC from source. ```bash [root@p12 unixODBC]# make [root@p12 unixODBC]# make install ``` -------------------------------- ### Build and Install PHP Source: https://github.com/lurcher/unixodbc/blob/master/doc/AdministratorManual/php3.html Compile and install PHP after configuration. ```bash make make install ``` -------------------------------- ### Start MySQL Server Source: https://github.com/lurcher/unixodbc/blob/master/doc/AdministratorManual/unixODBCsetup.html This command starts the MySQL database server in the background. Ensure that MySQL is properly installed and configured before running this. ```bash /usr/local/bin/safe_mysqld & ``` -------------------------------- ### Install User DSN using Template Source: https://github.com/lurcher/unixodbc/blob/master/doc/AdministratorManual/odbcinst.html Use this command to install a Data Source Name (DSN) for the current user by providing a template file. ```bash odbcinst -i -s -f template_file ``` -------------------------------- ### Install ODBC Driver using Template Source: https://github.com/lurcher/unixodbc/blob/master/doc/AdministratorManual/odbcinst.html Use this command to install an ODBC driver by providing a template file with driver configuration. ```bash odbcinst -i -d -f template_file ``` -------------------------------- ### Initialize MySQL Database Source: https://github.com/lurcher/unixodbc/blob/master/doc/AdministratorManual/unixODBCsetup.html Run this command as root to set up the system tables for MySQL. This is a necessary step before starting the MySQL server. ```bash /usr/local/bin/mysql_install_db ``` -------------------------------- ### Configure Apache Source: https://github.com/lurcher/unixodbc/blob/master/doc/AdministratorManual/php3.html Configure Apache before installing PHP. Adjust the prefix as needed. ```bash ./configure --prefix=/www ``` -------------------------------- ### Configure, Compile, and Install unixODBC Source: https://github.com/lurcher/unixodbc/blob/master/doc/AdministratorManual/unixODBCsetup.html These commands are used to configure, compile, and install the unixODBC package from its source directory. This process requires all necessary libraries and tools to be present. ```bash ./configure ``` ```bash ./make ``` ```bash ./make install ``` -------------------------------- ### Setting Custom Installation Prefix Source: https://github.com/lurcher/unixodbc/blob/master/doc/AdministratorManual/unixODBCsetup.html Use the --prefix flag to specify a custom installation directory for the ODBC drivers, such as /usr/local/odbc. ```bash --prefix=/usr/local/odbc ``` -------------------------------- ### Configure PHP with Custom ODBC Source: https://github.com/lurcher/unixodbc/blob/master/doc/AdministratorManual/php3.html Configure PHP to use a custom ODBC installation. Enable track vars if needed. ```bash ./configure --with-apache=../apache_1.3.6 --with-custom-odbc=/usr/local --enable-track-vars ``` -------------------------------- ### ODBC .odbc.ini Configuration for PostgreSQL Source: https://github.com/lurcher/unixodbc/blob/master/doc/AdministratorManual/odbcinst.html Example configuration for a PostgreSQL DSN in the .odbc.ini file. This specifies connection parameters like server, database, and port. ```ini [PostgreSQL] Description = Test to Postgres Driver = PostgreSQL Trace = Yes TraceFile = sql.log Database = nick Servername = localhost UserName = Password = Port = 5432 Protocol = 6.4 ReadOnly = No RowVersioning = No ShowSystemTables = No ShowOidColumn = No FakeOidIndex = No ConnSettings = ``` -------------------------------- ### Configure MySQL Driver in ODBCConfig Source: https://github.com/lurcher/unixodbc/blob/master/doc/AdministratorManual/unixODBCsetup.html Use these settings when configuring the MySQL driver via the ODBCConfig GUI. Ensure the driver and setup library paths are correct for your installation. ```text Name: myodbc Description: MySQL driver. Driver: /usr/local/lib/libmyodbc-2.50.23.so Setup: /usr/local/lib/libodbcmyS.so FileUsage: 1 ``` -------------------------------- ### Build from CVS Source Source: https://github.com/lurcher/unixodbc/blob/master/doc/AdministratorManual/index.html When building from CVS source, use this command to start the build process, which utilizes GNU auto-tools. ```bash [root@p12 unixODBC]# make -f Makefile.cvs ``` -------------------------------- ### Check unixODBC Installation Source: https://github.com/lurcher/unixodbc/blob/master/doc/AdministratorManual/index.html Execute this command in the terminal to check if unixODBC is already installed on your system. ```bash [root@p12 qt]# odbcinst --version unixODBC 2.1.1 ``` -------------------------------- ### MyODBC Configure Options Source: https://github.com/lurcher/unixodbc/blob/master/doc/AdministratorManual/unixODBCsetup.html Use these flags when configuring the MyODBC driver to ensure it integrates correctly with unixODBC. Specify the directory where unixODBC is installed and the location of MySQL sources. ```bash ./configure --with-unixodbc=/usr/local --with-mysql-sources=/usr/local/mysql ``` -------------------------------- ### Allocate Connection Handle and Set Timeout Source: https://github.com/lurcher/unixodbc/blob/master/doc/ProgrammerManual/Tutorial/conne.html Allocates a connection handle and sets the login timeout attribute for the connection. This example sets a timeout of 5 seconds. ```c // 2. allocate connection handle, set timeout V_OD_erg = SQLAllocHandle(SQL_HANDLE_DBC, V_OD_Env, &V_OD_hdbc); if ((V_OD_erg != SQL_SUCCESS) && (V_OD_erg != SQL_SUCCESS_WITH_INFO)) { printf("Error AllocHDB %d\n",V_OD_erg); SQLFreeHandle(SQL_HANDLE_ENV, V_OD_Env); exit(0); } SQLSetConnectAttr(V_OD_hdbc, SQL_LOGIN_TIMEOUT, (SQLPOINTER *)5, 0); ``` -------------------------------- ### MyODBC Configure Flags for unixODBC Source: https://github.com/lurcher/unixodbc/blob/master/doc/AdministratorManual/unixODBCsetup.html These are the specific flags for the configure script to locate and use unixODBC. DIR should be replaced with the actual installation path of unixODBC. ```bash --with-unixODBC=DIR ``` ```bash --with-unixODBC-libs=LIBDIR --with-unixODBC-includes=INCDIR ``` -------------------------------- ### ODBC Driver Template Configuration Source: https://github.com/lurcher/unixodbc/blob/master/doc/AdministratorManual/odbcinst.html Example INI-style configuration for an ODBC driver template file. This defines the driver's description and paths to its shared libraries. ```ini [PostgreSQL] Description = PostgreSQL driver for Linux & Win32 Driver = /usr/local/lib/libodbcpsql.so Setup = /usr/local/lib/libodbcpsqlS.so ``` -------------------------------- ### Get Number of Result Columns with SQLNumResultCols Source: https://github.com/lurcher/unixodbc/blob/master/doc/ProgrammerManual/Tutorial/resul.html Call SQLNumResultCols after executing a query to determine the number of columns in the result set. This is useful when the query uses SELECT *. ```c SQLSMALLINT V_OD_colanz; // Num of columns V_OD_erg=SQLNumResultCols(V_OD_hstmt,&V_OD_colanz); if ((V_OD_erg != SQL_SUCCESS) && (V_OD_erg != SQL_SUCCESS_WITH_INFO)) { printf("Fehler im ResultCols %d\n",V_OD_erg); SQLFreeHandle(SQL_HANDLE_STMT,V_OD_hstmt); SQLFreeHandle(SQL_HANDLE_DBC,V_OD_hdbc); SQLFreeHandle(SQL_HANDLE_ENV, V_OD_Env); exit(0); } printf("Number of Columns %d\n",V_OD_colanz); ``` -------------------------------- ### Configure Build Options Source: https://github.com/lurcher/unixodbc/blob/master/doc/AdministratorManual/index.html Execute the configure script with appropriate options to customize the build for your system's features and requirements. ```bash [root@p12 unixODBC]# ./configure --help ``` -------------------------------- ### Create ODBC Header File Source: https://github.com/lurcher/unixodbc/blob/master/doc/AdministratorManual/php3.html Create an odbc.h file in the include directory with necessary SQL headers. ```c #include #include #include ``` -------------------------------- ### Configure Apache with PHP Module Source: https://github.com/lurcher/unixodbc/blob/master/doc/AdministratorManual/php3.html Reconfigure Apache to activate the PHP3 module. Adjust the prefix as needed. ```bash ./configure --prefix=/www --activate-module=src/modules/php3/libphp3.a ``` -------------------------------- ### List All Available ODBC Datasources Source: https://github.com/lurcher/unixodbc/blob/master/doc/ProgrammerManual/Tutorial/dsn.html Use this C function to iterate through and print all configured system and user DSNs along with their descriptions. Ensure an environment handle (V_OD_Env) is allocated before calling. ```c void OD_ListDSN(void) { char l_dsn[100],l_desc[100]; short int l_len1,l_len2,l_next; l_next=SQL_FETCH_FIRST; while( SQLDataSources(V_OD_Env,l_next,l_dsn, sizeof(l_dsn), &l_len1, l_desc, sizeof(l_desc), &l_len2) == SQL_SUCCESS) { printf("Server=(%s) Beschreibung=(%s)\n",l_dsn,l_desc); l_next=SQL_FETCH_NEXT; } } ``` -------------------------------- ### Extract Qt Sources Source: https://github.com/lurcher/unixodbc/blob/master/doc/AdministratorManual/unixODBCsetup.html Use this command to extract the Qt source code tarball. Ensure you use the correct filename for your downloaded version. ```bash tar zxvf qt-2.0.1.tar.gz ``` -------------------------------- ### Copy and Configure PHP Ini Source: https://github.com/lurcher/unixodbc/blob/master/doc/AdministratorManual/php3.html Copy the distribution PHP ini file and configure Apache's httpd.conf or srm.conf to recognize PHP3 files. ```bash cp php3.ini-dist /usr/local/lib/php3.ini # Add to httpd.conf or srm.conf: # AddType application/x-httpd-php3 .php3 ``` -------------------------------- ### SQLConnect Source: https://github.com/lurcher/unixodbc/blob/master/doc/ProgrammerManual/Tutorial/gloss.html Establishes a connection to a specified data source using provided credentials. ```APIDOC ## SQLConnect ### Description Connects to a datasource. ### Method SQLConnect ### Arguments #### ConnectionHandle `ConnectionHandle` must have been allocated by `SQLAllocHandle` and will hold all information about the connection. #### ServerName Name of the database server. #### NameLength1 The length of `ServerName` or `SQL_NTS`. #### UserName The name of the user who connects to the database. #### NameLength2 The length of `UserName` or `SQL_NTS`. #### Authentication Password of the user. #### NameLength3 The length of `Authentication` or `SQL_NTS`. ``` -------------------------------- ### Complete ODBC Data Fetching Program Source: https://github.com/lurcher/unixodbc/blob/master/doc/ProgrammerManual/Tutorial/resul.html A complete C program demonstrating how to connect to an ODBC data source, execute a query, and fetch data row by row. Includes error handling and resource cleanup. ```c /* odbc.c testing unixODBC */ #include #include #include #include #include SQLHENV V_OD_Env; // Handle ODBC environment long V_OD_erg; // result of functions SQLHDBC V_OD_hdbc; // Handle connection char V_OD_stat[10]; // Status SQL SQLINTEGER V_OD_err,V_OD_rowanz,V_OD_id; SQLSMALLINT V_OD_mlen,V_OD_colanz; char V_OD_msg[200],V_OD_buffer[200]; int main(int argc,char *argv[]) { // 1. allocate Environment handle and register version V_OD_erg=SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&V_OD_Env); if ((V_OD_erg != SQL_SUCCESS) && (V_OD_erg != SQL_SUCCESS_WITH_INFO)) { printf("Error AllocHandle\n"); exit(0); } V_OD_erg=SQLSetEnvAttr(V_OD_Env, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0); if ((V_OD_erg != SQL_SUCCESS) && (V_OD_erg != SQL_SUCCESS_WITH_INFO)) { printf("Error SetEnv\n"); SQLFreeHandle(SQL_HANDLE_ENV, V_OD_Env); exit(0); } // 2. allocate connection handle, set timeout V_OD_erg = SQLAllocHandle(SQL_HANDLE_DBC, V_OD_Env, &V_OD_hdbc); if ((V_OD_erg != SQL_SUCCESS) && (V_OD_erg != SQL_SUCCESS_WITH_INFO)) { printf("Error AllocHDB %d\n",V_OD_erg); SQLFreeHandle(SQL_HANDLE_ENV, V_OD_Env); exit(0); } SQLSetConnectAttr(V_OD_hdbc, SQL_LOGIN_TIMEOUT, (SQLPOINTER *)5, 0); // 3. Connect to the datasource "web" V_OD_erg = SQLConnect(V_OD_hdbc, (SQLCHAR*) "web", SQL_NTS, (SQLCHAR*) "christa", SQL_NTS, (SQLCHAR*) "", SQL_NTS); if ((V_OD_erg != SQL_SUCCESS) && (V_OD_erg != SQL_SUCCESS_WITH_INFO)) { printf("Error SQLConnect %d\n",V_OD_erg); SQLGetDiagRec(SQL_HANDLE_DBC, V_OD_hdbc,1, V_OD_stat, &V_OD_err,V_OD_msg,100,&V_OD_mlen); printf("%s (%d)\n",V_OD_msg,V_OD_err); SQLFreeHandle(SQL_HANDLE_ENV, V_OD_Env); exit(0); } printf("Connected !\n"); V_OD_erg=SQLAllocHandle(SQL_HANDLE_STMT, V_OD_hdbc, &V_OD_hstmt); if ((V_OD_erg != SQL_SUCCESS) && (V_OD_erg != SQL_SUCCESS_WITH_INFO)) { printf("Fehler im AllocStatement %d\n",V_OD_erg); SQLGetDiagRec(SQL_HANDLE_DBC, V_OD_hdbc,1, V_OD_stat,&V_OD_err,V_OD_msg,100,&V_OD_mlen); printf("%s (%d)\n",V_OD_msg,V_OD_err); SQLFreeHandle(SQL_HANDLE_ENV, V_OD_Env); exit(0); } SQLBindCol(V_OD_hstmt,1,SQL_C_CHAR, &V_OD_buffer,150,&V_OD_err); SQLBindCol(V_OD_hstmt,2,SQL_C_ULONG,&V_OD_id,150,&V_OD_err); V_OD_erg=SQLExecDirect(V_OD_hstmt,"SELECT dtname,iduser FROM tkeyuser order by iduser",SQL_NTS); if ((V_OD_erg != SQL_SUCCESS) && (V_OD_erg != SQL_SUCCESS_WITH_INFO)) { printf("Error in Select %d\n",V_OD_erg); SQLGetDiagRec(SQL_HANDLE_DBC, V_OD_hdbc,1, V_OD_stat,&V_OD_err,V_OD_msg,100,&V_OD_mlen); printf("%s (%d)\n",V_OD_msg,V_OD_err); SQLFreeHandle(SQL_HANDLE_STMT,V_OD_hstmt); SQLFreeHandle(SQL_HANDLE_DBC,V_OD_hdbc); SQLFreeHandle(SQL_HANDLE_ENV, V_OD_Env); exit(0); } V_OD_erg=SQLNumResultCols(V_OD_hstmt,&V_OD_colanz); if ((V_OD_erg != SQL_SUCCESS) && (V_OD_erg != SQL_SUCCESS_WITH_INFO)) { SQLFreeHandle(SQL_HANDLE_STMT,V_OD_hstmt); SQLDisconnect(V_OD_hdbc); ``` -------------------------------- ### Connect to Datasource Source: https://github.com/lurcher/unixodbc/blob/master/doc/ProgrammerManual/Tutorial/conne.html Connects to a specified data source using the provided credentials. Includes error handling and diagnostic message retrieval if the connection fails. ```c // 3. Connect to the datasource "web" V_OD_erg = SQLConnect(V_OD_hdbc, (SQLCHAR*) "web", SQL_NTS, (SQLCHAR*) "christa", SQL_NTS, (SQLCHAR*) "", SQL_NTS); if ((V_OD_erg != SQL_SUCCESS) && (V_OD_erg != SQL_SUCCESS_WITH_INFO)) { printf("Error SQLConnect %d\n",V_OD_erg); SQLGetDiagRec(SQL_HANDLE_DBC, V_OD_hdbc,1, V_OD_stat, &V_OD_err,V_OD_msg,100,&V_OD_mlen); printf("%s (%d)\n",V_OD_msg,V_OD_err); SQLFreeHandle(SQL_HANDLE_ENV, V_OD_Env); exit(0); } printf("Connected !\n"); /* continued on next page */ ``` -------------------------------- ### unixODBC Configuration Directory Option Source: https://github.com/lurcher/unixodbc/blob/master/doc/AdministratorManual/unixODBCsetup.html This configure option allows specifying a custom directory for unixODBC configuration files like odbcinst.ini and odbc.ini. ```bash _\--sysconfdir=/etc_ ``` -------------------------------- ### ODBC .odbc.ini Configuration with Direct Driver Path Source: https://github.com/lurcher/unixodbc/blob/master/doc/AdministratorManual/odbcinst.html Alternative .odbc.ini configuration for PostgreSQL where the 'Driver' entry directly specifies the path to the driver library, bypassing the need for an odbcinst.ini entry. ```ini [PostgreSQL] Description = Test to Postgres Driver = /usr/local/lib/libodbcpsql.so Trace = Yes TraceFile = sql.log Database = nick Servername = localhost UserName = Password = Port = 5432 Protocol = 6.4 ReadOnly = No RowVersioning = No ShowSystemTables = No ShowOidColumn = No FakeOidIndex = No ConnSettings = ``` -------------------------------- ### Allocate Environment Handle and Register Version Source: https://github.com/lurcher/unixodbc/blob/master/doc/ProgrammerManual/Tutorial/conne.html Allocates an ODBC environment handle and sets the desired ODBC version (e.g., ODBC 3.0). Error handling is included for both allocation and version setting. ```c #include #include #include #include #include SQLHENV V_OD_Env; // Handle ODBC environment long V_OD_erg; // result of functions SQLHDBC V_OD_hdbc; // Handle connection char V_OD_stat[10]; // Status SQL SQLINTEGER V_OD_err,V_OD_rowanz,V_OD_id; SQLSMALLINT V_OD_mlen; char V_OD_msg[200],V_OD_buffer[200]; int main(int argc,char *argv[]) { // 1. allocate Environment handle and register version V_OD_erg=SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&V_OD_Env); if ((V_OD_erg != SQL_SUCCESS) && (V_OD_erg != SQL_SUCCESS_WITH_INFO)) { printf("Error AllocHandle\n"); exit(0); } V_OD_erg=SQLSetEnvAttr(V_OD_Env, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0); if ((V_OD_erg != SQL_SUCCESS) && (V_OD_erg != SQL_SUCCESS_WITH_INFO)) { printf("Error SetEnv\n"); SQLFreeHandle(SQL_HANDLE_ENV, V_OD_Env); exit(0); } ``` -------------------------------- ### Compile C Program with gcc Source: https://github.com/lurcher/unixodbc/blob/master/doc/ProgrammerManual/Tutorial/intro.html Use this command to compile a C program named 'odbc.c' into an executable named 'odbc' using gcc, linking against the 'odbc' library. ```bash gcc odbc.c -o odbc -lodbc ``` -------------------------------- ### Mini SQL Driver Template Source: https://github.com/lurcher/unixodbc/blob/master/doc/AdministratorManual/odbcinst.html Template configuration for the Mini SQL ODBC driver, specifying host and database connection parameters. ```ini [Mini SQL] Description = MiniSQL Driver = MiniSQL Trace = No TraceFile = Host = localhost Database = ConfigFile = ``` -------------------------------- ### Set PHP Environment Variables for ODBC Source: https://github.com/lurcher/unixodbc/blob/master/doc/AdministratorManual/php3.html Define environment variables for CFLAGS, LDFLAGS, and CUSTOM_ODBC_LIBS before configuring PHP. Remember to export them. ```bash CFLAGS="-I/usr/local/include" LDFLAGS= CUSTOM_ODBC_LIBS="-L/usr/local/lib -lodbc" export CFLAGS LDFLAGS CUSTOM_ODBC_LIBS ``` -------------------------------- ### SQLAllocHandle Source: https://github.com/lurcher/unixodbc/blob/master/doc/ProgrammerManual/Tutorial/gloss.html Allocates needed handles for ODBC operations. It can allocate environment, connection, statement, or descriptor handles. ```APIDOC ## SQLAllocHandle ### Description Allocates needed handles. ### Method SQLAllocHandle ### Arguments #### HandleType Defines the type of handle to be allocated by `SQLAllocHandle`. There are four possible values: `SQL_HANDLE_ENV`, `SQL_HANDLE_DBC`, `SQL_HANDLE_STMT`, `SQL_HANDLE_DESC`. #### InputHandle This is the input handle in whose context the new handle will be allocated. If `HandleType` is `SQL_HANDLE_ENV`, this is `SQL_NULL_HANDLE`. For a handle of type `SQL_HANDLE_DBC`, this has to be an environment handle, and if it is `SQL_HANDLE_STMT` or `SQL_HANDLE_DESC`, it must be a connection handle. #### OutputHandlePtr Pointer to a buffer in which to return the allocated handle. ### Returns `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_INVALID_HANDLE`, or `SQL_ERROR`. ``` -------------------------------- ### Freeing an environment handle Source: https://github.com/lurcher/unixodbc/blob/master/doc/ProgrammerManual/Tutorial/close.html Use `SQLFreeHandle` with `SQL_HANDLE_ENV` to free the environment handle. Ensure the handle is no longer needed before freeing. ```c SQLFreeHandle(SQL_HANDLE_ENV, V_OD_Env); ``` -------------------------------- ### SQLFetch Source: https://github.com/lurcher/unixodbc/blob/master/doc/ProgrammerManual/Tutorial/gloss.html Fetches the next row of the result set. ```APIDOC ## SQLFetch ### Description Fetches the next row of the result set. ### Signature `SQLRETURN SQLFetch(SQLHDBC StatementHandle); ` ### Arguments #### StatementHandle The handle of the statement to be closed fromwhich the data should be fetched. ### Returns `SQL_SUCCESS, SQL_NO_DATA, SQL_STILL_EXECUTING, SQL_SUCCESS_WITH_INFO, SQL_INVALID_HANDLE,` or `SQL_ERROR`. ``` -------------------------------- ### Declare Variables for Query Execution Source: https://github.com/lurcher/unixodbc/blob/master/doc/ProgrammerManual/Tutorial/query.html Declare necessary variables for statement handle, error codes, and buffers before executing a query. Ensure buffer sizes are adequate. ```c SQLHSTMT V_OD_hstmt; SQLINTEGER V_OD_err,V_OD_id; char V_OD_buffer[200]; ``` -------------------------------- ### SQLDataSources Source: https://github.com/lurcher/unixodbc/blob/master/doc/ProgrammerManual/Tutorial/gloss.html Fetches available datasource names (user, system, or both). ```APIDOC ## SQLDataSources ### Description Fetches available datasource names either user, system or both. ### Signature `SQLRETURN SQLDataSources(SQLHENV EnvironmentHandle, SQLUSMALLINT Direction, SQLCHAR *ServerName, SQLSMALLINT BufferLength1, SQLSMALLINT *NameLength1Ptr, SQLCHAR *Description, SQLSMALLINT BufferLength2, SQLSMALLINT *NameLength2Ptr);` ### Arguments #### EnvironmentHandle `EnvironmentHandle` must have been allocated by `SQLAllocHandle`. #### Direction Which DSN we are looking for. May be on of: `SQL_FETCH_FIRST` Sets up `SQLDataSources()` to lookup the first of all available datasources (either user or systemwide). `SQL_FETCH_FIRST_USER` Sets up `SQLDataSources()` to lookup the first of the available user datasources. `SQL_FETCH_FIRST_SYSTEM` Sets up `SQLDataSources()` to lookup the first of the available system datasources. `SQL_FETCH_NEXT` Fetches the next datasource. Depending on `SQL_FETCH_FIRST_USER`, `SQL_FETCH_FIRST_SYSTEM` or `SQL_FETCH_FIRST` this may only be a user datasource, only a system datasource or one of either. #### ServerName The name of the datasource is returned herein. #### BufferLength1 Defines how many chars _Servername_ may contain at most. #### NameLength1Ptr The pointer to the variable in which the actual length of the datasource name is stored. If _NameLength1Ptr_ is greater than _BufferLength1_, then the DSN in _ServerName_ is truncated to fit. #### BufferLength The size of the buffer `TargetValuePtr` points at in bytes. #### Description The description supplied with the datasource, giving more information on the datasource in human readable form. #### BufferLength2 Defines how many chars _Description_ may contain at most. #### NameLength2Ptr The pointer to the variable in which the actual length of the description is stored. If _NameLength2Ptr_ is greater than _BufferLength2_, then the description in _Description_ is truncated to fit. ### Returns `SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_ERROR`, `SQL_NO_DATA>` or `SQL_INVALID_HANDLE`. ``` -------------------------------- ### SQLConnect Function Signature Source: https://github.com/lurcher/unixodbc/blob/master/doc/ProgrammerManual/Tutorial/gloss.html Connects to a data source. The ServerName, UserName, and Authentication arguments specify the connection details. ```C SQLRETURN SQLConnect(SQLHDBC ConnectionHandle, SQLCHAR *ServerName, SQLSMALLINT NameLength1, SQLCHAR *UserName, SQLSMALLINT NameLength2, SQLCHAR *Authentication, SQLSMALLINT NameLength3); ``` -------------------------------- ### MySQL Driver Template Source: https://github.com/lurcher/unixodbc/blob/master/doc/AdministratorManual/odbcinst.html Template configuration for the MySQL ODBC driver, including host, port, socket, and database details. ```ini [MySQL] Description = MySQL Driver = MySQL Trace = No TraceFile = Host = localhost Port = Socket = Database = ``` -------------------------------- ### Sybase SQL Anywhere 5.0 Driver Template Source: https://github.com/lurcher/unixodbc/blob/master/doc/AdministratorManual/odbcinst.html Template configuration for the Sybase SQL Anywhere 5.0 ODBC driver, including user ID, password, and database file. ```ini [Sybase SQL Anywhere 5.0] Driver=Sybase SQL Anywhere 5.0 Description=Sybase SQL Anywhere 5.0 ODBC Driver Userid=dba Password=sql DatabaseFile=sademo.db ``` -------------------------------- ### Configure User DSN for MySQL Source: https://github.com/lurcher/unixodbc/blob/master/doc/AdministratorManual/unixODBCsetup.html This configuration is for a user-specific DSN to connect to a MySQL database. Adjust the 'Database' field if the 'test' database is not suitable. ```text Name: mysqltest Description: myodbc Driver: myodbc Trace: Yes TraceFile: mysql.log Host: localhost Port: 3306 Socket: Database: test ``` -------------------------------- ### SQLFreeHandle Source: https://github.com/lurcher/unixodbc/blob/master/doc/ProgrammerManual/Tutorial/gloss.html Frees allocated handles. ```APIDOC ## SQLFreeHandle ### Description frees allocated handles. ### Signature `SQLRETURN SQLFreeHandle(SQLSMALLINT HandleType, SQLHANDLE InputHandle); ` ### Arguments #### HandleType Defines the type of handle to be freed. There are four possible values: `SQL_HANDLE_ENV SQL_HANDLE_DBC SQL_HANDLE_STMT SQL_HANDLE_DESC` #### InputHandle The handle to be freed. Should match the type stated by `HandleType` ### Returns `SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_INVALID_HANDLE,` or `SQL_ERROR`. ``` -------------------------------- ### Process ODBC Query Results Source: https://github.com/lurcher/unixodbc/blob/master/doc/ProgrammerManual/Tutorial/resul.html This code demonstrates fetching and printing results from an ODBC query. It includes error checking for row count retrieval and iterates through fetched rows until SQL_NO_DATA is returned. Ensure all necessary ODBC handles are initialized before execution. ```c SQLFreeHandle(SQL_HANDLE_DBC,V_OD_hdbc); SQLFreeHandle(SQL_HANDLE_ENV, V_OD_Env); exit(0); } printf("Number of Columns %d\n",V_OD_colanz); V_OD_erg=SQLRowCount(V_OD_hstmt,&V_OD_rowanz); if ((V_OD_erg != SQL_SUCCESS) && (V_OD_erg != SQL_SUCCESS_WITH_INFO)) { printf("Number ofRowCount %d\n",V_OD_erg); SQLFreeHandle(SQL_HANDLE_STMT,V_OD_hstmt); SQLDisconnect(V_OD_hdbc); SQLFreeHandle(SQL_HANDLE_DBC,V_OD_hdbc); SQLFreeHandle(SQL_HANDLE_ENV, V_OD_Env); exit(0); } printf("Number of Rows %d\n",V_OD_rowanz); V_OD_erg=SQLFetch(V_OD_hstmt); while(V_OD_erg != SQL_NO_DATA) { printf("Result: %d %s\n",V_OD_id,V_OD_buffer); V_OD_erg=SQLFetch(V_OD_hstmt); } ; SQLFreeHandle(SQL_HANDLE_STMT,V_OD_hstmt); SQLDisconnect(V_OD_hdbc); SQLFreeHandle(SQL_HANDLE_DBC,V_OD_hdbc); SQLFreeHandle(SQL_HANDLE_ENV, V_OD_Env); return(0); } ``` -------------------------------- ### NNTP Driver Template Source: https://github.com/lurcher/unixodbc/blob/master/doc/AdministratorManual/odbcinst.html Template configuration for the NNTP driver, specifying host and database connection parameters. ```ini [nntp Data Source] Description = nntp Driver Driver = nntp Driver Trace = No TraceFile = Host = localhost Database = Port = ``` -------------------------------- ### SQLSetEnvAttr Source: https://github.com/lurcher/unixodbc/blob/master/doc/ProgrammerManual/Tutorial/gloss.html Sets attributes of environments. It takes an environment handle, an attribute to set, a pointer to the value for the attribute, and optionally the length of the value if it's a string or buffer. ```APIDOC ## SQLSetEnvAttr ### Description Sets attributes of environments. ### Method SQLSetEnvAttr ### Signature `SQLRETURN SQLSetEnvAttr(SQLHENV EnvironmentHandle, SQLINTEGER Attribute, SQLPOINTER ValuePtr, SQLINTEGER StringLength);` ### Arguments #### EnvironmentHandle `EnvironmentHandle` must have been allocated by `SQLAllocHandle` #### Attribute which attribute to set #### ValuePtr Pointer to the value for `Attribute`. Depending on `Attribute`, `ValuePtr` will be a 32-bit integer value or a pointer to a null-terminated string. #### StringLength If `ValuePtr` points to a character string or a binary buffer, this argument should be the length of `*ValuePtr`. Otherwise, for `ValuePtr` of type integer `StringLength` is ignored. ### Returns `SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_ERROR` or `SQL_INVALID_HANDLE`. ``` -------------------------------- ### Configure Threading Level for ODBC Driver Source: https://github.com/lurcher/unixodbc/blob/master/doc/AdministratorManual/odbcinst.html Add the 'Threading' parameter to a driver entry in the template file to specify the thread serialization level. '2' indicates full thread support. ```ini [PostgreSQL] Description = PostgreSQL driver for Linux & Win32 Driver = /usr/local/lib/libodbcpsql.so Setup = /usr/local/lib/libodbcpsqlS.so Threading = 2 ``` -------------------------------- ### SQLBindCol Source: https://github.com/lurcher/unixodbc/blob/master/doc/ProgrammerManual/Tutorial/gloss.html Binds a variable to a column in the result set, allowing fetched data to be stored directly into application variables. ```APIDOC ## SQLBindCol ### Description Binds a variable to a column in the result. ### Method SQLBindCol ### Arguments #### StatementHandle `StatementHandle` must have been allocated by `SQLAllocHandle` and will hold all information and the result set of the statement. #### ColumnNumber Number of the column in the result set. Starts with 1. #### TargetType Type identifier of the data type. #### TargetValuePtr The pointer to the variable in which the data will be stored. #### BufferLength The size of the buffer `TargetValuePtr` points at in bytes. #### StrLen_or_IndPtr When data is fetched, returns either the length of the data available to return, `SQL_NO_TOTAL`, or `SQL_NULL_DATA`. ### Returns `SQL_SUCCESS`, `SQL_SUCCESS_WITH_INFO`, `SQL_ERROR` or `SQL_INVALID_HANDLE`. ``` -------------------------------- ### ODBC Data Types to C Data Types Mapping Source: https://github.com/lurcher/unixodbc/blob/master/doc/ProgrammerManual/Tutorial/gloss.html This table shows the mapping between ODBC type identifiers, their corresponding typedefs, and standard C typedefs. You will need the type identifier when calling SQLBindCol. ```C Type identifier ODBC typedef C typedef SQL_C_CHAR SQLCHAR * unsigned char * SQL_C_SSHORT SQLSMALLINT short int SQL_C_USHORT SQLUSMALLINT unsigned short int SQL_C_SLONG SQLINTEGER long int SQL_C_FLOAT SQLREAL float SQL_C_DOUBLE SQLDOUBLE, SQLFLOAT double SQL_C_BINARY SQLCHAR * unsigned char SQL_C_TYPE_DATE SQL_DATE_STRUCT struct tagDATE_STRUCT { SQLSMALLINT year; SQLUSMALLINT month; SQLUSMALLINT day; } DATE_STRUCT; SQL_C_TYPE_TIME SQL_TIME_STRUCT struct tagTIME_STRUCT { SQLUSMALLINT hour; SQLUSMALLINT minute; SQLUSMALLINT second; } TIME_STRUCT; ``` -------------------------------- ### SQLExecDirect Source: https://github.com/lurcher/unixodbc/blob/master/doc/ProgrammerManual/Tutorial/gloss.html Executes a SQL statement. ```APIDOC ## SQLExecDirect ### Description Executes a SQL statement. ### Signature `SQLRETURN SQLExecDirect(SQLHSTMT StatementHandle, SQLCHAR *StatementText, SQLINTEGER TextLength);` ### Arguments #### StatementHandle `StatementHandle` must have been allocated by `SQLAllocHandle` and will hold all information and the result set of the statement. #### StatementText The SQL statement to be executed #### TextLength The length of `StatementText` or `SQL_NTS` ### Returns `SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_ERROR` or `SQL_INVALID_HANDLE`. ``` -------------------------------- ### Bind Columns to Variables Source: https://github.com/lurcher/unixodbc/blob/master/doc/ProgrammerManual/Tutorial/query.html Bind columns from the result set to program variables using SQLBindCol. Ensure the variable types match the column types and check return codes for errors. ```c SQLBindCol(V_OD_hstmt,1,SQL_C_CHAR, &V_OD_buffer,200,&V_OD_err); SQLBindCol(V_OD_hstmt,2,SQL_C_ULONG,&V_OD_id,sizeof(V_OD_id),&V_OD_err); ``` -------------------------------- ### SQLBindCol Function Signature Source: https://github.com/lurcher/unixodbc/blob/master/doc/ProgrammerManual/Tutorial/gloss.html Binds a variable to a column in the result set. The TargetType argument specifies the data type identifier of the column. ```C SQLRETURN SQLBindCol(SQLHSTMT StatementHandle, SQLUSMALLINT ColumnNumber, SQLSMALLINT TargetType, SQLPOINTER TargetValuePtr, SQLINTEGER BufferLength, SQLINTEGER *StrLen_or_IndPtr); ``` -------------------------------- ### Execute SQL Query and Handle Errors Source: https://github.com/lurcher/unixodbc/blob/master/doc/ProgrammerManual/Tutorial/query.html Execute a direct SQL query using SQLExecDirect and handle potential errors. If an error occurs, retrieve diagnostic information and deallocate handles. ```c V_OD_erg=SQLExecDirect(V_OD_hstmt, "SELECT dtname,iduser FROM tkeyuser order by iduser",SQL_NTS); if ((V_OD_erg != SQL_SUCCESS) && (V_OD_erg != SQL_SUCCESS_WITH_INFO)) { printf("Error Select %d\n",V_OD_erg); SQLGetDiagRec(SQL_HANDLE_DBC, V_OD_hdbc,1, V_OD_stat, &V_OD_err, V_OD_msg,100,&V_OD_mlen); printf("%s (%d)\n",V_OD_msg,V_OD_err); SQLFreeHandle(SQL_HANDLE_DBC,V_OD_hdbc); SQLFreeHandle(SQL_HANDLE_STMT, V_OD_hstmt); SQLFreeHandle(SQL_HANDLE_ENV, V_OD_Env); exit(0); } ``` -------------------------------- ### SQLAllocHandle Function Signature Source: https://github.com/lurcher/unixodbc/blob/master/doc/ProgrammerManual/Tutorial/gloss.html Allocates needed handles for ODBC operations. The HandleType argument defines the type of handle to be allocated. ```C SQLRETURN SQLAllocHandle(SQLSMALLINT HandleType, SQLHANDLE InputHandle, SQLHANDLE *OutputHandlePtr); ``` -------------------------------- ### SQLNumResultCols Source: https://github.com/lurcher/unixodbc/blob/master/doc/ProgrammerManual/Tutorial/gloss.html Returns the number of columns in the result set. ```APIDOC ## SQLNumResultCols ### Description returns the number of columns in the result set. ### Signature `SQLRETURN SQLNumResultCols(SQLHSTMT StatementHandle, SQLSMALLINT *ColumnCountPtr); ` ### Arguments #### StatementHandle `StatementHandle` must have been allocated by `SQLAllocHandle` and holds all information and the result set of the statement. #### ColumnCountPtr A pointer to a variable to hold the result value. ### Returns `SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_STILL_EXECUTING, SQL_INVALID_HANDLE,` or `SQL_ERROR`. ``` -------------------------------- ### Closing a database connection Source: https://github.com/lurcher/unixodbc/blob/master/doc/ProgrammerManual/Tutorial/close.html Call `SQLDisconnect` with the connection handle to close the active database connection. This should be done before freeing the connection handle. ```c SQLDisconnect(V_OD_hdbc); ``` -------------------------------- ### SQLDisconnect Source: https://github.com/lurcher/unixodbc/blob/master/doc/ProgrammerManual/Tutorial/gloss.html Disconnects the specified connection. ```APIDOC ## SQLDisconnect ### Description disconnects the specified connection ### Signature `SQLRETURN SQLDisconnect(SQLHDBC ConnectionHandle); ` ### Arguments #### ConnectionHandle The handle of the connection to be closed. ### Returns `SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_INVALID_HANDLE,` or `SQL_ERROR`. ``` -------------------------------- ### SQLSetConnectAttr Source: https://github.com/lurcher/unixodbc/blob/master/doc/ProgrammerManual/Tutorial/gloss.html Modifies attributes of connections. It takes a connection handle, an attribute to set, a pointer to the value for the attribute, and optionally the length of the value if it's a string or buffer. ```APIDOC ## SQLSetConnectAttr ### Description Modifies attributes of connections. ### Method SQLSetConnectAttr ### Signature `SQLRETURN SQLSetConnectAttr(SQLHDBC ConnectionHandle, SQLINTEGER Attribute, SQLPOINTER ValuePtr, SQLINTEGER StringLength);` ### Arguments #### ConnectionHandle `ConnectionHandle` must have been allocated by `SQLAllocHandle` and defines the connection which will be modified. #### Attribute which attribute to set #### ValuePtr Pointer to the value for `Attribute`. Depending on `Attribute`, `ValuePtr` will be a 32-bit integer value or a pointer to a null-terminated string. #### StringLength If `ValuePtr` points to a character string or a binary buffer, this argument should be the length of `*ValuePtr`. Otherwise, for `ValuePtr` of type integer `StringLength` is ignored. ### Returns `SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_ERROR` or `SQL_INVALID_HANDLE`. ``` -------------------------------- ### SQLRowCount Source: https://github.com/lurcher/unixodbc/blob/master/doc/ProgrammerManual/Tutorial/gloss.html Returns the number of rows affected by INSERT, UPDATE or DELETE. ```APIDOC ## SQLRowCount ### Description returns the number of rows affected by INSERT, UPDATE or DELETE. Many drivers (but not all) return the number of rows returned by the last executed SELECT statement too. ### Signature `SQLRETURN SQLSQLRowCount(SQLHSTMT StatementHandle, SQLSMALLINT *RowCountPtr); ` ### Arguments #### StatementHandle `StatementHandle` must have been allocated by `SQLAllocHandle` and holds all information and the result set of the statement. #### RowCountPtr A pointer to a variable to hold the result value. ### Returns `SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_STILL_EXECUTING, SQL_INVALID_HANDLE,` or `SQL_ERROR`. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.