1
/* Copyright (C) 2005 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; either version 2 of the License, or
6
(at your option) any later version.
8
This program is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License
14
along with this program; if not, write to the Free Software
15
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31
#include "sb_options.h"
32
#include "db_driver.h"
35
/* Number of rows to prefetch for result sets */
36
#define ORA_DRV_PREFETCH_COUNT 1000
38
#define CHECKERR(stmt) \
40
if (rc != OCI_SUCCESS) \
42
log_text(LOG_FATAL, "%s failed in %s:%d", stmt, __FILE__, __LINE__); \
43
checkerr(ora_con->errhp, rc); \
48
static sb_arg_t ora_drv_args[] =
50
{"oracle-user", "Oracle user", SB_ARG_TYPE_STRING, "sbtest"},
51
{"oracle-password", "Oracle password", SB_ARG_TYPE_STRING, ""},
52
{"oracle-db", "Oracle database name", SB_ARG_TYPE_STRING, "sbtest"},
54
{NULL, NULL, SB_ARG_TYPE_NULL, NULL}
96
sb_list_item_t listitem;
108
sb_list_item_t listitem;
126
/* Structure used for DB-to-Oracle bind types map */
130
db_bind_type_t db_type;
133
} db_oracle_bind_map_t;
135
/* DB-to-Oracle bind types map */
136
db_oracle_bind_map_t db_oracle_bind_map[] =
139
{DB_TYPE_TINYINT, SQLT_INT, sizeof(char)},
140
{DB_TYPE_SMALLINT, SQLT_INT, sizeof(short)},
141
{DB_TYPE_INT, SQLT_INT, sizeof(int)} ,
142
{DB_TYPE_BIGINT, SQLT_INT, sizeof(long long)},
143
{DB_TYPE_FLOAT, SQLT_FLT, sizeof(float)},
144
{DB_TYPE_DOUBLE, SQLT_FLT, sizeof(double)},
145
{DB_TYPE_DATETIME, SQLT_DATE, sizeof(void *)},
146
{DB_TYPE_TIMESTAMP, SQLT_TIMESTAMP, sizeof(void *)},
147
{DB_TYPE_CHAR, SQLT_AFC, 0},
148
{DB_TYPE_VARCHAR, SQLT_VCS, 0},
152
/* Oracle driver capabilities */
154
static drv_caps_t ora_drv_caps =
156
.multi_rows_insert = 0,
158
.prepared_statements = 1,
160
.table_options_str = NULL
164
static OCIEnv *ora_env; /* OCI environmental handle */
166
static ora_drv_args_t args; /* driver args */
168
/* Oracle driver operations */
170
static int ora_drv_init(void);
171
static int ora_drv_describe(drv_caps_t *, const char *);
172
static int ora_drv_connect(db_conn_t *);
173
static int ora_drv_disconnect(db_conn_t *);
174
static int ora_drv_prepare(db_stmt_t *, const char *);
175
static int ora_drv_bind_param(db_stmt_t *, db_bind_t *, unsigned int);
176
static int ora_drv_bind_result(db_stmt_t *, db_bind_t *, unsigned int);
177
static int ora_drv_execute(db_stmt_t *, db_result_set_t *);
178
static int ora_drv_fetch(db_result_set_t *);
179
static int ora_drv_fetch_row(db_result_set_t *, db_row_t *);
180
static unsigned long long ora_drv_num_rows(db_result_set_t *);
181
static int ora_drv_query(db_conn_t *, const char *, db_result_set_t *);
182
static int ora_drv_free_results(db_result_set_t *);
183
static int ora_drv_close(db_stmt_t *);
184
static int ora_drv_store_results(db_result_set_t *);
185
static int ora_drv_done(void);
187
/* Oracle driver definition */
189
static db_driver_t oracle_driver =
192
.lname = "Oracle driver",
193
.args = ora_drv_args,
207
ora_drv_free_results,
210
ora_drv_store_results,
213
.listitem = {NULL, NULL}
217
/* Local functions */
219
static sword get_oracle_bind_type(db_bind_t *, ub2 *, sb4 *, sb2 *);
220
static sb4 get_oracle_type_size(sword);
221
static ora_stmt_type_t get_stmt_type(const char *);
222
static void checkerr(OCIError *, sword);
224
/* Register Oracle driver */
227
int register_driver_oracle(sb_list_t *drivers)
229
SB_LIST_ADD_TAIL(&oracle_driver.listitem, drivers);
235
/* Oracle driver initialization */
238
int ora_drv_init(void)
242
args.user = sb_get_value_string("oracle-user");
243
args.password = sb_get_value_string("oracle-password");
244
args.db = sb_get_value_string("oracle-db");
246
/* Initialize the environment */
247
rc = OCIEnvCreate(&ora_env, OCI_THREADED | OCI_OBJECT, NULL, NULL, NULL, NULL,
249
if (rc != OCI_SUCCESS || ora_env == NULL)
251
log_text(LOG_FATAL, "OCIEnvCreate failed!");
259
/* Describe database capabilities */
262
int ora_drv_describe(drv_caps_t *caps, const char * table_name)
265
*caps = ora_drv_caps;
271
/* Connect to the database */
274
int ora_drv_connect(db_conn_t *sb_conn)
277
ora_conn_t *ora_con = NULL;
279
ora_con = (ora_conn_t *)malloc(sizeof(ora_conn_t));
283
/* Allocate a service handle */
284
rc = OCIHandleAlloc(ora_env, (dvoid **)&(ora_con->svchp), OCI_HTYPE_SVCCTX, 0,
286
if (rc != OCI_SUCCESS)
288
log_text(LOG_FATAL, "OCIHandleAlloc (OCI_HTYPE_SVCCTX) failed");
292
/* Allocate an error handle */
293
rc = OCIHandleAlloc(ora_env, (dvoid **)&(ora_con->errhp), OCI_HTYPE_ERROR, 0,
295
if (rc != OCI_SUCCESS)
297
log_text(LOG_FATAL, "OCIHandleAlloc (OCI_HTYPE_ERROR) failed");
301
/* Allocate an server handle */
302
rc = OCIHandleAlloc(ora_env, (dvoid **)&(ora_con->srvhp), OCI_HTYPE_SERVER, 0,
304
CHECKERR("OCIHandleAlloc");
306
/* Allocate a user session handle */
307
rc = OCIHandleAlloc(ora_env, (dvoid **)&(ora_con->usrhp), OCI_HTYPE_SESSION, 0,
309
CHECKERR("OCIHandleAlloc");
311
/* Attach to the server */
312
rc = OCIServerAttach(ora_con->srvhp, ora_con->errhp, args.db, strlen(args.db),
314
CHECKERR("OCIServerAttach");
316
/* Set the server attribute in the service context handler */
317
rc = OCIAttrSet(ora_con->svchp, OCI_HTYPE_SVCCTX, ora_con->srvhp, 0,
318
OCI_ATTR_SERVER, ora_con->errhp);
319
CHECKERR("OCIAttrSet");
321
/* Set the user name attribute in the user session handler */
322
rc = OCIAttrSet(ora_con->usrhp, OCI_HTYPE_SESSION, args.user,
323
strlen(args.user), OCI_ATTR_USERNAME, ora_con->errhp);
324
CHECKERR("OCIAttrSet");
326
/* Set the password attribute in the user session handler */
327
rc = OCIAttrSet(ora_con->usrhp, OCI_HTYPE_SESSION, args.password,
328
strlen(args.password), OCI_ATTR_PASSWORD, ora_con->errhp);
329
CHECKERR("OCIAttrSet");
331
/* Allocate the transaction handle and set it to service context */
332
rc = OCIHandleAlloc(ora_env, (dvoid **)&(ora_con->transhp), OCI_HTYPE_TRANS, 0,
334
CHECKERR("OCIHandleAlloc");
335
rc = OCIAttrSet(ora_con->svchp, OCI_HTYPE_SVCCTX, ora_con->transhp, 0,
336
OCI_ATTR_TRANS, ora_con->errhp);
337
CHECKERR("OCIAttrSet");
339
/* Start the session */
340
rc = OCISessionBegin (ora_con->svchp, ora_con->errhp, ora_con->usrhp,
341
OCI_CRED_RDBMS, OCI_DEFAULT);
342
CHECKERR("OCISessionBegin");
344
/* Set the user session attribute in the service context handler */
345
rc = OCIAttrSet(ora_con->svchp, OCI_HTYPE_SVCCTX, ora_con->usrhp, 0,
346
OCI_ATTR_SESSION, ora_con->errhp);
347
CHECKERR("OCIAttrSet");
349
sb_conn->ptr = ora_con;
361
/* Disconnect from database */
364
int ora_drv_disconnect(db_conn_t *sb_conn)
366
ora_conn_t *con = sb_conn->ptr;
373
rc = OCISessionEnd(con->svchp, con->errhp, con->usrhp, 0);
374
if (rc != OCI_SUCCESS)
376
log_text(LOG_FATAL, "OCISessionEnd failed");
380
rc = OCIServerDetach(con->srvhp, con->errhp, OCI_DEFAULT);
381
if (rc != OCI_SUCCESS)
383
log_text(LOG_FATAL, "OCIServerDetach failed");
389
if (OCIHandleFree(con->usrhp, OCI_HTYPE_SESSION) != OCI_SUCCESS)
391
if (OCIHandleFree(con->srvhp, OCI_HTYPE_SERVER) != OCI_SUCCESS)
393
if (OCIHandleFree(con->svchp, OCI_HTYPE_SVCCTX) != OCI_SUCCESS)
395
if (OCIHandleFree(con->errhp, OCI_HTYPE_ERROR) != OCI_SUCCESS)
404
/* Prepare statement */
407
int ora_drv_prepare(db_stmt_t *stmt, const char *query)
409
ora_conn_t *ora_con = (ora_conn_t *)stmt->connection->ptr;
411
ora_stmt_t *ora_stmt = NULL;
414
unsigned int need_realloc;
418
ub4 prefetch_cnt = ORA_DRV_PREFETCH_COUNT;
423
if (db_globals.ps_mode != DB_PS_MODE_DISABLE)
425
ora_stmt = (ora_stmt_t *)calloc(1, sizeof(ora_stmt_t));
426
if (ora_stmt == NULL)
429
rc = OCIHandleAlloc(ora_env, (dvoid **)&(ora_stmt->ptr), OCI_HTYPE_STMT, 0,
431
if (rc != OCI_SUCCESS)
434
/* Convert query to Oracle-style named placeholders */
438
for (i = 0, j = 0; query[i] != '\0'; i++)
441
if (j+1 >= buflen || need_realloc)
443
buflen = (buflen > 0) ? buflen * 2 : 256;
444
buf = realloc(buf, buflen);
456
n = snprintf(buf + j, buflen - j, ":%d", vcnt);
457
if (n < 0 || n >= (int)(buflen - j))
468
ora_stmt->type = get_stmt_type(buf);
470
if (ora_stmt->type != STMT_TYPE_BEGIN &&
471
ora_stmt->type != STMT_TYPE_COMMIT)
473
rc = OCIStmtPrepare(ora_stmt->ptr, ora_con->errhp, buf, strlen(buf),
474
OCI_NTV_SYNTAX, OCI_DEFAULT);
475
CHECKERR("OCIStmtPrepare");
477
rc = OCIAttrSet(ora_stmt->ptr, OCI_HTYPE_STMT, &prefetch_cnt, 0,
478
OCI_ATTR_PREFETCH_ROWS, ora_con->errhp);
479
CHECKERR("OCIAttrSet");
484
stmt->ptr = (void *)ora_stmt;
488
/* Use client-side PS */
491
stmt->query = strdup(query);
496
if (ora_stmt != NULL)
498
if (ora_stmt->ptr != NULL)
499
OCIHandleFree(ora_stmt->ptr, OCI_HTYPE_STMT);
503
log_text(LOG_FATAL, "Failed to prepare statement: '%s'", query);
509
/* Bind parameters for prepared statement */
512
int ora_drv_bind_param(db_stmt_t *stmt, db_bind_t *params, unsigned int len)
514
ora_conn_t *con = (ora_conn_t *)stmt->connection->ptr;
515
ora_stmt_t *ora_stmt = (ora_stmt_t *)stmt->ptr;
527
if (ora_stmt == NULL || ora_stmt->ptr == NULL)
530
if (ora_stmt->params != NULL)
531
free(ora_stmt->params);
532
ora_stmt->params = (ora_bind_t *)malloc(len * sizeof(ora_bind_t));
533
if (ora_stmt->params == NULL)
536
/* Convert SysBench bind structures to Oracle ones */
538
for (i = 0; i < len; i++)
540
if (get_oracle_bind_type(params+i, &dtype, &dlen,
541
&ora_stmt->params[i].ind))
543
free(ora_stmt->params);
544
ora_stmt->params = NULL;
548
rc = OCIBindByPos(ora_stmt->ptr, &bindp, con->errhp, i+1, params[i].buffer,
549
dlen, dtype, (dvoid *)&ora_stmt->params[i].ind, NULL,
550
NULL, 0, NULL, OCI_DEFAULT);
551
if (rc != OCI_SUCCESS)
553
log_text(LOG_FATAL, "OCIBindByPos failed");
554
free(ora_stmt->params);
555
ora_stmt->params = NULL;
564
if (stmt->bound_param != NULL)
565
free(stmt->bound_param);
566
stmt->bound_param = (db_bind_t *)malloc(len * sizeof(db_bind_t));
567
if (stmt->bound_param == NULL)
569
memcpy(stmt->bound_param, params, len * sizeof(db_bind_t));
570
stmt->bound_param_len = len;
576
/* Bind results for prepared statement */
579
int ora_drv_bind_result(db_stmt_t *stmt, db_bind_t *params, unsigned int len)
591
/* Execute prepared statement */
594
int ora_drv_execute(db_stmt_t *stmt, db_result_set_t *rs)
596
db_conn_t *db_con = stmt->connection;
597
ora_stmt_t *ora_stmt = stmt->ptr;
601
unsigned int buflen = 0;
602
unsigned int i, j, vcnt;
607
(void)rs; /* unused */
610
return SB_DB_ERROR_FAILED;
611
ora_con = db_con->ptr;
613
return SB_DB_ERROR_FAILED;
617
if (stmt->ptr == NULL)
618
return SB_DB_ERROR_FAILED;
620
if (ora_stmt->type == STMT_TYPE_BEGIN)
622
rc = OCITransStart(ora_con->svchp, ora_con->errhp, 3600, OCI_TRANS_NEW);
623
CHECKERR("OCITransStart");
625
return SB_DB_ERROR_NONE;
627
else if (ora_stmt->type == STMT_TYPE_COMMIT)
629
rc = OCITransCommit(ora_con->svchp, ora_con->errhp, OCI_DEFAULT);
630
CHECKERR("OCITransCommit");
632
return SB_DB_ERROR_NONE;
634
else if (ora_stmt->type == STMT_TYPE_SELECT)
639
rc = OCIStmtExecute(ora_con->svchp, ora_stmt->ptr, ora_con->errhp, iters, 0,
640
NULL, NULL, OCI_DEFAULT);
641
CHECKERR("OCIStmtExecute");
643
return SB_DB_ERROR_NONE;
646
/* Build the actual query string from parameters list */
649
for (i = 0, j = 0; stmt->query[i] != '\0'; i++)
652
if (j+1 >= buflen || need_realloc)
654
buflen = (buflen > 0) ? buflen * 2 : 256;
655
buf = realloc(buf, buflen);
658
return SB_DB_ERROR_FAILED;
663
if (stmt->query[i] != '?')
665
buf[j++] = stmt->query[i];
669
n = db_print_value(stmt->bound_param + vcnt, buf + j, buflen - j);
680
db_con->db_errno = ora_drv_query(db_con, buf, rs);
683
return SB_DB_ERROR_NONE;
686
log_text(LOG_FATAL, "failed query was: '%s'", stmt->query);
688
return SB_DB_ERROR_FAILED;
692
/* Execute SQL query */
695
int ora_drv_query(db_conn_t *sb_conn, const char *query,
698
ora_conn_t *ora_con = sb_conn->ptr;
702
ora_stmt_type_t type;
703
OCIStmt *stmt = NULL;
705
(void)rs; /* unused */
707
type = get_stmt_type(query);
709
if (type == STMT_TYPE_BEGIN)
711
rc = OCITransStart(ora_con->svchp, ora_con->errhp, 3600, OCI_TRANS_NEW);
712
CHECKERR("OCITransStart");
714
return SB_DB_ERROR_NONE;
716
else if (type == STMT_TYPE_COMMIT)
718
rc = OCITransCommit(ora_con->svchp, ora_con->errhp, OCI_DEFAULT);
719
CHECKERR("OCITransCommit");
721
return SB_DB_ERROR_NONE;
723
else if (type == STMT_TYPE_SELECT)
728
rc = OCIHandleAlloc(ora_env, (dvoid **)&tmp, OCI_HTYPE_STMT, 0, (dvoid **)NULL);
729
CHECKERR("OCIHandleAlloc");
731
stmt = (OCIStmt *)tmp;
733
rc = OCIStmtPrepare(stmt, ora_con->errhp, (OraText *)query, strlen(query),
734
OCI_NTV_SYNTAX, OCI_DEFAULT);
735
CHECKERR("OCIStmtPrepare");
737
rc = OCIStmtExecute(ora_con->svchp, stmt, ora_con->errhp, iters, 0, NULL, NULL,
739
CHECKERR("OCIStmtExecute");
741
OCIHandleFree(stmt, OCI_HTYPE_STMT);
743
return SB_DB_ERROR_NONE;
746
log_text(LOG_FATAL, "failed query was: '%s'", query);
748
OCIHandleFree(stmt, OCI_HTYPE_STMT);
750
return SB_DB_ERROR_FAILED;
754
/* Fetch row from result set of a prepared statement */
757
int ora_drv_fetch(db_result_set_t *rs)
766
/* Fetch row from result set of a query */
769
int ora_drv_fetch_row(db_result_set_t *rs, db_row_t *row)
772
(void)rs; /* unused */
773
(void)row; /* unused */
779
/* Return the number of rows in a result set */
782
unsigned long long ora_drv_num_rows(db_result_set_t *rs)
784
ora_result_set_t *ora_rs = (ora_result_set_t *)rs->ptr;
786
/* Check if the results are already fetched */
788
return ora_rs->nrows;
794
/* Store results from the last query */
797
int ora_drv_store_results(db_result_set_t *rs)
801
db_stmt_t *db_stmt = rs->statement;
802
db_conn_t *db_conn = rs->connection;
803
ora_stmt_t *ora_stmt;
805
ora_result_set_t *ora_rs;
806
ora_column_t *column;
810
unsigned int col_len;
815
if (db_stmt == NULL || db_conn == NULL)
818
ora_stmt = (ora_stmt_t *)db_stmt->ptr;
819
ora_con = (ora_conn_t *)db_conn->ptr;
820
if (ora_stmt == NULL || ora_con == NULL)
825
ora_rs = (ora_result_set_t *)calloc(1, sizeof(ora_result_set_t));
829
SB_LIST_INIT(&ora_rs->columns);
830
SB_LIST_INIT(&ora_rs->rows);
833
rc = OCIParamGet((dvoid *)ora_stmt->ptr, OCI_HTYPE_STMT, ora_con->errhp,
835
parm = (OCIParam *)tmp;
837
/* Loop to get description of all columns */
838
while (rc == OCI_SUCCESS)
840
column = (ora_column_t *)calloc(1, sizeof(ora_column_t));
843
SB_LIST_ADD_TAIL(&column->listitem, &ora_rs->columns);
845
/* Get the column type attribute */
846
rc = OCIAttrGet((dvoid *)parm, OCI_DTYPE_PARAM, (dvoid *)&column->type,
847
NULL, OCI_ATTR_DATA_TYPE, ora_con->errhp);
848
CHECKERR("OCIAttrGet");
850
/* Get the column name attribute */
851
rc = OCIAttrGet((dvoid *)parm, OCI_DTYPE_PARAM, &fnamep,
852
(ub4 *)&col_len, OCI_ATTR_NAME, ora_con->errhp);
853
CHECKERR("OCIAttrGet");
854
column->name = (char *)malloc(col_len + 1);
855
if (column->name == NULL)
857
strncpy(column->name, fnamep, col_len + 1);
860
/* Get the length semantics */
861
rc = OCIAttrGet((dvoid *)parm, OCI_DTYPE_PARAM, (dvoid *)&semantics,
862
NULL, OCI_ATTR_CHAR_USED, ora_con->errhp);
863
CHECKERR("OCIAttrGet");
867
/* Get the column width in characters */
868
rc = OCIAttrGet((dvoid *)parm, OCI_DTYPE_PARAM, (dvoid *)&column->len,
869
NULL, OCI_ATTR_CHAR_SIZE, ora_con->errhp);
870
if (column->len == 0)
871
column->len = get_oracle_type_size(column->type);
875
/* Get the column width in bytes */
876
rc = OCIAttrGet((dvoid *)parm, OCI_DTYPE_PARAM, (dvoid *)&column->len,
877
NULL, OCI_ATTR_DATA_SIZE, ora_con->errhp);
878
if (column->len == 0)
879
column->len = get_oracle_type_size(column->type);
881
CHECKERR("OCIAttrGet");
883
OCIDescriptorFree(parm, OCI_DTYPE_PARAM);
885
/* Describe the column */
886
column->value = malloc(column->len);
887
if (column->value == NULL)
889
rc = OCIDefineByPos(ora_stmt->ptr, &column->defhp, ora_con->errhp, i,
890
column->value, column->len, column->type, &column->ind,
891
NULL, NULL, OCI_DEFAULT);
892
CHECKERR("OCIDefineByPos");
895
rc = OCIParamGet(ora_stmt->ptr, OCI_HTYPE_STMT, ora_con->errhp,
897
parm = (OCIParam *)tmp;
899
ora_rs->ncolumns = i-1;
901
/* Now fetch the actual data */
904
rc = OCIStmtFetch2(ora_stmt->ptr, ora_con->errhp, 1, OCI_FETCH_NEXT, 0,
906
if (rc == OCI_NO_DATA)
908
CHECKERR("OCIStmtFetch");
910
row = (ora_row_t *)calloc(1, sizeof(ora_row_t));
913
row->data = (ora_data_t *)calloc(ora_rs->ncolumns, sizeof(ora_data_t));
915
SB_LIST_FOR_EACH(pos, &ora_rs->columns)
917
column = SB_LIST_ENTRY(pos, ora_column_t, listitem);
918
row->data[i].value = (void *)malloc(column->len);
919
if (row->data[i].value == NULL)
921
memcpy(row->data[i].value, column->value, column->len);
922
row->data[i].ind = column->ind;
925
SB_LIST_ADD_TAIL(&row->listitem, &ora_rs->rows);
937
/* Free result set */
940
int ora_drv_free_results(db_result_set_t *rs)
942
ora_result_set_t *ora_rs = (ora_result_set_t *)rs->ptr;
944
ora_column_t *column;
946
sb_list_item_t *next;
952
SB_LIST_FOR_EACH_SAFE(cur, next, &ora_rs->rows)
954
row = SB_LIST_ENTRY(cur, ora_row_t, listitem);
956
if (row->data != NULL)
958
for (i = 0; i < ora_rs->ncolumns; i++)
960
if (row->data[i].value != NULL)
961
free(row->data[i].value);
970
SB_LIST_FOR_EACH_SAFE(cur, next, &ora_rs->columns)
972
column = SB_LIST_ENTRY(cur, ora_column_t, listitem);
974
if (column->name != NULL)
976
if (column->value != NULL)
989
/* Close prepared statement */
992
int ora_drv_close(db_stmt_t *stmt)
994
ora_stmt_t *ora_stmt = stmt->ptr;
996
if (ora_stmt == NULL)
998
OCIHandleFree(stmt, OCI_HTYPE_STMT);
1004
/* Uninitialize driver */
1007
int ora_drv_done(void)
1011
if (ora_env == NULL)
1014
rc = OCIHandleFree(ora_env, OCI_HTYPE_ENV);
1015
if (rc != OCI_SUCCESS)
1017
log_text(LOG_FATAL, "OCIHandleFree failed");
1025
/* Get Oracle type, type length and indicator values from SysBench parameter */
1027
sword get_oracle_bind_type(db_bind_t *param, ub2 *type, sb4 *len,
1032
for (i = 0; db_oracle_bind_map[i].db_type != DB_TYPE_NONE; i++)
1033
if (db_oracle_bind_map[i].db_type == param->type)
1035
*type = db_oracle_bind_map[i].ora_type;
1036
*len = db_oracle_bind_map[i].ora_len;
1037
if (param->type == DB_TYPE_CHAR || param->type == DB_TYPE_VARCHAR)
1038
*len = strlen(param->buffer);
1039
*ind = (param->is_null) ? -1 : 0;
1048
/* Get Oracle type size in bytes */
1051
sb4 get_oracle_type_size(sword type)
1056
if (type == SQLT_NUM)
1059
for (i = 0; db_oracle_bind_map[i].db_type != DB_TYPE_NONE; i++)
1060
if (db_oracle_bind_map[i].ora_type == type &&
1061
size < db_oracle_bind_map[i].ora_len)
1062
size = db_oracle_bind_map[i].ora_len;
1067
ora_stmt_type_t get_stmt_type(const char *query)
1069
if (!strncmp(query, "BEGIN", 5))
1070
return STMT_TYPE_BEGIN;
1071
else if (!strncmp(query, "COMMIT", 6))
1072
return STMT_TYPE_COMMIT;
1073
else if (!strncmp(query, "SELECT", 6))
1074
return STMT_TYPE_SELECT;
1076
return STMT_TYPE_UPDATE;
1079
db_bind_type_t get_db_bind_type(sword type)
1083
for (i = 0; db_oracle_bind_map[i].db_type != DB_TYPE_NONE; i++)
1084
if (db_oracle_bind_map[i].ora_type == type)
1085
return db_oracle_bind_map[i].db_type;
1087
return DB_TYPE_NONE;
1091
/* Check and display Oracle error */
1094
void checkerr(OCIError *errhp, sword status)
1103
case OCI_SUCCESS_WITH_INFO:
1104
log_text(LOG_ALERT, "Error - OCI_SUCCESS_WITH_INFO");
1107
log_text(LOG_ALERT, "Error - OCI_NEED_DATA");
1110
log_text(LOG_ALERT, "Error - OCI_NO_DATA");
1113
OCIErrorGet((dvoid *) errhp, (ub4) 1,
1114
(text *) NULL, (sb4 *) &errcode,
1115
errbuf, (ub4) sizeof(errbuf),
1116
(ub4) OCI_HTYPE_ERROR);
1117
log_text(LOG_ALERT, "Error - %s", errbuf);
1119
case OCI_INVALID_HANDLE:
1120
log_text(LOG_ALERT, "Error - OCI_INVALID_HANDLE");
1122
case OCI_STILL_EXECUTING:
1123
log_text(LOG_ALERT, "Error - OCI_STILL_EXECUTE");
1126
log_text(LOG_ALERT, "Error - OCI_CONTINUE");