Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Versions available for this page: CUBRID 8.3.1 |  CUBRID 8.4.0 |  CUBRID 8.4.1 | 



Using BLOB/CLOB with CCI

Storing LOB Data

You can create LOB data file and bind the data by using the following functions in CCI applications.

Example 1

int con = 0; /* connection handle */

int req = 0; /* request handle */

int res;

int n_executed;

int i;

T_CCI_ERROR error;

T_CCI_BLOB blob = NULL;

char data[1024] = “bulabula”;

 

con = cci_connect ("localhost", 33000, “tdb", "PUBLIC", "");

if (con < 0) {

goto handle_error;

}

req = cci_prepare (con, “insert into doc (doc_id, content) values (?,?)”, 0, &error);

if (req< 0)

{

goto handle_error;

}

 

res = cci_bind_param (req, 1 /* binding index*/, CCI_A_TYPE_STR, “doc-10”, &ind, CCI_U_TYPE_STRING);

 

/* Creating an empty LOB data file

res = cci_blob_new (con, &blob, &error);

res = cci_blob_write (con, blob, 0 /* start position */, 1024 /* length */, data, &error);

 

/* Binding BLOB data */

res = cci_bind_param (req, 2 /* binding index*/, CCI_A_TYPE_BLOB, (void *)blob, CCI_U_TYPE_BLOB, CCI_BIND_PTR);

 

n_executed = cci_execute (req, 0, 0, &error);

if (n_executed < 0)

{

goto handle_error

}

 

/* Memory free */

cci_blob_free(blob);

return 0;

 

handle_error:

if (blob != NULL)

{

cci_blob_free(blob);

}

if (req > 0)

{

cci_close_req_handle (req);

}

if (con > 0)

{

cci_disconnect(con, &error);

}

return -1;

Getting LOB Data
Description

You can get LOB data by using the following functions in CCI applications. Note that if you enter data in LOB type colulmn, the actual LOB data is stored externally and Locator value referring to the file is stored in LOB type column itself. Therefore, you must call the cci_blob_read() function (not the cci_get_data() function) to get LOB data stored in the file.

  • Getting LOB type column meta data (Locator) (related function : cci_get_data( ))
  • Getting LOB data (related function : cci_blob_read( ))
  • Freeing memory of LOB structure (related function : cci_blob_free( ))
Example

int con = 0; /* connection handle */

int req = 0; /* request handle */

int ind; /* NULL indicator, 0 if not NULL, -1 if NULL*/

int res;

int i;

T_CCI_ERROR error;

T_CCI_BLOB blob;

char buffer[1024];

 

con = cci_connect ("localhost", 33000, "image_db", "PUBLIC", "");

if (con < 0)

 {

  goto handle_error;

 }

req = cci_prepare (con, "select content from doc_t", 0 /*flag*/, &error);

if (req< 0)

 {

  goto handle_error;

 }

res = cci_execute (req, 0/*flag*/, 0/*max_col_size*/, &error);

res = cci_fetch_size (req, 100 /* fetch size */);

 

while (1) {

  res = cci_cursor (req, 1/* offset */, CCI_CURSOR_CURRENT/* cursor position */, &error);

  if (res == CCI_ER_NO_MORE_DATA)

     {

      break;

     }

  res = cci_fetch (req, &error);

 

/* Fetching CLOB Locator */

  res = cci_get_data (req, 1 /* colume index */, CCI_A_TYPE_BLOB,

        (void *)&blob /* BLOB handle */, &ind /* NULL indicator */);

 

/* Fetching CLOB data */

res = cci_blob_read (con, blob, 0 /* start position */, 1024 /* length */, buffer, &error);

printf ("content = %s ", buffer);

}

/* Memory free */

cci_blob_free(blob);

res=cci_close_req_handle(req);

res = cci_disconnect (con, &error);

return 0;

 

handle_error:

if (req > 0)

    {

     cci_close_req_handle (req);

    }

if (con > 0)

   {

     cci_disconnect(con, &error);

   }

return -1;