Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

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 | 

cci_execute_batch

Description

In CCI, multiple jobs can be processed simultaneously when using DML queries such as INSERT/UPDATE/DELETE. cci_execute_arrary() and cci_execute_batch() functions can be used to execute such batch jobs. Note that prepared statements cannot be used in the cci_execute_batch() function. The query result will be stored on the array of T_CCI_QUERY_RESULT structures.

Executes sql_stmt as many times as num_sql_stmt specified as a parameter and returns the number of queries executed with the query_result variable. You can use CCI_QUERY_RESULT_RESULT, CCI_QUERY_RESULT_ERR_MSG, and CCI_QUERY_RESULT_STMT_TYPE macros to get result of each query. Regarding the summary of these macros, see cci_execute_array().

Note that the validity check is not performed for each parameter entered in the macro. After using the query_result variable, you must delete the query result by using the cci_query_result_free() function.

If autocommit mode is on, each query in the array is committed after executing.

Caution In the previous version of 2008 R4.3, if the autocommit is on, all queries in the array were committed after all of them are executed.

Syntax

int cci_execute_batch(int conn_handle, int num_sql_stmt, char **sql_stmt, T_CCI_QUERY_RESULT **query_result, T_CCI_ERROR *err_buf)

  • conn_handle: (IN) Connection handle
  • num_sql_stmt: (IN) The number of sql_stmt
  • sql_stmt: (IN) SQL statement array
  • query_result: (OUT) The results of sql_stmt
  • err_buf: (OUT) Database error buffer
Return Value
  • Success: The number of executed queries
  • Failure: Negative number
Error Code
  • CCI_ER_CON_HANDLE
  • CCI_ER_DBMS
  • CCI_ER_COMMUNICATION
  • CCI_ER_NO_MORE_MEMORY
  • CCI_ER_CONNECT
  • CCI_ER_QUERY_TIMEOUT
  • CCI_ER_LOGIN_TIMEOUT
Example

char **queries;

  T_CCI_QUERY_RESULT *result;

  int n_queries, n_executed;

...

 

  count = 3;

  queries = (char **) malloc (count * sizeof (char *));

  queries[0] =

    "insert into athlete(name, gender, nation_code, event) values('Ji-sung Park', 'M', 'KOR', 'Soccer')";

  queries[1] =

    "insert into athlete(name, gender, nation_code, event) values('Joo-young Park', 'M', 'KOR', 'Soccer')";

  queries[2] =

    "select * from athlete order by code desc for orderby_num() < 3";

//calling cci_execute_batch()

  n_executed = cci_execute_batch (con, count, queries, &result, &cci_error);

  if (n_executed < 0)

    {

      printf ("execute_batch: %d, %s ", cci_error.err_code,

              cci_error.err_msg);

      goto handle_error;

    }

  printf ("%d statements were executed. ", n_executed);

 

  for (i = 1; i <= n_executed; i++)

    {

      printf ("query %d ", i);

      printf ("result count = %d ", CCI_QUERY_RESULT_RESULT (result, i));

      printf ("error message = %s ", CCI_QUERY_RESULT_ERR_MSG (result, i));

      printf ("statement type = %d ",

              CCI_QUERY_RESULT_STMT_TYPE (result, i));

    }

 

  error = cci_query_result_free (result, n_executed);

  if (error < 0)                                                                                                                            

    {                                                                                                                                       

      printf ("query_result_free: %d ", error);   

      goto handle_error;

    }