Skip to content

CCI API reference: connections and utilities

View as Markdown

The CCI API is the C interface of CoraDB, described in the CCI overview. This reference is split into four pages:

Group Functions
Connections and utilities cci_cancel, cci_connect, cci_connect_ex, cci_connect_with_url, cci_connect_with_url_ex, cci_datasource_borrow, cci_datasource_change_property, cci_datasource_create, cci_datasource_destroy, cci_datasource_release, cci_disconnect, cci_end, cci_get_cas_info, cci_get_db_version, cci_get_dbms_type, cci_get_err_msg, cci_get_error_msg, cci_get_login_timeout, cci_get_version_string, cci_get_query_timeout, cci_get_version, cci_init, cci_property_create, cci_property_destroy, cci_property_get, cci_property_set, cci_set_allocators, cci_set_cas_change_mode, cci_set_charset, cci_set_login_timeout, cci_set_query_timeout
Transactions and session settings cci_end_tran, cci_get_autocommit, cci_get_db_parameter, cci_get_holdability, cci_is_holdable, cci_savepoint, cci_set_autocommit, cci_set_db_parameter, cci_set_holdability, cci_set_isolation_level, cci_set_lock_timeout
Statements and results cci_bind_param, cci_bind_param_array, cci_bind_param_array_size, cci_bind_param_ex, cci_close_query_result, cci_close_req_handle, cci_cursor, cci_cursor_update, cci_escape_string, cci_execute, cci_execute_array, cci_execute_batch, cci_execute_result, cci_fetch, cci_fetch_buffer_clear, cci_fetch_sensitive, cci_fetch_size, cci_get_bind_num, cci_get_class_num_objs, cci_get_data, cci_get_last_insert_id, cci_get_param_info, cci_get_query_plan, cci_last_insert_id, cci_param_info_free, cci_query_info_free, cci_get_result_info, cci_is_updatable, cci_next_result, cci_prepare, cci_prepare_and_execute, cci_query_result_free, cci_register_out_param, cci_register_out_param_ex, cci_row_count, cci_schema_info, cci_set_max_row
LOBs, collections and OIDs cci_blob_free, cci_blob_new, cci_blob_read, cci_blob_size, cci_blob_write, cci_clob_free, cci_clob_new, cci_clob_read, cci_clob_size, cci_clob_write, cci_col_get, cci_col_seq_drop, cci_col_seq_insert, cci_col_seq_put, cci_col_set_add, cci_col_set_drop, cci_col_size, cci_get_attr_type_str, cci_get_cur_oid, cci_oid, cci_oid_get, cci_oid_get_class_name, cci_oid_put, cci_oid_put2, cci_set_element_type, cci_set_free, cci_set_get, cci_set_make, cci_set_size
int cci_cancel(int conn_handle)

Cancel the running query on the other thread. This function executes the same behavior as Statement.cancel() method in JAVA.

  • CCI_ER_COMMUNICATION
  • CCI_ER_CON_HANDLE
  • CCI_ER_CONNECT

The following shows how to cancel the query execution of a thread.

