00001
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 #include "examples.h"
00005
00006
00007 int insert_into_blob_table(sqlo_db_handle_t dbh, int key )
00008 {
00009 char * stmt =
00010 "INSERT INTO T_SQLORA_BLOB (KEY, CDATA) "
00011 "VALUES (:b1, EMPTY_CLOB()) RETURNING CDATA INTO :b2";
00012
00013 char data[MAX_BLOB_BUFFER_DATA];
00014 sqlo_lob_desc_t loblp;
00015 sqlo_stmt_handle_t sth;
00016 int status;
00017 int k = key;
00018
00019 printf("Insert CLOB\n");
00020
00021
00022 create_blob_table(dbh);
00023
00024
00025 fillbuf(data, MAX_BLOB_BUFFER_DATA);
00026
00027
00028
00029 if (0>(sth = sqlo_prepare(dbh, stmt)))
00030 error_exit(dbh, "sqlo_prepare");
00031
00032
00033 if (0 > sqlo_alloc_lob_desc(dbh, &loblp))
00034 error_exit(dbh, "sqlo_alloc_lob_desc");
00035
00036
00037 if (SQLO_SUCCESS !=
00038 (sqlo_bind_by_pos(sth, 1, SQLOT_INT, &k, sizeof(int), NULL, 0)) ||
00039 (sqlo_bind_by_pos(sth, 2, SQLOT_CLOB, &loblp, 0, NULL, 0))
00040 ) {
00041 sqlo_free_lob_desc(dbh, &loblp);
00042 error_exit(dbh, "sqlo_bind_by_pos");
00043 }
00044
00045
00046 status = sqlo_execute(sth, 1);
00047
00048 if (SQLO_SUCCESS != status) {
00049 sqlo_free_lob_desc(dbh, &loblp);
00050 error_exit(dbh, "sqlo_execute");
00051 }
00052
00053
00054 status = sqlo_lob_write_buffer(dbh, loblp, MAX_BLOB_BUFFER_DATA, data,
00055 MAX_BLOB_BUFFER_DATA, SQLO_ONE_PIECE);
00056
00057 if (status < 0) {
00058 sqlo_free_lob_desc(dbh, &loblp);
00059 error_exit(dbh, "sqlo_log_write_buffer");
00060 }
00061
00062 sqlo_free_lob_desc(dbh, &loblp);
00063 sqlo_close(sth);
00064
00065 return (1);
00066 }
00067
00068 void create_blob_table(sqlo_db_handle_t dbh)
00069 {
00070 char * stmt=
00071 "CREATE TABLE T_SQLORA_BLOB (KEY INTEGER, CDATA CLOB, BDATA BLOB)";
00072
00073 if (SQLO_SUCCESS != sqlo_exec(dbh, stmt))
00074 if (sqlo_geterrcode(dbh) != 955)
00075 error_exit(dbh, "sqlo_exec");
00076 }
00077
00078 void drop_blob_table(sqlo_db_handle_t dbh)
00079 {
00080 char * stmt = "DROP TABLE T_SQLORA_BLOB";
00081
00082 if (SQLO_SUCCESS != sqlo_exec(dbh, stmt))
00083 error_exit(dbh, "sqlo_exec");
00084 }
00085
00086 void fillbuf(char * data, int len)
00087 {
00088 int i;
00089 for (i = 0; i < len; ++i) {
00090 data[i] = 'A' + i % 26;
00091 }
00092 }
00093
00094