Versions available for this page: CUBRID 8.2.1 | CUBRID 8.3.0 | CUBRID 8.3.1 | CUBRID 8.4.0 | CUBRID 8.4.1 | CUBRID 8.4.3 | CUBRID 9.0.0 |
The cci_bind_param function binds data in the bind variable of prepared statement. This function converts value of the given a_type to an actual binding type and stores it. Subsequently, whenever cci_execute() is called, the stored data is sent to the server. If cci_bind_param() is called multiple times for the same index, the latest configured value is valid.
If NULL is bound to the database, there can be two scenarios.
If CCI_BIND_PTR is configured for flag, the pointer of value variable is copied (shallow copy), but no value is copied. If it is not configured for flag, the value of value variable is copied (deep copy) by allocating memory. If multiple columns are bound by using the same memory buffer, CCI_BIND_PTR must not be configured for the flag.
T_CCI_A_TYPE is a C language type that is used in CCI applications for data binding, and consists of primitive types such as int and float, and user-defined types defined by CCI such as T_CCI_BIT and T_CCI_DATE. The identifier for each type is defined as shown in the table below.
|
a_type |
value type |
|---|---|
|
CCI_A_TYPE_STR |
char* |
|
CCI_A_TYPE_INT |
int* |
|
CCI_A_TYPE_FLOAT |
float* |
|
CCI_A_TYPE_DOUBLE |
double* |
|
CCI_A_TYPE_BIT |
T_CCI_BIT* |
|
CCI_A_TYPE_SET |
T_CCI_SET* |
|
CCI_A_TYPE_DATE |
T_CCI_DATE* |
|
CCI_A_TYPE_BIGINT |
int64_t* |
|
CCI_A_TYPE_BLOB |
T_CCI_BLOB |
|
CCI_A_TYPE_CLOB |
T_CCI_CLOB |
T_CCI_U_TYPE is a column type of database and data bound though the value argument is converted into this type. The cci_bind_param() function uses two kinds of types to send information which is used to convert U-type data from A-type data; the U-type data can be interpreted by database language and the A-type data can be interpreted by C language.
There are various A-type data that are allowed by U-type data. For example, CCI_U_TYPE_INT can receive CCI_A_TYPE_STR as A-type data including CCI_A_TYPE_INT. For information on type conversion, see "CUBRID SQL Guide > Data Types > Implicit Type Conversion > Rules."
Both T_CCI_A_TYPE and T_CCI_U_TYPE enum(s) are defined in the cas_cci.h file. The definition of each identifier is described in the table below.
|
u_type |
Corresponding a_type (default) |
|---|---|
|
CCI_U_TYPE_CHAR |
CCI_A_TYPE_STR |
|
CCI_U_TYPE_STRING |
CCI_A_TYPE_STR |
|
CCI_U_TYPE_NCHAR |
CCI_A_TYPE_STR |
|
CCI_U_TYPE_VARNCHAR |
CCI_A_TYPE_STR |
|
CCI_U_TYPE_BIT |
CCI_A_TYPE_BIT |
|
CCI_U_TYPE_VARBIT |
CCI_A_TYPE_BIT |
|
CCI_U_TYPE_NUMERIC |
CCI_A_TYPE_STR |
|
CCI_U_TYPE_INT |
CCI_A_TYPE_INT |
|
CCI_U_TYPE_SHORT |
CCI_A_TYPE_INT |
|
CCI_U_TYPE_MONETARY |
CCI_A_TYPE_DOUBLE |
|
CCI_U_TYPE_FLOAT |
CCI_A_TYPE_FLOAT |
|
CCI_U_TYPE_DOUBLE |
CCI_A_TYPE_DOUBLE |
|
CCI_U_TYPE_DATE |
CCI_A_TYPE_DATE |
|
CCI_U_TYPE_TIME |
CCI_A_TYPE_DATE |
|
CCI_U_TYPE_TIMESTAMP |
CCI_A_TYPE_DATE |
|
CCI_U_TYPE_OBJECT |
CCI_A_TYPE_STR |
|
CCI_U_TYPE_BIGINT |
CCI_A_TYPE_BIGINT |
|
CCI_U_TYPE_DATETIME |
CCI_A_TYPE_DATE |
|
CCI_U_TYPE_BLOB |
CCI_A_TYPE_BLOB |
|
CCI_U_TYPE_CLOB |
CCI_A_TYPE_CLOB |
When the string including the date is used as an input parameter of DATE, DATETIME, or TIMESTAMP, only "YYYY/MM/DD" is allowed for the date string format. Therefore, "2012/01/31" is valid, but "01/31/2012" or "2012-01-31" is invalid. The following is an example of having the string that includes the date as an input parameter of the date type.
// "CREATE TABLE tbl(aa date, bb datetime)";
char *values[][3] =
{
{"1994/11/30", "1994/11/30 20:08:08"},
{"2008/10/31", "2008/10/31 20:08:08"}
};
req = cci_prepare(conn, "insert into tbl (aa, bb) values ( ?, ?)", CCI_PREPARE_INCLUDE_OID, &error);
for(i=0; i< 2; i++)
{
res = cci_bind_param(req, 1, CCI_A_TYPE_STR, values[i][0], CCI_U_TYPE_DATE, (char)NULL);
res = cci_bind_param(req, 2, CCI_A_TYPE_STR, values[i][1], CCI_U_TYPE_DATETIME, (char)NULL);
cci_execute(req, CCI_EXEC_QUERY_ALL, 0, err_buf);
…
int cci_bind_param(int req_handle, int index, T_CCI_A_TYPE a_type, void *value, T_CCI_U_TYPE u_type, char flag)