/* gcc -o pthr pthr.c -m64 -I${CORADB}/include -lnsl ${CORADB}/lib/libcascci.so -lpthread
*/
#include <stdio.h>
#include <cas_cci.h>
#include <unistd.h>
#include <pthread.h>
#include <string.h>
#include <time.h>
#define QUERY "select * from db_class A, db_class B, db_class C, db_class D, db_class E"
static void *thread_main (void *arg);
static void *execute_statement (int con, char *sql_stmt);
int
main (int argc, char *argv[])
{
int thr_id = 0, conn_handle = 0, res = 0;
void *jret;
pthread_t th;
char url[1024];
T_CCI_ERROR error;
snprintf (url, 1024, "cci:coradb:localhost:33000:e-commerce:PUBLIC::");
conn_handle = cci_connect_with_url_ex (url, NULL, NULL, &error);
if (conn_handle < 0)
{
printf ("ERROR: %s\n", error.err_msg);
return -1;
}
res = pthread_create (&th, NULL, &thread_main, (void *) &conn_handle);
if (res < 0)
{
printf ("thread fork failed.\n");
return -1;
}
else
{
printf ("thread started\n");
}
sleep (5);
// If thread_main is still running, below cancels the query of thread_main.
res = cci_cancel (conn_handle);
if (res < 0)
{
printf ("cci_cancel failed\n");
return -1;
}
else
{
printf ("The query was canceled by cci_cancel.\n");
}
res = pthread_join (th, &jret);
if (res < 0)
{
printf ("thread join failed.\n");
return -1;
}
printf ("thread_main was cancelled with\n\t%s\n", (char *) jret);
free (jret);
res = cci_disconnect (conn_handle, &error);
if (res < 0)
{
printf ("ERROR: %s\n", error.err_msg);
return res;
}
return 0;
}
void *
thread_main (void *arg)
{
int con = *((int *) arg);
int ret_val;
void *ret_ptr;
T_CCI_ERROR error;
cci_set_autocommit (con, CCI_AUTOCOMMIT_TRUE);
ret_ptr = execute_statement (con, QUERY);
return ret_ptr;
}
static void *
execute_statement (int con, char *sql_stmt)
{
int col_count = 1, ind, i, req;
T_CCI_ERROR error;
char *buffer;
char *error_msg;
int res = 0;
error_msg = (char *) malloc (128);
if ((req = cci_prepare (con, sql_stmt, 0, &error)) < 0)
{
snprintf (error_msg, 128, "cci_prepare ERROR: %s\n", error.err_msg);
goto conn_err;
}
if ((res = cci_execute (req, 0, 0, &error)) < 0)
{
snprintf (error_msg, 128, "cci_execute ERROR: %s\n", error.err_msg);
goto execute_error;
}
if (res >= 0)
{
while (1)
{
res = cci_cursor (req, 1, CCI_CURSOR_CURRENT, &error);
if (res == CCI_ER_NO_MORE_DATA)
{
break;
}
if (res < 0)
{
snprintf (error_msg, 128, "cci_cursor ERROR: %s\n",
error.err_msg);
return error_msg;
}
if ((res = cci_fetch (req, &error)) < 0)
{
snprintf (error_msg, 128, "cci_fetch ERROR: %s\n",
error.err_msg);
return error_msg;
}
for (i = 1; i <= col_count; i++)
{
if ((res = cci_get_data (req, i, CCI_A_TYPE_STR, &buffer, &ind)) < 0)
{
snprintf (error_msg, 128, "cci_get_data ERROR\n");
return error_msg;
}
}
}
}
if ((res = cci_close_query_result (req, &error)) < 0)
{
snprintf (error_msg, 128, "cci_close_query_result ERROR: %s\n", error.err_msg);
return error_msg;
}
execute_error:
if ((res = cci_close_req_handle (req)) < 0)
{
snprintf (error_msg, 128, "cci_close_req_handle ERROR\n");
}
conn_err:
return error_msg;
}

Parameters

  • conn_handle: (IN) Connection handle

Returns: Error code

int cci_connect(char *ip, int port, char *db_name, char *db_user, char *db_password)

A connection handle to the database server is assigned and it tries to connect to the server. If it has succeeded, the connection handle ID is returned; if fails, an error code is returned.

  • CCI_ER_NO_MORE_MEMORY
  • CCI_ER_HOSTNAME
  • CCI_ER_CON_HANDLE
  • CCI_ER_DBMS
  • CCI_ER_COMMUNICATION
  • CCI_ER_CONNECT

Parameters

  • ip: (IN) A string that represents the IP address of the server (host name)
  • port: (IN) Broker port (The port configured in the $CORADB/conf/coradb_broker.conf file)
  • db_name: (IN) Database name
  • db_user: (IN) Database user name
  • db_passwd: (IN) Database user password

Returns: Success: Connection handle ID (int), Failure: Error code

int cci_connect_ex(char *ip, int port, char *db_name, char *db_user, char *db_password, T_CCI_ERROR * err_buf)

The cci_connect_ex function returns CCI_ER_DBMS error and checks the error details in the database error buffer (err_buf) at the same time. In that point, it is different from cci_connect and the others are the same as the cci_connect function.

  • CCI_ER_NO_MORE_MEMORY
  • CCI_ER_HOSTNAME
  • CCI_ER_CON_HANDLE
  • CCI_ER_DBMS
  • CCI_ER_COMMUNICATION
  • CCI_ER_CONNECT

Parameters

  • ip: (IN) A string that represents the IP address of the server (host name)
  • port: (IN) Broker port (The port configured in the $CORADB/conf/coradb_broker.conf file)
  • db_name: (IN) Database name
  • db_user: (IN) Database user name
  • db_passwd: (IN) Database user password
  • err_buf: Database error buffer

Returns: Success: Connection handle ID (int), Failure: Error code

int cci_connect_with_url (char *url, char *db_user, char *db_password)

The cci_connect_with_url function connects a database by using connection information passed with a url argument.

  • CCI_ER_NO_MORE_MEMORY
  • CCI_ER_HOSTNAME
  • CCI_ER_INVALID_URL
  • CCI_ER_CON_HANDLE
  • CCI_ER_CONNECT
  • CCI_ER_DBMS
  • CCI_ER_COMMUNICATION
  • CCI_ER_LOGIN_TIMEOUT
