apr_dbd_odbc.c (258602) | apr_dbd_odbc.c (272076) |
---|---|
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 | 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 |
|
50/* Driver name is "odbc" and the entry point is 'apr_dbd_odbc_driver' 51 * unless ODBC_DRIVER_NAME is defined and it is linked with another db library which 52 * is ODBC source-compatible. e.g. DB2, Informix, TimesTen, mysql. 53 */ 54#ifndef ODBC_DRIVER_NAME 55#define ODBC_DRIVER_NAME odbc 56#endif 57#define STRINGIFY(x) #x --- 51 unchanged lines hidden (view full) --- 109 SQLHANDLE dbc; /* SQL connection handle - NULL after close */ 110 apr_pool_t *pool; /* connection lifetime pool */ 111 char *dbname; /* ODBC datasource */ 112 int lasterrorcode; 113 int lineNumber; 114 char lastError[MAX_ERROR_STRING]; 115 int defaultBufferSize; /* used for CLOBs in text mode, 116 * and when fld size is indeterminate */ | 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 */ |
117 intptr_t transaction_mode; 118 intptr_t dboptions; /* driver options re SQLGetData */ 119 intptr_t default_transaction_mode; | 132 ODBC_INTPTR_T transaction_mode; 133 ODBC_INTPTR_T dboptions; /* driver options re SQLGetData */ 134 ODBC_INTPTR_T default_transaction_mode; |
120 int can_commit; /* controls end_trans behavior */ 121}; 122 123struct apr_dbd_results_t 124{ 125 SQLHANDLE stmt; /* parent sql statement handle */ 126 SQLHANDLE dbc; /* parent sql connection handle */ 127 apr_pool_t *pool; /* pool from query or select */ --- 226 unchanged lines hidden (view full) --- 354 return APR_FROM_SQL_RESULT(rc); 355} 356 357/* setup the arrays in results for all the returned columns */ 358static SQLRETURN odbc_set_result_column(int icol, apr_dbd_results_t *res, 359 SQLHANDLE stmt) 360{ 361 SQLRETURN rc; | 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; |
362 intptr_t maxsize, textsize, realsize, type, isunsigned = 1; | 377 ODBC_INTPTR_T maxsize, textsize, realsize, type, isunsigned = 1; |
363 364 /* discover the sql type */ 365 rc = SQLColAttribute(stmt, icol + 1, SQL_DESC_UNSIGNED, NULL, 0, NULL, 366 (SQLPOINTER)&isunsigned); 367 isunsigned = (isunsigned == SQL_TRUE); 368 369 rc = SQLColAttribute(stmt, icol + 1, SQL_DESC_TYPE, NULL, 0, NULL, 370 (SQLPOINTER)&type); --- 371 unchanged lines hidden (view full) --- 742 * return -1 if data not available 743 */ 744static void *odbc_get(const apr_dbd_row_t *row, const int col, 745 const SQLSMALLINT sqltype) 746{ 747 SQLRETURN rc; 748 SQLLEN indicator; 749 int state = row->res->colstate[col]; | 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]; |
750 intptr_t options = row->res->apr_dbd->dboptions; | 765 ODBC_INTPTR_T options = row->res->apr_dbd->dboptions; |
751 752 switch (state) { 753 case (COL_UNAVAIL): 754 return (void *)-1; 755 case (COL_RETRIEVED): 756 return NULL; 757 758 case (COL_BOUND): --- 53 unchanged lines hidden (view full) --- 812 return (void *)-1; 813} 814 815/* Parse the parameter string for open */ 816static apr_status_t odbc_parse_params(apr_pool_t *pool, const char *params, 817 int *connect, SQLCHAR **datasource, 818 SQLCHAR **user, SQLCHAR **password, 819 int *defaultBufferSize, int *nattrs, | 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, |
820 int **attrs, intptr_t **attrvals) | 835 int **attrs, ODBC_INTPTR_T **attrvals) |
821{ 822 char *seps, *last, *next, *name[MAX_PARAMS], *val[MAX_PARAMS]; 823 int nparams = 0, i, j; 824 825 *attrs = apr_pcalloc(pool, MAX_PARAMS * sizeof(char *)); | 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 *)); |
826 *attrvals = apr_pcalloc(pool, MAX_PARAMS * sizeof(intptr_t)); | 841 *attrvals = apr_pcalloc(pool, MAX_PARAMS * sizeof(ODBC_INTPTR_T)); |
827 *nattrs = 0; 828 seps = DEFAULTSEPS; 829 name[nparams] = apr_strtok(apr_pstrdup(pool, params), seps, &last); 830 831 /* no params is OK here - let connect return a more useful error msg */ 832 if (!name[nparams]) 833 return SQL_SUCCESS; 834 --- 223 unchanged lines hidden (view full) --- 1058 apr_dbd_t *handle; 1059 char *err_step; 1060 int err_htype, i; 1061 int defaultBufferSize = DEFAULT_BUFFER_SIZE; 1062 SQLHANDLE err_h = NULL; 1063 SQLCHAR *datasource = (SQLCHAR *)"", *user = (SQLCHAR *)"", 1064 *password = (SQLCHAR *)""; 1065 int nattrs = 0, *attrs = NULL, connect = 0; | 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; |
1066 intptr_t *attrvals = NULL; | 1081 ODBC_INTPTR_T *attrvals = NULL; |
1067 1068 err_step = "SQLAllocHandle (SQL_HANDLE_DBC)"; 1069 err_htype = SQL_HANDLE_ENV; 1070 err_h = henv; 1071 rc = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc); 1072 if (SQL_SUCCEEDED(rc)) { 1073 err_step = "Invalid DBD Parameters - open"; 1074 err_htype = SQL_HANDLE_DBC; --- 37 unchanged lines hidden (view full) --- 1112 handle->dbname = apr_pstrdup(pool, (char *)datasource); 1113 handle->dbc = hdbc; 1114 handle->pool = pool; 1115 handle->defaultBufferSize = defaultBufferSize; 1116 CHECK_ERROR(handle, "SQLConnect", rc, SQL_HANDLE_DBC, handle->dbc); 1117 handle->default_transaction_mode = 0; 1118 handle->can_commit = APR_DBD_TRANSACTION_IGNORE_ERRORS; 1119 SQLGetInfo(hdbc, SQL_DEFAULT_TXN_ISOLATION, | 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, |
1120 &(handle->default_transaction_mode), sizeof(intptr_t), NULL); | 1135 &(handle->default_transaction_mode), sizeof(ODBC_INTPTR_T), NULL); |
1121 handle->transaction_mode = handle->default_transaction_mode; 1122 SQLGetInfo(hdbc, SQL_GETDATA_EXTENSIONS ,&(handle->dboptions), | 1136 handle->transaction_mode = handle->default_transaction_mode; 1137 SQLGetInfo(hdbc, SQL_GETDATA_EXTENSIONS ,&(handle->dboptions), |
1123 sizeof(intptr_t), NULL); | 1138 sizeof(ODBC_INTPTR_T), NULL); |
1124 apr_pool_cleanup_register(pool, handle, odbc_close_cleanup, apr_pool_cleanup_null); 1125 return handle; 1126 } 1127 else { 1128 apr_dbd_t tmp_dbc; 1129 1130 tmp_dbc.pool = pool; 1131 tmp_dbc.dbname = NULL; --- 604 unchanged lines hidden --- | 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 --- |