Deleted Added
sdiff udiff text old ( 258602 ) new ( 272076 )
full compact
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/* 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 */
117 intptr_t transaction_mode;
118 intptr_t dboptions; /* driver options re SQLGetData */
119 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;
362 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];
750 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,
820 int **attrs, 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 *));
826 *attrvals = apr_pcalloc(pool, MAX_PARAMS * sizeof(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;
1066 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,
1120 &(handle->default_transaction_mode), sizeof(intptr_t), NULL);
1121 handle->transaction_mode = handle->default_transaction_mode;
1122 SQLGetInfo(hdbc, SQL_GETDATA_EXTENSIONS ,&(handle->dboptions),
1123 sizeof(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 ---