<url> ::= cci:coradb:<host>:<port>:<db_name>:<db_user>:<db_password>:[?<properties>]
<properties> ::= <property> [&<property>]
<property> ::= altHosts=<alternative_hosts> [ &rcTime=<time>] [ &loadBalance=true|false]
|{login_timeout|loginTimeout}=<milli_sec>
|{query_timeout|queryTimeout}=<milli_sec>
|{disconnect_on_query_timeout|disconnectOnQueryTimeout}=true|false
| logFile=<file_name>
| logBaseDir=<dir_name>
| logSlowQueries=true|false[&slowQueryThresholdMillis=<milli_sec>]
| logTraceApi=true|false
| logTraceNetwork=true|false
| useSSL=<bool_type>
<alternative_hosts> ::= <host>:<port> [,<host>:<port>]
<host> := HOSTNAME | IP_ADDR
<time> := SECOND
<milli_sec> := MILLI SECOND

altHosts is the property related to connection target and loginTimeout, queryTimeout, and disconnectOnQueryTimeout are the properties related to timeout; logSlowQueries, logTraceApi, and logTraceNetwork are the properties related to log information configuration for debugging. Note that a property name which is a value to be entered in the url argument is not case sensitive.

  • host: A host name or IP address of the master database

  • port: A port number

  • db_name: A name of the database

  • db_user: A name of the database user

  • db_password: A database user password. You cannot include ':' in the password of the url string.

  • loadBalance: When this value is true, the applications try to connect to the main host and alternative hosts specified with the altHosts property as a random order. (default value: false).

  • login_timeout | loginTimeout: Timeout value (unit: msec.) for database login. Upon timeout, a CCI_ER_LOGIN_TIMEOUT (-38) error is returned. The default value is 30,000(30 sec.). If this value is 0, it means infinite waiting. This value is also applied when internal reconnection occurs after the initial connection.

  • query_timeout | queryTimeout: If time specified in these properties has expired when calling cci_prepare, cci_execute, etc. a cancellation message for query request which was sent to a server will be delivered and called function returns a CCI_ER_QUERY_TIMEOUT (-39) error. The value returned upon timeout may vary depending on a value specified in disconnect_on_query_timeout. For details, see disconnect_on_query_timeout.

  • disconnect_on_query_timeout | disconnectOnQueryTimeout: Whether to disconnect socket immediately after time for query request has expired. It determines whether to terminate a socket connection immediately or wait for server response after sending cancellation message for query request to a server when calling cci_prepare, cci_execute, etc. The default value is false, meaning that it will wait for server response. It this value is true, a socket will be closed immediately after sending a cancellation message to a server upon timeout and returns the CCI_ER_QUERY_TIMEOUT (-39) error. (If an error occurs on database server side, not on broker side, it returns -1. If you want to view error details, see error codes in "database error buffer." You can get information how to check error codes in CCI error codes and error messages.) Please note that there is a possibility that a database server does not get a cancellation message and execute a query even after an error is returned.

  • logFile: A log file name for debugging (default value: cci_ <handle_id> .log). <handle_id> indicates the ID of a connection handle returned by this function.

  • logBaseDir: A directory where a debug log file is created. The file name including the path will be logBaseDir/logFile, and the relative path is possible.

  • logSlowQueries: Whether to log slow query for debugging (default value: false)

  • slowQueryThresholdMillis: Timeout for slow query logging if slow query logging is enabled (default value: 60000, unit: milliseconds)

  • logTraceApi: Whether to log the start and end of CCI functions

  • logTraceNetwork: Whether to log network data content transferred of CCI functions

  • useSSL: Packet Encryption mode (Default: false)

  • Packet encryption: useSSL = true
  • Plain text: useSSL = false

Example

URL=cci:coradb:192.168.0.1:33000:e-commerce:::?altHosts=192.168.0.2:33000,192.168.0.3:33000
URL=cci:coradb:192.168.0.1:33000:e-commerce:::?altHosts=192.168.0.2:33000,192.168.0.3:33000&rcTime=600
--connection URL string when properties(logSlowQueries,slowQueryThresholdMills, logTraceApi, logTraceNetwork) are specified for interface debugging
URL = "cci:coradb:192.168.0.1:33000:e-commerce:::?logSlowQueries=true&slowQueryThresholdMillis=1000&logTraceApi=true&logTraceNetwork=true"
--connection URL string when useSSL property specified for encrypted connection
URL = "cci:coradb:192.168.0.1:33000:e-commerce:::?useSSL=true

Parameters

  • url: (IN) A string that contains server connection information.
  • db_user: (IN) Database user name. If this is NULL, it becomes <db_user> in url. If this is an empty string ("") or <db_user> in url is not specified, DB user name becomes PUBLIC.
  • db_passwd: (IN) Database user password. If this is NULL, <db_password> in url is used. If <db_password> in url is not specified, DB password becomes an empty string ("").

Returns: Success: Connection handle ID (int), Failure: Error code

