Ring/Lessons/ODBC Functions

ODBC Functions
This chapter contains the ODBC functions provided by the Ring programming language. Before using the functions load the odbclib.ring library:


 * odbc_init
 * odbc_drivers
 * odbc_datasources
 * odbc_close
 * odbc_connect
 * odbc_disconnect
 * odbc_execute
 * odbc_colcount
 * odbc_fetch
 * odbc_getdata
 * odbc_tables
 * odbc_columns
 * odbc_autocommit
 * odbc_commit
 * odbc_rollback

odbc_init Function
We can create ODBC Handle using the odbc_init function

Syntax:

odbc_drivers Function
We can get a list of ODBC drivers using the odbc_drivers function

Syntax:

odbc_datasources Function
We can get a list of ODBC data sources using the odbc_datasources function

Syntax:

odbc_close Function
After the end of using ODBC functions we can free resources using ODBC_Close function

Syntax:

Print List of ODBC Drivers
The next example print a list of ODBC drivers.

Output:

Print List of ODBC Data Sources
The next example print a list of ODBC data sources.

Output:

odbc_connect Function
We can connect to the database using the odbc_connect function.

Syntax:

odbc_disconnect Function
We can close the connection to the database using the odbc_disconnect function.

Syntax:

Open and Close Connection
The next example connect to the database then close the connection

Output:

odbc_execute Function
We can execute SQL Statements on the database using the odbc_execute function.

Syntax:

odbc_colcount Function
We can get columns count in the query result using the odbc_colcount function.

Syntax:

odbc_fetch Function
We can fetch a row from the query result using the odbc_fetch function.

Syntax:

odbc_getdata Function
We can get column value from the fetched row using the odbc_getdata function.

Syntax:

Execute Query and Print Result
The next example execute query then print the query result.

odbc_tables Function
We can get a list of tables inside the database using the odbc_tables function.

We can access the result of this function as we get any query result.

Syntax:

Example:

Output:

odbc_columns Function
We can get a list of columns inside the table using the odbc_columns function.

Syntax:

Example:

Output:

odbc_autocommit Function
We can enable or disable the auto commit feature using the odbc_autocommit function.

Syntax:

odbc_commit Function
We can commit updates to the database using the odbc_commit function.

Syntax:

odbc_rollback Function
We can rollback updates to the database using the odbc_rollback function.

Syntax:

Transactions and Using Commit and Rollback
Example:

for x = 15001 to 20000 odbc_execute(pODBC,"insert into tel values (" + x + ",'fayed')") next

ODBC_ROLLBACK(pODBC) odbc_execute(pODBC,"insert into tel values (" + x + ",'fayed')") odbc_commit(pODBC)

See "Close database..." + nl	odbc_disconnect(pODBC) odbc_close(pODBC)

Output:

Save and Restore images
The next example save an image inside the database

The next example restore the image from the database