Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Versions available for this page: CUBRID 8.2.1 |  CUBRID 8.3.0 | 

cci_glo_new

Description

This function is used to create a glo object in a glo class of class_name with filename. It loads a glo column to a file or specifies a file name in the filename where data is stored. If filename is NULL, only the glo object is created (cci 2.3 or higher).

Syntax

intcci_glo_new(int conn_handle, char *class_name, char *filename, char *oid_str, T_CCI_ERROR *err_buf)

  • conn_handle : (IN) Connection handle
  • class_name : (IN) glo class name
  • filename : (IN) Source file
  • oid_str : (OUT) glo object (OID string)
  • err_buf : (OUT) Database error buffer
Return Value
  • Error code (0 : success, negative number : failure)
Example 1

cci_glo_new(), cci_glo_save() and cci_glo_load() functions are used by default to use the glo data type in CCI. The following is an example that saves the a.out file to the photo column as a glo object in the person table with the name column of string type and the photo column of glo type.

#include <stdio.h>

#include <stdlib.h>

#include <error.h>

#include <fcntl.h>

#include <sys/types.h>

#include <sys/stat.h>

 

#include "cas_cci.h"

 

extern int errno;

 

int main() {

    char oid_str[24] = {0x00};

    char *query = "insert into person(name, photo) values(?,?);";

    char *i_filename = "a.out";

 

    int con, ret, req;

    int fd = -1;

    T_CCI_ERROR err_buf;

 

    con = ret = req = 0;

 

    con = cci_connect("localhost", 30000, "testdb", "dba", "");

    if (con < 0){

        printf("%d:%s\n", err_buf.err_code, err_buf.err_msg);

        return -1;

    }

 

    // Getting OID values from "glo" table

    ret = cci_glo_new(con, "glo", i_filename, oid_str, &err_buf);

    if (ret < 0){

        printf("%d:%s\n", err_buf.err_code, err_buf.err_msg);

        cci_disconnect(con, &err_buf);

        return -1;

    }

 

    req = cci_prepare(con, query, CCI_PREPARE_INCLUDE_OID, &err_buf);

    if (req < 0) {

        printf("%d:%s\n", err_buf.err_code, err_buf.err_msg);

        cci_disconnect(con, &err_buf);

        return -1;

    }

 

    ret = cci_bind_param(req, 1, CCI_A_TYPE_STR, i_filename, CCI_U_TYPE_CHAR, (char)NULL);

    if (ret < 0) {

        printf("%d:%s\n", err_buf.err_code, err_buf.err_msg);

 

        cci_disconnect(con, &err_buf);

        return -1;

    }

 

    // Binding OID values

    ret = cci_bind_param(req, 2, CCI_A_TYPE_STR, oid_str, CCI_U_TYPE_OBJECT, (char)NULL);

    if (ret < 0) {

        printf("%d:%s\n", err_buf.err_code, err_buf.err_msg);

        cci_disconnect(con, &err_buf);

        return -1;

    }

    ret = cci_execute(req, 0, 0, &err_buf);

    if (ret < 0) {

        printf("%d:%s\n", err_buf.err_code, err_buf.err_msg);

        cci_disconnect(con, &err_buf);

        return -1;

    }

 

    ret = cci_end_tran(con, CCI_TRAN_COMMIT, &err_buf);

    if (ret < 0) {

        printf("%d:%s\n", err_buf.err_code, err_buf.err_msg);

        cci_disconnect(con, &err_buf);

        return -1;

    }

 

    cci_disconnect(con, &err_buf);

 

    return 1;

}

Example 2

The following is an example in which the data saved in the database is copied to b.out in the file system through CCI.

#include <stdio.h>

#include <stdlib.h>

#include <error.h>

#include <fcntl.h>

#include <sys/types.h>

#include <sys/stat.h>

 

#include "cas_cci.h"

 

extern int errno;

 

int main() {

    char *oid_str;

    char *query = "select photo from person where name = 'a.out'";

    char *o_filename = "b.out";

    int con, ret, req, ind;

    int fd = -1;

    T_CCI_ERROR err_buf;

 

    con = ret = req = 0;

 

    con = cci_connect("localhost", 30000, "testdb", "dba", "");

    if (con < 0){

        printf("%d:%s\n", err_buf.err_code, err_buf.err_msg);

        return -1;

    }

 

    req = cci_prepare(con, query, CCI_PREPARE_INCLUDE_OID, &err_buf);

    if (req < 0) {

        printf("%d:%s\n", err_buf.err_code, err_buf.err_msg);

        cci_disconnect(con, &err_buf);

        return -1;

    }

 

    ret = cci_execute(req, 0, 0, &err_buf);

    if (ret < 0) {

        printf("%d:%s\n", err_buf.err_code, err_buf.err_msg);

        cci_disconnect(con, &err_buf);

        return -1;

    }

 

    ret = cci_cursor(req, 1, CCI_CURSOR_CURRENT, &err_buf);

    if (ret < 0) {

        printf("%d:%s\n", err_buf.err_code, err_buf.err_msg);

        cci_disconnect(con, &err_buf);

        return -1;

    }

 

    ret = cci_fetch(req, &err_buf);

    if (ret < 0) {

        printf("%d:%s\n", err_buf.err_code, err_buf.err_msg);

        cci_disconnect(con, &err_buf);

        return -1;

    }

    ret = cci_get_data(req, 1, CCI_A_TYPE_STR, &oid_str, &ind);

    if (ret < 0) {

        printf("%d:%s\n", err_buf.err_code, err_buf.err_msg);

        cci_disconnect(con, &err_buf);

        return -1;

    }

 

    // opening b.out

    fd = open(o_filename, O_CREAT | O_RDWR | O_TRUNC);

    if (fd < 0) {

        perror(o_filename);

        return -1;

    }

 

    // copying glo data from database to the fd

    ret = cci_glo_load(con, oid_str, fd, &err_buf);

    if (ret < 0) {

        printf("%d:%s\n", err_buf.err_code, err_buf.err_msg);

        printf("TDBG : %s:%d \n", __FILE__, __LINE__);

        cci_disconnect(con, &err_buf);

        close(fd);

        return -1;

    }

    close(fd);

 

    ret = cci_end_tran(con, CCI_TRAN_COMMIT, &err_buf);

    if (ret < 0) {

        printf("%d:%s\n", err_buf.err_code, err_buf.err_msg);

        cci_disconnect(con, &err_buf);

        return -1;

    }

    cci_close_req_handle(req);

    cci_disconnect(con, &err_buf);

 

    return 1;

}