int cci_connect_with_url_ex (char *url, char *db_user, char *db_password, T_CCI_ERROR * err_buf)

The cci_connect_with_url_ex function returns CCI_ER_DBMS error and checks the error details in the database error buffer (err_buf) at the same time. In that point, it is different from cci_connect_with_url and the others are the same as the cci_connect_with_url function.

Parameters

  • err_buf: Database error buffer

T_CCI_CONN cci_datasource_borrow (T_CCI_DATASOURCE *datasource, T_CCI_ERROR *err_buf)

The cci_datasource_borrow function obtains CCI connection to be used in T_CCI_DATASOURCE struct.

See also: cci_property_create, cci_property_destroy, cci_property_get, cci_property_set, cci_datasource_create, cci_datasource_destroy, cci_datasource_release, cci_datasource_change_property

Parameters

  • datasource: (IN) T_CCI_DATASOURCE struct pointer in which CCI connection exists
  • err_buf: (OUT) Error code and message returned upon error occurrence

Returns: Success: CCI connection handler identifier, Failure: -1

int cci_datasource_change_property (T_CCI_DATASOURCE *datasource, const char *key, const char *val)

A property name of a DATASOURCE is specified in key, a value in val. The changed property value by this function is applied to all connections in the datasource.

  • CCI_ER_NO_MORE_MEMORY
  • CCI_ER_NO_PROPERTY
  • CCI_ER_PROPERTY_TYPE

The following shows names and values of changeable properties.

Property name Type Value Description
default_autocommit bool true/false Whether auto-commit or not. The default is CCI_DEFAULT_AUTOCOMMIT in coradb_broker.conf; the default of this is ON(true)
default_lock_timeout msec number Lock timeout
default_isolation string See the table of `cci_property_set <#cci_propert Isolation level. The default is isolation_level in coradb.conf; the default of this is "READ COMMITTED". y_set>`__
login_timeout msec number Login timeout. The default is 0(infinite wait). It can also be used when you call prepare or execute functions; at this time reconnection can happen.

Example

...
ps = cci_property_create ();
...
ds = cci_datasource_create (ps, &err);
...
cci_datasource_change_property(ds, "login_timeout", "5000");
cci_datasource_change_property(ds, "default_lock_timeout", "2000");
cci_datasource_change_property(ds, "default_isolation", "TRAN_REP_CLASS_COMMIT_INSTANCE");
cci_datasource_change_property(ds, "default_autocommit", "true");
...

See also: cci_property_create, cci_property_destroy, cci_property_get, cci_property_set, cci_datasource_create, cci_datasource_borrow, cci_datasource_destroy, cci_datasource_release

Parameters

  • datasource: (IN) T_CCI_DATASOURCE struct pointer to obtain CCI connections.
  • key: (IN) A pointer to the string of a property name
  • val: (IN) A pointer to the string of a property value

Returns: Error code(0: success)

T_CCI_DATASOURCE * cci_datasource_create (T_CCI_PROPERTIES *properties, T_CCI_ERROR *err_buf)

The cci_datasource_create function creates DATASOURCE of CCI.

See also: cci_property_create, cci_property_destroy, cci_property_get, cci_property_set, cci_datasource_borrow, cci_datasource_destroy, cci_datasource_release, cci_datasource_change_property

Parameters

  • properties: (IN) T_CCI_PROPERTIES struct pointer in which configuration of struct pointer is stored. Values of properties will be set with cci_property_set.
  • err_buf: (OUT) Error buffer. Error code and message returned upon error occurrence

Returns: Success: T_CCI_DATASOURCE struct pointer created, Failure: NULL

void cci_datasource_destroy (T_CCI_DATASOURCE *datasource)

The cci_datasource_destroy function destroys DATASOURCE of CCI.

See also: cci_property_create, cci_property_destroy, cci_property_get, cci_property_set, cci_datasource_create, cci_datasource_borrow, cci_datasource_release, cci_datasource_change_property

Parameters

  • datasource: (IN) T_CCI_DATASOURCE struct pointer to be deleted

Returns: void

int cci_datasource_release (T_CCI_DATASOURCE *datasource, T_CCI_CONN conn, T_CCI_ERROR *err_buf)

The cci_datasource_release function returns CCI connection released in T_CCI_DATASOURCE struct. If you want to reuse the connection after calling this function, recall cci_datasource_borrow.

See also: cci_property_create, cci_property_destroy, cci_property_get, cci_property_set, cci_datasource_create, cci_datasource_destroy, cci_datasource_borrow, cci_datasource_change_property

Parameters

  • datasource: (IN) T_CCI_DATASOURCE struct pointer which returns CCI connection
  • conn: (IN) CCI connection handler identifier released
  • err_buf: (OUT) Error buffer(returns error code and error message when an error occurs)

