Embedded SQL Application Development in C

As explained in the eXtremeSQL C API page, an embedded SQL application will define its database schema using the eXtremeDB DDL then compile the schema using mcocomp as for all C and C++ applications. The applications will then use the static C API functions to start the eXtremeSQL runtime, specify memory devices and database parameters, and then call mco_db_open_dev() to open the database and mco_db_connect() to create a database connection. This database connection (handle) is then passed to the eXtremeSQL function mco_api_initialize() to initialize the SQL wrapper. Then mcosql_open() is called to open an SQL engine.

This SQL engine structure is used for all SQL database access through functions mcosql_execute_query() and mcosql_execute_statement().

Processing SQL Queries

The C structures data_source_t, cursor_t and record_t are provided for processing query results. Typically the address of a data_source_t will be passed with a select statement to function mcosql_execute_query() to obtain a result set; then a cursor_t will be created by function mcosql_get_cursor() which is used to iterate the result set (data source) . Cursor navigation functions mcosql_move_first(), mcosql_move_next(), mcosql_move_last() and mcosql_move_prev() are used to position the cursor and obtain a record_t handle for the current result set row. The individual column values of the result set row (record) can then be accessed with function mcosql_get_column_value(). When finished, the function mcosql_release_query_result() must be called to release the dynamic memory resources allocated for this data_source_t.

Executing SQL Statements

The SQL engine structure is passed to function mcosql_execute_statement()with an insert, update or delete statement to modify database contents. A number of argument substitution specifiers are provided for constructing SQL statements.

Prepared Statements

SQL statements can be prepared and reused multiple times. This saves processor time by eliminating the statement compilation step each time the statement is executed. An even more significant advantage is that the prepare step binds its statement arguments only once and then reuses these arguments in further calculations. This can have a noticeable effect because, unlike the mcosql_execute_query() and mcosql_execute_statement()functions, mcosql_prepare_statement()works only with pointers to arguments. Thus the values of arguments are bound at the prepare step so that the mcosql_execute_prepared_query() or mcosql_execute_prepared_statement()functions work with the actual values of these statement arguments.

eXtremeSQL Application Implementation Details

Please use the links below to view details of the category of APIs of interest:

Runtime Initialization eXtremeSQL runtime initialization
Engine Initialization SQL engine initialization
Queries Executing database queries
Statements Executing other SQL statements
Prepared Statements Executing Prepared Statements
Argument Substitution SQL Statement Argument Substitution
Transactions Managing database transactions
Metadata Saving database metadata
Mixing Languages Mixing the C language API with C++