This document gives a brief overview on writing applications on SOLID Light Client API. The objective of this document is to provide the reader with sufficient knowledge for connecting to SOLID Server through Light Client library and completing the basic database operations. The reader is expected to have the basic knowledge on the following subjects:
This document contains a general description of the services provided by the Light Client API and some code examples using the functions. ContentsBackground Other SOLID Light Client documentation SOLID Light Client Function
Reference Other SOLID Server documentation SOLID
Server Technical Description BackgroundSOLID Light Client API provides full access to SOLID Server relational database. It provides functions for controlling database connections, executing SQL statements, retrieving result sets, committing transactions and other SOLID Server functionality. SOLID Light Client API has a strong resemblance to ODBC, which is SOLID Server's native database API on all platforms. See SOLID Server Programmer's Guide and Reference for more information about the ODBC API. Using SOLID Light ClientGetting Started Getting started with using SOLID Light Client consists of following steps, each of which is briefly described below.
Setting up the TCP/IP InfrastructureFor more details see SOLID Light Client Installation Instructions and your platform specific documentation. Setting up the Development Environment and Building a Sample Program Building a program using SOLID Light Client library goes exactly like building any normal C/C++ program.If necessary, check your development environment documentation on the following:
The first two issues are described in more detail below. Insert the library file into your project. Check your development environment's documentation on how to link a library to a program.
Include header files Following line needs to be included in a Light Client program. #include "cli0lcli.h" Other necessary Light Client headers are included by this header file. Insert the directory containing all the Light Client headers into your development environment's include directories setting. Verifying the development environment setup The easiest way to do this is to build a Light Client sample program. This enables you to verify your development and running environment without writing any code.
Connecting to Database using the Sample Application Establishing a connection to database using SOLID Light Client library is very similar to establishing connections using ODBC. An application needs to obtain an environment handle, allocate space for a connection and establish a connection. Run the sample program to check whether it can obtain a connection to SOLID Server in your environment. The following code establishes a connection to SOLID Server database running in a machine 192.168.1.111 and listening to tcp/ip at port 1313. User account "DBA" with password "DBA" has been defined in the database. HENV henv; /* pointer to
environment
object */
rc =
SQLConnect(hdbc,(UCHAR*)"192.168.1.111
1313",SQL_NTS, (UCHAR*)"DBA",SQL_NTS,
(UCHAR*)"DBA", SQL_NTS); The connection established above can be cleared using the code below. To make it easier to read no return code checking is included.
Running SQL Statements on Light ClientThis chapter describes briefly how to do basic database operations with SQL. The following operations are presented here
For more detailed description on these subjects see other SOLID Server documentation. Executing Statements with SOLID Light Client APIThe code below executes a simple SQL statement INSERT
INTO TESTTABLE (I,C) VALUES (100,'HUNDRED'). rc = SQLAllocStmt(hdbc, &hstmt); rc =
SQLExecDirect(hstmt,(UCHAR*)"INSERT INTO TESTTABLE
(I,C) VALUES (100,'HUNDRED')",SQL_NTS); rc =
SQLTransact(SQL_NULL_HENV,hdbc,SQL_COMMIT); The code example below prepares a simple statement INSERT INTO TESTTABLE (I,C) VALUES (?,?) to be executed several times with different parameter values. Note, that the Light Client does not provide ODBC-like parameter binding. Instead, the values for parameters need to be assigned using the SQLSetParamValue function. Following variable definitions are expected. char buf[255]; As above, the code also expects a valid HENV henv and a valid HDBC hdbc to exist and variable rc of type RETCODE to be defined and a table TESTTABLE with columns I and C to exist in the database. rc = SQLAllocStmt(hdbc, &hstmt); for (i=1;i<100;i++) rc =
m_lc->LC_SQLSetParamValue( rc =
m_lc->LC_SQLExecute(hstmt); rc = SQLFreeStmt(hstmt,SQL_DROP); The following code excerpt prepares an SQL Statement
"SELECT I,C FROM TESTTABLE", executes it and
fetches all the rows the database returns. rc = SQLAllocStmt(hdbc, &hstmt); rc = SQLExecute(hstmt); rc =
SQLGetCol(hstmt,2,SQL_C_CHAR,buf,sizeof(buf),NULL); Also the following Light Client API functions may be useful when processing result sets:
Transactions and Autocommit Mode All SOLID Light Client connections have the autocommit
option set off. There is no method in Light Client to set
the option on. To commit the transaction, call the function as follows rc = SQLTransact(SQL_NULL_HENV,hdbc,SQL_COMMIT); To roll the transaction back, call it as follows. rc =
SQLTransact(SQL_NULL_HENV,hdbc,SQL_ROLLBACK); Typically, after any Light Client API function has returned SQL_ERROR or SQL_SUCCESS_WITH_INFO more information about the error or warning can be obtained by calling the SQLError function. If the following code is run against a database where no table TESTTABLE is defined it will produce the appropriate error information. As usually, the code expects a valid HENV henv and a valid HDBC hdbc to exist and variable rc of type RETCODE to be defined . rc = SQLPrepare(hstmt,(UCHAR*)"SELECT
I,C FROM TESTTABLE",SQL_NTS); char szSQLState[255]; if (SQL_ERROR == rc) Check SOLID Server Programmer's Guide and Reference Appendix A for possible error codes. Special Notes about SOLID Server and SOLID Light ClientNetwork Traffic in Fetching Data SOLID Light Client communication does not support SOLID Server's RowsPerMessage setting. Every Light Client call to SQLFetch causes a network message to be sent between client and server. This affects performance when fetching large amounts of data. Notes for Programmers Familiar with ODBCMigrating ODBC Applications to using Light Client API Migration to using SOLID Light Client from standard ODBC database interface requires some programming, if you are using ODBC functions not provided in the Light Client API. Roughly, the migration steps are as follows.
Company | Products | Support | Search | Free Eval Packs
|