Returns: Success: 1, Failure: 0

int cci_disconnect(int conn_handle, T_CCI_ERROR *err_buf)

The cci_disconnect function disconnects all request handles created for conn_handle. If a transaction is being performed, the handles are disconnected after cci_end_tran is executed.

  • CCI_ER_CON_HANDLE
  • CCI_ER_DBMS
  • CCI_ER_COMMUNICATION

Parameters

  • conn_handle: (IN) Connection handle
  • err_buf: (OUT) Database error buffer

Returns: Error code (0: success)

void cci_end(void)

The cci_end function is the counterpart of cci_init, kept for compatibility. It does nothing; close connections with cci_disconnect and data sources with cci_datasource_destroy.

int cci_get_cas_info (int conn_handle, char *info_buf, int buf_length, T_CCI_ERROR * err_buf)

Retrieve CAS information which is connected to conn_handle. The string of the below format is returned to the info_buf.

<host>:<port>,<cas id>,<cas process id>

The below is an example.

127.0.0.1:33000,1,12916

Through CAS ID, you can check the SQL log file of this CAS easily.

For details, see Checking SQL log.

  • CCI_ER_INVALID_ARGS
  • CCI_ER_CON_HANDLE

Parameters

  • conn_handle: (IN) connection handle
  • info_buf: (OUT) connection information buffer
  • buf_length: (IN) buffer length of the connection information
  • err_buf: (OUT) Error buffer

Returns: error code

int cci_get_db_version(int conn_handle, char *out_buf, int out_buf_size)

The cci_get_db_version function gets the Database Management System (DBMS) version.

  • CCI_ER_CON_HANDLE
  • CCI_ER_COMMUNICATION
  • CCI_ER_CONNECT

Parameters

  • conn_handle: (IN) Connection handle
  • out_buf: (OUT) Result buffer
  • out_buf_size: (IN) out_buf size

Returns: Error code (0: success)

int cci_get_dbms_type(int conn_handle)

The cci_get_dbms_type function returns the type of DBMS behind the broker of the connection, as reported by the broker when the connection was made: 1 for CoraDB. A negative value is an error code.

  • CCI_ER_CON_HANDLE

Parameters

  • conn_handle: (IN) Connection handle

Returns: DBMS type (1: CoraDB), or an error code

int cci_get_err_msg(int err_code, char *msg_buf, int msg_buf_size)

The cci_get_err_msg function stores error messages corresponding to the error code in the error message buffer. For details on error codes and error messages, see CCI error codes and error messages.

Functions that have an err_buf parameter also store their error in it, so the message can be printed from the buffer:

req = cci_prepare (con, query, 0, &err_buf);
if (req < 0)
{
printf ("error: %d, %s\n", err_buf.err_code, err_buf.err_msg);
goto handle_error;
}

For a function without err_buf, get the message with cci_get_err_msg; cci_get_error_msg combines both cases:

req = cci_prepare (con, query, 0, &err_buf);
if (req < 0)
{
char msg_buf[1024];
cci_get_error_msg (req, &err_buf, msg_buf, 1024);
printf ("error: %s\n", msg_buf);
goto handle_error;
}

Parameters

  • err_code: (IN) Error code
  • msg_buf: (OUT) Error message buffer
  • msg_buf_size: (IN) msg_buf size

Returns: 0: Success, -1: Failure

int cci_get_error_msg(int err_code, T_CCI_ERROR *err_buf, char *msg_buf, int msg_buf_size)

Saves the error messages corresponding to the CCI error codes in the message buffer. If the value of CCI error code is CCI_ER_DBMS, the database error buffer (err_buf) receives the error message sent from the data server and saves it in the message buffer(msg_buf). For details on error codes and messages, see CCI error codes and error messages.

Parameters

  • err_code: (IN) Error code
  • err_buf: (IN) Database error buffer
  • msg_buf: (OUT) Error message buffer
  • msg_buf_size: (IN) msg_buf size

Returns: 0: Success, -1: Failure

int cci_get_login_timeout(int conn_handle, int *timeout, T_CCI_ERROR *err_buf)

Return login timeout value to timeout.

  • CCI_ER_INVALID_ARGS
  • CCI_ER_CON_HANDLE
  • CCI_ER_USED_CONNECTION

Parameters

  • conn_handle: (IN) Connection handle
  • timeout: (OUT) A pointer to login timeout value(unit: millisecond)
  • err_buf: (OUT) Error buffer

Returns: Error code (0: success)

int cci_get_version_string(char *str, size_t len)

The cci_get_version_string function writes the full version string of the CCI library, including the build number (for example 1.0.1.0001-abcdef0), into str. cci_get_version returns only the major, minor and patch numbers.

Parameters

  • str: (OUT) Buffer that receives the version string
  • len: (IN) Size of str

