1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
--- 33 unchanged lines hidden (view full) ---
42#ifdef HAVE_SQL_H
43#include <sql.h>
44#include <sqlext.h>
45#elif defined(HAVE_ODBC_SQL_H)
46#include <odbc/sql.h>
47#include <odbc/sqlext.h>
48#endif
49
50/*
51* MSVC6 does not support intptr_t (C99)
52* APR does not have a signed inptr type until 2.0 (r1557720)
53*/
54#if defined(_MSC_VER) && _MSC_VER < 1400
55#if APR_SIZEOF_VOIDP == 8
56#define ODBC_INTPTR_T apr_int64_t
57#else
58#define ODBC_INTPTR_T apr_int32_t
59#endif
60#else
61#define ODBC_INTPTR_T intptr_t
62#endif
63
64
65/* Driver name is "odbc" and the entry point is 'apr_dbd_odbc_driver'
66 * unless ODBC_DRIVER_NAME is defined and it is linked with another db library which
67 * is ODBC source-compatible. e.g. DB2, Informix, TimesTen, mysql.
68 */
69#ifndef ODBC_DRIVER_NAME
70#define ODBC_DRIVER_NAME odbc
71#endif
72#define STRINGIFY(x) #x
--- 51 unchanged lines hidden (view full) ---
124 SQLHANDLE dbc; /* SQL connection handle - NULL after close */
125 apr_pool_t *pool; /* connection lifetime pool */
126 char *dbname; /* ODBC datasource */
127 int lasterrorcode;
128 int lineNumber;
129 char lastError[MAX_ERROR_STRING];
130 int defaultBufferSize; /* used for CLOBs in text mode,
131 * and when fld size is indeterminate */
132 ODBC_INTPTR_T transaction_mode;
133 ODBC_INTPTR_T dboptions; /* driver options re SQLGetData */
134 ODBC_INTPTR_T default_transaction_mode;
135 int can_commit; /* controls end_trans behavior */
136};
137
138struct apr_dbd_results_t
139{
140 SQLHANDLE stmt; /* parent sql statement handle */
141 SQLHANDLE dbc; /* parent sql connection handle */
142 apr_pool_t *pool; /* pool from query or select */
--- 226 unchanged lines hidden (view full) ---
369 return APR_FROM_SQL_RESULT(rc);
370}
371
372/* setup the arrays in results for all the returned columns */
373static SQLRETURN odbc_set_result_column(int icol, apr_dbd_results_t *res,
374 SQLHANDLE stmt)
375{
376 SQLRETURN rc;
377 ODBC_INTPTR_T maxsize, textsize, realsize, type, isunsigned = 1;
378
379 /* discover the sql type */
380 rc = SQLColAttribute(stmt, icol + 1, SQL_DESC_UNSIGNED, NULL, 0, NULL,
381 (SQLPOINTER)&isunsigned);
382 isunsigned = (isunsigned == SQL_TRUE);
383
384 rc = SQLColAttribute(stmt, icol + 1, SQL_DESC_TYPE, NULL, 0, NULL,
385 (SQLPOINTER)&type);
--- 371 unchanged lines hidden (view full) ---
757 * return -1 if data not available
758 */
759static void *odbc_get(const apr_dbd_row_t *row, const int col,
760 const SQLSMALLINT sqltype)
761{
762 SQLRETURN rc;
763 SQLLEN indicator;
764 int state = row->res->colstate[col];
765 ODBC_INTPTR_T options = row->res->apr_dbd->dboptions;
766
767 switch (state) {
768 case (COL_UNAVAIL):
769 return (void *)-1;
770 case (COL_RETRIEVED):
771 return NULL;
772
773 case (COL_BOUND):
--- 53 unchanged lines hidden (view full) ---
827 return (void *)-1;
828}
829
830/* Parse the parameter string for open */
831static apr_status_t odbc_parse_params(apr_pool_t *pool, const char *params,
832 int *connect, SQLCHAR **datasource,
833 SQLCHAR **user, SQLCHAR **password,
834 int *defaultBufferSize, int *nattrs,
835 int **attrs, ODBC_INTPTR_T **attrvals)
836{
837 char *seps, *last, *next, *name[MAX_PARAMS], *val[MAX_PARAMS];
838 int nparams = 0, i, j;
839
840 *attrs = apr_pcalloc(pool, MAX_PARAMS * sizeof(char *));
841 *attrvals = apr_pcalloc(pool, MAX_PARAMS * sizeof(ODBC_INTPTR_T));
842 *nattrs = 0;
843 seps = DEFAULTSEPS;
844 name[nparams] = apr_strtok(apr_pstrdup(pool, params), seps, &last);
845
846 /* no params is OK here - let connect return a more useful error msg */
847 if (!name[nparams])
848 return SQL_SUCCESS;
849
--- 223 unchanged lines hidden (view full) ---
1073 apr_dbd_t *handle;
1074 char *err_step;
1075 int err_htype, i;
1076 int defaultBufferSize = DEFAULT_BUFFER_SIZE;
1077 SQLHANDLE err_h = NULL;
1078 SQLCHAR *datasource = (SQLCHAR *)"", *user = (SQLCHAR *)"",
1079 *password = (SQLCHAR *)"";
1080 int nattrs = 0, *attrs = NULL, connect = 0;
1081 ODBC_INTPTR_T *attrvals = NULL;
1082
1083 err_step = "SQLAllocHandle (SQL_HANDLE_DBC)";
1084 err_htype = SQL_HANDLE_ENV;
1085 err_h = henv;
1086 rc = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
1087 if (SQL_SUCCEEDED(rc)) {
1088 err_step = "Invalid DBD Parameters - open";
1089 err_htype = SQL_HANDLE_DBC;
--- 37 unchanged lines hidden (view full) ---
1127 handle->dbname = apr_pstrdup(pool, (char *)datasource);
1128 handle->dbc = hdbc;
1129 handle->pool = pool;
1130 handle->defaultBufferSize = defaultBufferSize;
1131 CHECK_ERROR(handle, "SQLConnect", rc, SQL_HANDLE_DBC, handle->dbc);
1132 handle->default_transaction_mode = 0;
1133 handle->can_commit = APR_DBD_TRANSACTION_IGNORE_ERRORS;
1134 SQLGetInfo(hdbc, SQL_DEFAULT_TXN_ISOLATION,
1135 &(handle->default_transaction_mode), sizeof(ODBC_INTPTR_T), NULL);
1136 handle->transaction_mode = handle->default_transaction_mode;
1137 SQLGetInfo(hdbc, SQL_GETDATA_EXTENSIONS ,&(handle->dboptions),
1138 sizeof(ODBC_INTPTR_T), NULL);
1139 apr_pool_cleanup_register(pool, handle, odbc_close_cleanup, apr_pool_cleanup_null);
1140 return handle;
1141 }
1142 else {
1143 apr_dbd_t tmp_dbc;
1144
1145 tmp_dbc.pool = pool;
1146 tmp_dbc.dbname = NULL;
--- 604 unchanged lines hidden ---
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
--- 33 unchanged lines hidden (view full) ---
42#ifdef HAVE_SQL_H
43#include <sql.h>
44#include <sqlext.h>
45#elif defined(HAVE_ODBC_SQL_H)
46#include <odbc/sql.h>
47#include <odbc/sqlext.h>
48#endif
49
50/*
51* MSVC6 does not support intptr_t (C99)
52* APR does not have a signed inptr type until 2.0 (r1557720)
53*/
54#if defined(_MSC_VER) && _MSC_VER < 1400
55#if APR_SIZEOF_VOIDP == 8
56#define ODBC_INTPTR_T apr_int64_t
57#else
58#define ODBC_INTPTR_T apr_int32_t
59#endif
60#else
61#define ODBC_INTPTR_T intptr_t
62#endif
63
64
65/* Driver name is "odbc" and the entry point is 'apr_dbd_odbc_driver'
66 * unless ODBC_DRIVER_NAME is defined and it is linked with another db library which
67 * is ODBC source-compatible. e.g. DB2, Informix, TimesTen, mysql.
68 */
69#ifndef ODBC_DRIVER_NAME
70#define ODBC_DRIVER_NAME odbc
71#endif
72#define STRINGIFY(x) #x
--- 51 unchanged lines hidden (view full) ---
124 SQLHANDLE dbc; /* SQL connection handle - NULL after close */
125 apr_pool_t *pool; /* connection lifetime pool */
126 char *dbname; /* ODBC datasource */
127 int lasterrorcode;
128 int lineNumber;
129 char lastError[MAX_ERROR_STRING];
130 int defaultBufferSize; /* used for CLOBs in text mode,
131 * and when fld size is indeterminate */
132 ODBC_INTPTR_T transaction_mode;
133 ODBC_INTPTR_T dboptions; /* driver options re SQLGetData */
134 ODBC_INTPTR_T default_transaction_mode;
135 int can_commit; /* controls end_trans behavior */
136};
137
138struct apr_dbd_results_t
139{
140 SQLHANDLE stmt; /* parent sql statement handle */
141 SQLHANDLE dbc; /* parent sql connection handle */
142 apr_pool_t *pool; /* pool from query or select */
--- 226 unchanged lines hidden (view full) ---
369 return APR_FROM_SQL_RESULT(rc);
370}
371
372/* setup the arrays in results for all the returned columns */
373static SQLRETURN odbc_set_result_column(int icol, apr_dbd_results_t *res,
374 SQLHANDLE stmt)
375{
376 SQLRETURN rc;
377 ODBC_INTPTR_T maxsize, textsize, realsize, type, isunsigned = 1;
378
379 /* discover the sql type */
380 rc = SQLColAttribute(stmt, icol + 1, SQL_DESC_UNSIGNED, NULL, 0, NULL,
381 (SQLPOINTER)&isunsigned);
382 isunsigned = (isunsigned == SQL_TRUE);
383
384 rc = SQLColAttribute(stmt, icol + 1, SQL_DESC_TYPE, NULL, 0, NULL,
385 (SQLPOINTER)&type);
--- 371 unchanged lines hidden (view full) ---
757 * return -1 if data not available
758 */
759static void *odbc_get(const apr_dbd_row_t *row, const int col,
760 const SQLSMALLINT sqltype)
761{
762 SQLRETURN rc;
763 SQLLEN indicator;
764 int state = row->res->colstate[col];
765 ODBC_INTPTR_T options = row->res->apr_dbd->dboptions;
766
767 switch (state) {
768 case (COL_UNAVAIL):
769 return (void *)-1;
770 case (COL_RETRIEVED):
771 return NULL;
772
773 case (COL_BOUND):
--- 53 unchanged lines hidden (view full) ---
827 return (void *)-1;
828}
829
830/* Parse the parameter string for open */
831static apr_status_t odbc_parse_params(apr_pool_t *pool, const char *params,
832 int *connect, SQLCHAR **datasource,
833 SQLCHAR **user, SQLCHAR **password,
834 int *defaultBufferSize, int *nattrs,
835 int **attrs, ODBC_INTPTR_T **attrvals)
836{
837 char *seps, *last, *next, *name[MAX_PARAMS], *val[MAX_PARAMS];
838 int nparams = 0, i, j;
839
840 *attrs = apr_pcalloc(pool, MAX_PARAMS * sizeof(char *));
841 *attrvals = apr_pcalloc(pool, MAX_PARAMS * sizeof(ODBC_INTPTR_T));
842 *nattrs = 0;
843 seps = DEFAULTSEPS;
844 name[nparams] = apr_strtok(apr_pstrdup(pool, params), seps, &last);
845
846 /* no params is OK here - let connect return a more useful error msg */
847 if (!name[nparams])
848 return SQL_SUCCESS;
849
--- 223 unchanged lines hidden (view full) ---
1073 apr_dbd_t *handle;
1074 char *err_step;
1075 int err_htype, i;
1076 int defaultBufferSize = DEFAULT_BUFFER_SIZE;
1077 SQLHANDLE err_h = NULL;
1078 SQLCHAR *datasource = (SQLCHAR *)"", *user = (SQLCHAR *)"",
1079 *password = (SQLCHAR *)"";
1080 int nattrs = 0, *attrs = NULL, connect = 0;
1081 ODBC_INTPTR_T *attrvals = NULL;
1082
1083 err_step = "SQLAllocHandle (SQL_HANDLE_DBC)";
1084 err_htype = SQL_HANDLE_ENV;
1085 err_h = henv;
1086 rc = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
1087 if (SQL_SUCCEEDED(rc)) {
1088 err_step = "Invalid DBD Parameters - open";
1089 err_htype = SQL_HANDLE_DBC;
--- 37 unchanged lines hidden (view full) ---
1127 handle->dbname = apr_pstrdup(pool, (char *)datasource);
1128 handle->dbc = hdbc;
1129 handle->pool = pool;
1130 handle->defaultBufferSize = defaultBufferSize;
1131 CHECK_ERROR(handle, "SQLConnect", rc, SQL_HANDLE_DBC, handle->dbc);
1132 handle->default_transaction_mode = 0;
1133 handle->can_commit = APR_DBD_TRANSACTION_IGNORE_ERRORS;
1134 SQLGetInfo(hdbc, SQL_DEFAULT_TXN_ISOLATION,
1135 &(handle->default_transaction_mode), sizeof(ODBC_INTPTR_T), NULL);
1136 handle->transaction_mode = handle->default_transaction_mode;
1137 SQLGetInfo(hdbc, SQL_GETDATA_EXTENSIONS ,&(handle->dboptions),
1138 sizeof(ODBC_INTPTR_T), NULL);
1139 apr_pool_cleanup_register(pool, handle, odbc_close_cleanup, apr_pool_cleanup_null);
1140 return handle;
1141 }
1142 else {
1143 apr_dbd_t tmp_dbc;
1144
1145 tmp_dbc.pool = pool;
1146 tmp_dbc.dbname = NULL;
--- 604 unchanged lines hidden ---