Returns: 0

int cci_get_query_timeout (int req_handle)

The cci_get_query_timeout function returns timeout configured for query execution.

  • CCI_ER_REQ_HANDLE

Parameters

  • req_handle: (IN) Request handle

Returns: Success: Timeout value configured in current request handle (unit: msec.), Failure: Error code

int cci_get_version(int *major, int *minor, int *patch)

The cci_get_version function gets the version of the CCI library. For version 1.0.1, 1 is the major version, 0 the minor version and 1 the patch version. cci_get_version_string returns the full version string with the build number.

Parameters

  • major: (OUT) major version
  • minor: (OUT) minor version
  • patch: (OUT) patch version

Returns: Zero without exception (success)

void cci_init()

If you compile the CCI application program for Windows with static linking library(.lib), this function should be called always. In the other cases, this does not need to be called.

T_CCI_PROPERTIES * cci_property_create ()

The cci_property_create function creates T_CCI_PROPERTIES struct to configure DATASOURCE of CCI.

See also: cci_property_create, cci_property_destroy, cci_property_get, cci_property_set, cci_datasource_create, cci_datasource_destroy, cci_datasource_release

Returns: Success: T_CCI_PROPERTIES struct pointer in which memory is allocated, Failure: NULL

void cci_property_destroy (T_CCI_PROPERTIES * properties)

The cci_property_destroy function destroys T_CCI_PROPERTIES struct.

See also: cci_property_create, cci_property_destroy, cci_property_get, cci_property_set, cci_datasource_create, cci_datasource_destroy, cci_datasource_release

Parameters

  • properties: T_CCI_PROPERTIES struct pointer to be destroyed
char *cci_property_get (T_CCI_PROPERTIES * properties, char *key)

The cci_property_get function retrieves the property value configured in the T_CCI_PROPERTIES struct.

See also: cci_property_create, cci_property_destroy, cci_property_get, cci_property_set, cci_datasource_create, cci_datasource_destroy, cci_datasource_release

Parameters

  • properties: T_CCI_PROPERTIES struct pointer which gets value corresponding to key
  • key: Name of property to be retrieved (For name and description available properties, see the cci_property_set)

Returns: Success: String pointer of value corresponding to key, Failure: NULL

int cci_property_set (T_CCI_PROPERTIES *properties, char *key, char *value)

It configures a property value in T_CCI_PROPERTIES struct.

The property names and its meanings that can be configured in the struct are as follows:

Property name Type Default Description
user password url string string string DB user name. DB user password. Connection URL. For specifying connection URL string, see cci_connect_with_url.
pool_size int 10 Maximum number of connections which a connection pool can have.
max_pool_size int pool_size Total number of connections to create when creating an initial datasource. maximum value is INT_MAX.
max_wait msec 1000 Maximum waiting time to get connection.
pool_prepared_statement bool false Whether to enable statement pooling. true or false.
max_open_prepared_statement int 1000 The maximum number of prepared statements to maintain in the statement pool.
login_timeout msec 0(inf.) Login timeout applied when you create a datasource with cci_datasource_create function or internal timeout occurs in prepare/execute function.
query_timeout msec 0(inf.) Query timeout.
disconnect_on_query_timeout bool no Whether to terminate connection when execution is discarded due to query execution timeout. yes or no.
default_autocommit bool CCI_DEFAULT_AUTOCOMMIT in coradb_broker.conf Auto-commit mode specified when a datasource is created by cci_datasource_create function. true or false.
default_isolation string isolation_level in coradb.conf Transaction isolation level specified when a datasource is created by cci_datasource_create function. See the below table.
default_lock_timeout msec lock_timeout in coradb.conf Lock timeout specified when a datasource is created by cci_datasource_create function.

If the number of prepared statements exceeds max_open_prepared_statement value, the oldest prepared statement is released from the statement pool. If you reuse it later, it is added to the statement pool again.

A number of connections which a connection pool can contain is changeable by using cci_datasource_change_property function when it's required, but it cannot exceed max_pool_size. You can change this number when you want to handle the limitation of the number of connections. For example, usually set the number less than max_pool_size; raise the number when more connections are required than expected; shrink the number again when many connections are not required.

The number of connections which a connection pool can contain is limited until pool_size; it's maximum value is max_pool_size.

When you set login_timeout, default_autocommit, default_isolation or default_lock_timeout, these specified values are used in a connection which is returned when calling cci_datasource_borrow function.

login_timeout, default_autocommit, default_isolation or default_lock_timeout can be changed even after calling cci_datasource_borrow function. Regarding this, see cci_set_login_timeout, cci_set_autocommit, cci_set_isolation_level, cci_set_lock_timeout. Changed values by functions which the name starts with cci_set_ are only applied to the changed connection objects, and after the connection is released, they are restored as the specified values by cci_property_set. It is restored as the default value when there is no value specified by cci_property_set function.

default_isolation has one of the following configuration values. For details on isolation level, see SET TRANSACTION ISOLATION LEVEL.

isolation_level Configuration value
SERIALIZABLE "TRAN_SERIALIZABLE"
REPEATABLE READ "TRAN_REP_READ"
READ COMMITTED "TRAN_READ_COMMITTED"

DB user's name and password can be specified by the setting of user and password directly, or by the setting of user and password in url.

The following shows how to work as the first priority if both are specified.

  • If both are specified, the value of direct setting will be first.
  • If one of them is NULL, the value which is not NULL is used.
  • If both are NULL, they are used as NULL value.
  • If the direct setting value of DB user is NULL then "public" is used, else if the direct setting value of the password is NULL then NULL is used.
  • If the direct setting value of the password is NULL, it follows the setting of URL.

The following shows that the DB user's name becomes "dba" and the password becomes "coradbpwd".

cci_property_set(ps, "user", "dba");
cci_property_set(ps, "password", "coradbpwd");
...
cci_property_set(ps, "url", "cci:coradb:192.168.0.1:33000:e-commerce:public:mypwd:?logSlowQueries=true&slowQueryThresholdMillis=1000&logTraceApi=true&logTraceNetwork=true");

See also: cci_property_create, cci_property_destroy, cci_property_get, cci_property_set, cci_datasource_create, cci_datasource_destroy, cci_datasource_release

Parameters

  • properties: T_CCI_PROPERTIES struct pointer in which key and value are stored
  • key: String pointer of property name
  • value: String pointer of property value

Returns: Success: 1, Failure: 0

int cci_set_allocators(CCI_MALLOC_FUNCTION malloc_func, CCI_FREE_FUNCTION free_func, CCI_REALLOC_FUNCTION realloc_func, CCI_CALLOC_FUNCTION calloc_func)

The cci_set_allocators function registers the memory allocation/release functions used by users. By executing this function, you can use user-defined functions for every memory allocation/release jobs being processed in CCI API. If you do not use this function, system functions (malloc, free, realloc, and calloc) are used.

/*
How to build: gcc -Wall -g -o test_cci test_cci.c -I${CORADB}/include -L${CORADB}/lib -lcascci
*/
#include <stdio.h>
#include <stdlib.h>
#include "cas_cci.h"
void *my_malloc(size_t size)
{
printf ("my malloc: size: %ld\n", size);
return malloc (size);
}
void *my_calloc(size_t nm, size_t size)
{
printf ("my calloc: nm: %ld, size: %ld\n", nm, size);
return calloc (nm, size);
}
void *my_realloc(void *ptr, size_t size)
{
printf ("my realloc: ptr: %p, size: %ld\n", ptr, size);
return realloc (ptr, size);
}
void my_free(void *ptr)
{
printf ("my free: ptr: %p\n", ptr);
return free (ptr);
}
int test_simple (int con)
{
int req = 0, col_count = 0, i, ind;
int error;
char *data;
T_CCI_ERROR cci_error;
T_CCI_COL_INFO *col_info;
T_CCI_CORADB_STMT stmt_type;
char *query = "select * from db_class";
//preparing the SQL statement
req = cci_prepare (con, query, 0, &cci_error);
if (req < 0)
{
printf ("prepare error: %d, %s\n", cci_error.err_code,
cci_error.err_msg);
goto handle_error;
}
//getting column information when the prepared statement is the SELECT query
col_info = cci_get_result_info (req, &stmt_type, &col_count);
if (col_info == NULL)
{
printf ("get_result_info error\n");
goto handle_error;
}
//Executing the prepared SQL statement
error = cci_execute (req, 0, 0, &cci_error);
if (error < 0)
{
printf ("execute error: %d, %s\n", cci_error.err_code, cci_error.err_msg);
goto handle_error;
}
while (1)
{
//Moving the cursor to access a specific tuple of results
error = cci_cursor (req, 1, CCI_CURSOR_CURRENT, &cci_error);
if (error == CCI_ER_NO_MORE_DATA)
{
break;
}
if (error < 0)
{
printf ("cursor error: %d, %s\n", cci_error.err_code, cci_error.err_msg);
goto handle_error;
}
//Fetching the query result into a client buffer
error = cci_fetch (req, &cci_error);
if (error < 0)
{
printf ("fetch error: %d, %s\n", cci_error.err_code, cci_error.err_msg);
goto handle_error;
}
for (i = 1; i <= col_count; i++)
{
//Getting data from the fetched result
error = cci_get_data (req, i, CCI_A_TYPE_STR, &data, &ind);
if (error < 0)
{
printf ("get_data error: %d, %d\n", error, i);
goto handle_error;
}
printf ("%s\t|", data);
}
printf ("\n");
}
//Closing the query result
error = cci_close_query_result(req, &cci_error);
if (error < 0)
{
printf ("cci_close_query_result error: %d, %s\n", cci_error.err_code, cci_error.err_msg);
goto handle_error;
}
//Closing the request handle
error = cci_close_req_handle(req);
if (error < 0)
{
printf ("cci_close_req_handle error\n");
goto handle_error;
}
//Disconnecting with the server
error = cci_disconnect (con, &cci_error);
if (error < 0)
{
printf ("cci_disconnect error: %d, %s\n", cci_error.err_code, cci_error.err_msg);
goto handle_error;
}
return 0;
handle_error:
if (req > 0)
cci_close_req_handle (req);
if (con > 0)
cci_disconnect (con, &cci_error);
return 1;
}
int main()
{
int con = 0;
if (cci_set_allocators (my_malloc, my_free, my_realloc, my_calloc) != 0)
{
printf ("cannot register allocators\n");
return 1;
};
//getting a connection handle for a connection with a server
con = cci_connect ("localhost", 33000, "e-commerce", "dba", "");
if (con < 0)
{
printf ("cannot connect to database\n");
return 1;
}
test_simple (con);
return 0;
}

Parameters

  • malloc_func: (IN) Pointer of externally defined function corresponding to malloc
  • free_func: (IN) Pointer of externally defined function corresponding to free
  • realloc_func: (IN) Pointer of externally defined function corresponding to realloc
  • calloc_func: Pointer of externally defined function corresponding to calloc

Returns: Error code (0: success)

int cci_set_cas_change_mode(int conn_handle, int mode, T_CCI_ERROR *err_buf)

The cci_set_cas_change_mode function sets whether the broker may move the connection to another CAS between transactions (see KEEP_CONNECTION in Broker parameters):

  • CCI_CAS_CHANGE_MODE_AUTO: the connection can be served by another CAS after a transaction ends.
  • CCI_CAS_CHANGE_MODE_KEEP: the connection stays with the same CAS, for example to keep session state such as prepared statements or session variables.
  • CCI_ER_CON_HANDLE
  • CCI_ER_INVALID_ARGS (unknown mode)
  • CCI_ER_COMMUNICATION

Parameters

  • conn_handle: (IN) Connection handle
  • mode: (IN) CCI_CAS_CHANGE_MODE_AUTO or CCI_CAS_CHANGE_MODE_KEEP
  • err_buf: (OUT) Database error buffer

Returns: Error code (0: success)

int cci_set_charset(int conn_handle, char *charset)

The cci_set_charset function sets the charset in which CCI converts strings for the connection. It has an effect only on Windows; on other platforms it does nothing and returns 0.

  • CCI_ER_CON_HANDLE
  • CCI_ER_INVALID_ARGS (charset is NULL)

Parameters

  • conn_handle: (IN) Connection handle
  • charset: (IN) Charset name, for example "utf-8"

Returns: Error code (0: success)

int cci_set_login_timeout(int conn_handle, int timeout, T_CCI_ERROR *err_buf)

The cci_set_login_timeout function specifies the login timeout as milliseconds. The login timeout is applied when an internal reconnection occurs as cci_prepare or cci_execute function is called. This change is only applied to the current connection.

  • CCI_ER_CON_HANDLE
  • CCI_ER_USED_CONNECTION

Parameters

  • conn_handle: (IN) Connection handle
  • timeout: (IN) Login timeout(unit: milliseconds)
  • err_buf: (OUT) Error buffer

Returns: Error code(0: success)

int cci_set_query_timeout(int req_handle, int milli_sec)

The cci_set_query_timeout function configures timeout value for query execution.

  • CCI_ER_REQ_HANDLE

The timeout value configured by cci_set_query_timeout affects cci_prepare, cci_execute, cci_execute_array, cci_execute_batch functions. When timeout occurs in the function and if the disconnect_on_query_timeout value configured in cci_connect_with_url connection URL is yes, it returns the CCI_ER_QUERY_TIMEOUT error.

These functions can return the CCI_ER_LOGIN_TIMEOUT error if login_timeout is configured in the connection URL, which is an argument of cci_connect_with_url function; this means that login timeout happens between application client and CAS during re-connection.

It is going through the process of re-connection between application client and CAS when an application restarts or it is re-scheduled. Re-scheduling is a process that CAS chooses an application client, and starts and stops connection in the unit of transaction. If KEEP_CONNECTION, broker parameter, is OFF, it always happens; if AUTO, it can happen depending on its situation. For details, see the description of KEEP_CONNECTION in the Parameter by broker

Parameters

  • req_handle: (IN) Request handle
  • milli_sec: Timeout (unit: msec.)

Returns: Success: Request handle ID (int), Failure: Error code