1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
|
/*********************************************************************
*
* unixODBC Cursor Library
*
* Created by Nick Gorham
* (nick@easysoft.com).
*
* copyright (c) 1999 Nick Gorham
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
**********************************************************************
*
* $Id: SQLConnect.c,v 1.3 2002/11/25 15:37:54 lurcher Exp $
*
* $Log: SQLConnect.c,v $
* Revision 1.3 2002/11/25 15:37:54 lurcher
*
* Fix problems in the cursor lib
*
* Revision 1.2 2002/11/19 18:52:28 lurcher
*
* Alter the cursor lib to not require linking to the driver manager.
*
* Revision 1.1.1.1 2001/10/17 16:40:15 lurcher
*
* First upload to SourceForge
*
* Revision 1.3 2001/04/12 17:43:36 nick
*
* Change logging and added autotest to odbctest
*
* Revision 1.2 2001/03/28 14:57:22 nick
*
* Fix bugs in corsor lib introduced bu UNCODE and other changes
*
* Revision 1.1.1.1 2000/09/04 16:42:52 nick
* Imported Sources
*
* Revision 1.3 1999/11/20 20:54:00 ngorham
*
* Asorted portability fixes
*
* Revision 1.2 1999/11/10 03:51:35 ngorham
*
* Update the error reporting in the DM to enable ODBC 3 and 2 calls to
* work at the same time
*
* Revision 1.1 1999/09/19 22:22:50 ngorham
*
*
* Added first cursor library work, read only at the moment and only works
* with selects with no where clause
*
*
**********************************************************************/
#include "cursorlibrary.h"
static struct driver_func cl_template_func[] =
{
/* 00 */ { SQL_API_SQLALLOCCONNECT, "SQLAllocConnect", NULL, NULL,
NULL },
/* 01 */ { SQL_API_SQLALLOCENV, "SQLAllocEnv", NULL, NULL,
NULL },
/* 02 */ { SQL_API_SQLALLOCHANDLE, "SQLAllocHandle", NULL, NULL,
(SQLRETURN (*)())CLAllocHandle },
/* 03 */ { SQL_API_SQLALLOCSTMT, "SQLAllocStmt", NULL, NULL,
(SQLRETURN (*)())CLAllocStmt },
/* 04 */ { SQL_API_SQLALLOCHANDLESTD, "SQLAllocHandleStd", NULL, NULL,
(SQLRETURN (*)())CLAllocHandleStd },
/* 05 */ { SQL_API_SQLBINDCOL, "SQLBindCol", NULL, NULL,
(SQLRETURN (*)())CLBindCol },
/* 06 */ { SQL_API_SQLBINDPARAM, "SQLBindParam", NULL, NULL,
(SQLRETURN (*)())CLBindParam },
/* 07 */ { SQL_API_SQLBINDPARAMETER, "SQLBindParameter", NULL, NULL,
(SQLRETURN (*)())CLBindParameter },
/* 08 */ { SQL_API_SQLBROWSECONNECT, "SQLBrowseConnect", NULL, NULL,
NULL },
/* 09 */ { SQL_API_SQLBULKOPERATIONS, "SQLBulkOperations", NULL, NULL,
NULL },
/* 10 */ { SQL_API_SQLCANCEL, "SQLCancel", NULL, NULL,
(SQLRETURN (*)())CLCancel },
/* 11 */ { SQL_API_SQLCLOSECURSOR, "SQLCloseCursor", NULL, NULL,
(SQLRETURN (*)())CLCloseCursor },
/* 12 */ { SQL_API_SQLCOLATTRIBUTE, "SQLColAttribute", NULL, NULL,
(SQLRETURN (*)())CLColAttribute },
/* 13 */ { SQL_API_SQLCOLATTRIBUTES, "SQLColAttributes", NULL, NULL,
(SQLRETURN (*)())CLColAttributes },
/* 14 */ { SQL_API_SQLCOLUMNPRIVILEGES, "SQLColumnPrivileges", NULL, NULL,
(SQLRETURN (*)())CLColumnPrivileges },
/* 15 */ { SQL_API_SQLCOLUMNS, "SQLColumns", NULL, NULL,
(SQLRETURN (*)())CLColumns },
/* 16 */ { SQL_API_SQLCONNECT, "SQLConnect", NULL, NULL,
NULL },
/* 17 */ { SQL_API_SQLCOPYDESC, "SQLCopyDesc", NULL, NULL,
(SQLRETURN (*)())CLCopyDesc },
/* 18 */ { SQL_API_SQLDATASOURCES, "SQLDataSources", NULL, NULL,
NULL },
/* 19 */ { SQL_API_SQLDESCRIBECOL, "SQLDescribeCol", NULL, NULL,
(SQLRETURN (*)())CLDescribeCol },
/* 20 */ { SQL_API_SQLDESCRIBEPARAM, "SQLDescribeParam", NULL, NULL,
(SQLRETURN (*)())CLDescribeParam },
/* 21 */ { SQL_API_SQLDISCONNECT, "SQLDisconnect", NULL, NULL,
(SQLRETURN (*)())CLDisconnect },
/* 22 */ { SQL_API_SQLDRIVERCONNECT, "SQLDriverConnect", NULL, NULL,
NULL },
/* 23 */ { SQL_API_SQLDRIVERS, "SQLDrivers", NULL, NULL,
NULL },
/* 24 */ { SQL_API_SQLENDTRAN, "SQLEndTran", NULL, NULL,
(SQLRETURN (*)())CLEndTran },
/* 25 */ { SQL_API_SQLERROR, "SQLError", NULL, NULL,
(SQLRETURN (*)())CLError },
/* 26 */ { SQL_API_SQLEXECDIRECT, "SQLExecDirect", NULL, NULL,
(SQLRETURN (*)())CLExecDirect },
/* 27 */ { SQL_API_SQLEXECUTE, "SQLExecute", NULL, NULL,
(SQLRETURN (*)())CLExecute },
/* 28 */ { SQL_API_SQLEXTENDEDFETCH, "SQLExtendedFetch", NULL, NULL,
(SQLRETURN (*)())CLExtendedFetch },
/* 29 */ { SQL_API_SQLFETCH, "SQLFetch", NULL, NULL,
(SQLRETURN (*)())CLFetch },
/* 30 */ { SQL_API_SQLFETCHSCROLL, "SQLFetchScroll", NULL, NULL,
(SQLRETURN (*)())CLFetchScroll },
/* 31 */ { SQL_API_SQLFOREIGNKEYS, "SQLForeignKeys", NULL, NULL,
(SQLRETURN (*)())CLForeignKeys },
/* 32 */ { SQL_API_SQLFREEENV, "SQLFreeEnv", NULL, NULL,
NULL },
/* 33 */ { SQL_API_SQLFREEHANDLE, "SQLFreeHandle", NULL, NULL,
(SQLRETURN (*)())CLFreeHandle },
/* 34 */ { SQL_API_SQLFREESTMT, "SQLFreeStmt", NULL, NULL,
(SQLRETURN (*)())CLFreeStmt },
/* 35 */ { SQL_API_SQLFREECONNECT, "SQLFreeConnect", NULL, NULL,
NULL },
/* 36 */ { SQL_API_SQLGETCONNECTATTR, "SQLGetConnectAttr", NULL, NULL,
(SQLRETURN (*)())CLGetConnectAttr },
/* 37 */ { SQL_API_SQLGETCONNECTOPTION, "SQLGetConnectOption", NULL, NULL,
(SQLRETURN (*)())CLGetConnectOption },
/* 38 */ { SQL_API_SQLGETCURSORNAME, "SQLGetCursorName", NULL, NULL,
(SQLRETURN (*)())CLGetCursorName },
/* 39 */ { SQL_API_SQLGETDATA, "SQLGetData", NULL, NULL,
(SQLRETURN (*)())CLGetData },
/* 40 */ { SQL_API_SQLGETDESCFIELD, "SQLGetDescField", NULL, NULL,
(SQLRETURN (*)())CLGetDescField },
/* 41 */ { SQL_API_SQLGETDESCREC, "SQLGetDescRec", NULL, NULL,
(SQLRETURN (*)())CLGetDescRec },
/* 42 */ { SQL_API_SQLGETDIAGFIELD, "SQLGetDiagField", NULL, NULL,
(SQLRETURN (*)())CLGetDiagField },
/* 43 */ { SQL_API_SQLGETENVATTR, "SQLGetEnvAttr", NULL, NULL,
NULL },
/* 44 */ { SQL_API_SQLGETFUNCTIONS, "SQLGetFunctions", NULL, NULL,
NULL },
/* 45 */ { SQL_API_SQLGETINFO, "SQLGetInfo", NULL, NULL,
(SQLRETURN (*)())CLGetInfo },
/* 46 */ { SQL_API_SQLGETSTMTATTR, "SQLGetStmtAttr", NULL, NULL,
(SQLRETURN (*)())CLGetStmtAttr },
/* 47 */ { SQL_API_SQLGETSTMTOPTION, "SQLGetStmtOption", NULL, NULL,
(SQLRETURN (*)())CLGetStmtOption },
/* 48 */ { SQL_API_SQLGETTYPEINFO, "SQLGetTypeInfo", NULL, NULL,
(SQLRETURN (*)())CLGetTypeInfo },
/* 49 */ { SQL_API_SQLMORERESULTS, "SQLMoreResults", NULL, NULL,
(SQLRETURN (*)())CLMoreResults },
/* 50 */ { SQL_API_SQLNATIVESQL, "SQLNativeSql", NULL, NULL,
(SQLRETURN (*)())CLNativeSql },
/* 51 */ { SQL_API_SQLNUMPARAMS, "SQLNumParams", NULL, NULL,
(SQLRETURN (*)())CLNumParams },
/* 52 */ { SQL_API_SQLNUMRESULTCOLS, "SQLNumResultCols", NULL, NULL,
(SQLRETURN (*)())CLNumResultCols },
/* 53 */ { SQL_API_SQLPARAMDATA, "SQLParamData", NULL, NULL,
(SQLRETURN (*)())CLParamData },
/* 54 */ { SQL_API_SQLPARAMOPTIONS, "SQLParamOptions", NULL, NULL,
(SQLRETURN (*)())CLParamOptions },
/* 55 */ { SQL_API_SQLPREPARE, "SQLPrepare", NULL, NULL,
(SQLRETURN (*)())CLPrepare },
/* 56 */ { SQL_API_SQLPRIMARYKEYS, "SQLPrimaryKeys", NULL, NULL,
(SQLRETURN (*)())CLPrimaryKeys },
/* 57 */ { SQL_API_SQLPROCEDURECOLUMNS, "SQLProcedureColumns", NULL, NULL,
(SQLRETURN (*)())CLProcedureColumns },
/* 58 */ { SQL_API_SQLPROCEDURES, "SQLProcedures", NULL, NULL,
(SQLRETURN (*)())CLProcedures },
/* 59 */ { SQL_API_SQLPUTDATA, "SQLPutData", NULL, NULL,
(SQLRETURN (*)())CLPutData },
/* 60 */ { SQL_API_SQLROWCOUNT, "SQLRowCount", NULL, NULL,
(SQLRETURN (*)())CLRowCount },
/* 61 */ { SQL_API_SQLSETCONNECTATTR, "SQLSetConnectAttr", NULL, NULL,
(SQLRETURN (*)())CLSetConnectAttr },
/* 62 */ { SQL_API_SQLSETCONNECTOPTION, "SQLSetConnectOption", NULL, NULL,
(SQLRETURN (*)())CLSetConnectOption },
/* 63 */ { SQL_API_SQLSETCURSORNAME, "SQLSetCursorName", NULL, NULL,
(SQLRETURN (*)())CLSetCursorName },
/* 64 */ { SQL_API_SQLSETDESCFIELD, "SQLSetDescField", NULL, NULL,
(SQLRETURN (*)())CLSetDescField },
/* 65 */ { SQL_API_SQLSETDESCREC, "SQLSetDescRec", NULL, NULL,
(SQLRETURN (*)())CLSetDescRec },
/* 66 */ { SQL_API_SQLSETENVATTR, "SQLSetEnvAttr", NULL, NULL,
NULL },
/* 67 */ { SQL_API_SQLSETPARAM, "SQLSetParam", NULL, NULL,
(SQLRETURN (*)())CLSetParam },
/* 68 */ { SQL_API_SQLSETPOS, "SQLSetPos", NULL, NULL,
(SQLRETURN (*)())CLSetPos },
/* 69 */ { SQL_API_SQLSETSCROLLOPTIONS, "SQLSetScrollOptions", NULL, NULL,
(SQLRETURN (*)())CLSetScrollOptions },
/* 70 */ { SQL_API_SQLSETSTMTATTR, "SQLSetStmtAttr", NULL, NULL,
(SQLRETURN (*)())CLSetStmtAttr },
/* 71 */ { SQL_API_SQLSETSTMTOPTION, "SQLSetStmtOption", NULL, NULL,
(SQLRETURN (*)())CLSetStmtOption },
/* 72 */ { SQL_API_SQLSPECIALCOLUMNS, "SQLSpecialColumns", NULL, NULL,
(SQLRETURN (*)())CLSpecialColumns },
/* 73 */ { SQL_API_SQLSTATISTICS, "SQLStatistics", NULL, NULL,
(SQLRETURN (*)())CLStatistics },
/* 74 */ { SQL_API_SQLTABLEPRIVILEGES, "SQLTablePrivileges", NULL, NULL,
(SQLRETURN (*)())CLTablePrivileges },
/* 75 */ { SQL_API_SQLTABLES, "SQLTables", NULL, NULL,
(SQLRETURN (*)())CLTables },
/* 76 */ { SQL_API_SQLTRANSACT, "SQLTransact", NULL, NULL,
(SQLRETURN (*)())CLTransact },
/* 77 */ { SQL_API_SQLGETDIAGREC, "SQLGetDiagRec", NULL, NULL,
(SQLRETURN (*)())CLGetDiagRec },
};
/*
* connect is done by the driver manager, the is called to put the
* cursor lib in the call chain
*/
SQLRETURN CLConnect( DMHDBC connection, struct driver_helper_funcs *dh )
{
int i;
CLHDBC cl_connection;
SQLRETURN ret;
/*
* Allocated a cursor connection structure
*/
cl_connection = malloc( sizeof( struct cl_connection ));
if ( !cl_connection )
{
dh ->dm_log_write( "CL " __FILE__,
__LINE__,
LOG_INFO,
LOG_INFO,
"Error: IM001" );
dh ->__post_internal_error( &connection -> error,
ERROR_HY001, NULL,
connection -> environment -> requested_version );
return SQL_ERROR;
}
memset( cl_connection, 0, sizeof( struct cl_connection ));
cl_connection -> functions = connection -> functions;
cl_connection -> dm_connection = connection;
cl_connection -> dh.__post_internal_error_ex = dh -> __post_internal_error_ex;
cl_connection -> dh.__post_internal_error = dh -> __post_internal_error;
cl_connection -> dh.dm_log_write = dh -> dm_log_write;
/*
* allocated a copy of the functions
*/
if ( !( cl_connection -> functions = malloc( sizeof( cl_template_func ))))
{
dh -> dm_log_write( "CL " __FILE__,
__LINE__,
LOG_INFO,
LOG_INFO,
"Error: IM001" );
cl_connection -> dh.__post_internal_error( &connection -> error,
ERROR_HY001, NULL,
connection -> environment -> requested_version );
return SQL_ERROR;
}
/*
* replace the function pointers with the ones in the
* cursor lib
*/
for ( i = 0;
i < sizeof( cl_template_func ) / sizeof( cl_template_func[ 0 ] );
i ++ )
{
cl_connection -> functions[ i ] =
connection -> functions[ i ];
/*
* if set replace the driver function with the function in
* the template
*/
if ( cl_template_func[ i ].func &&
connection -> functions[ i ].func )
{
connection -> functions[ i ] =
cl_template_func[ i ];
/*
* copy the can_supply from the drivers list
*/
connection -> functions[ i ].can_supply =
cl_connection -> functions[ i ].can_supply;
}
}
/*
* add some functions the cursor lib will supply
*/
connection -> functions[ DM_SQLSETPOS ].can_supply = 1;
connection -> functions[ DM_SQLSETPOS ].func =
cl_template_func[ DM_SQLSETPOS ].func;
connection -> functions[ DM_SQLSETSCROLLOPTIONS ].can_supply = 1;
connection -> functions[ DM_SQLSETSCROLLOPTIONS ].func =
cl_template_func[ DM_SQLSETSCROLLOPTIONS ].func;
connection -> functions[ DM_SQLFETCHSCROLL ].can_supply = 1;
connection -> functions[ DM_SQLFETCHSCROLL ].func =
cl_template_func[ DM_SQLFETCHSCROLL ].func;
connection -> functions[ DM_SQLEXTENDEDFETCH ].can_supply = 1;
connection -> functions[ DM_SQLEXTENDEDFETCH ].func =
cl_template_func[ DM_SQLEXTENDEDFETCH ].func;
/*
* blank off what we don't do
*/
connection -> functions[ DM_SQLBULKOPERATIONS ].can_supply = 0;
connection -> functions[ DM_SQLBULKOPERATIONS ].func = NULL;
/*
* intercept the driver dbc
*/
cl_connection -> driver_dbc = connection -> driver_dbc;
connection -> driver_dbc = ( SQLHANDLE ) cl_connection;
/*
* check the number of alowed active statements
*/
if ( CHECK_SQLGETINFO( cl_connection ))
{
ret = SQLGETINFO( cl_connection,
cl_connection -> driver_dbc,
SQL_MAX_CONCURRENT_ACTIVITIES,
&cl_connection -> active_statement_allowed,
0,
NULL );
/*
* assume the worst
*/
if ( !SQL_SUCCEEDED( ret ))
{
cl_connection -> active_statement_allowed = 1;
}
}
else
{
cl_connection -> active_statement_allowed = 1;
}
return SQL_SUCCESS;
}
SQLRETURN CLDisconnect( SQLHDBC connection_handle )
{
SQLRETURN ret;
int i;
CLHDBC cl_connection = (CLHDBC)connection_handle;
DMHDBC connection = cl_connection -> dm_connection;
/*
* disconnect from the driver
*/
ret = SQLDISCONNECT( cl_connection,
cl_connection -> driver_dbc );
if ( SQL_SUCCEEDED( ret ))
{
/*
* replace the function pointers with the ones from the
* cursor lib
*/
for ( i = 0;
i < sizeof( cl_template_func ) / sizeof( cl_template_func[ 0 ] );
i ++ )
{
connection -> functions[ i ] =
cl_connection -> functions[ i ];
}
/*
* replace the driver dbc
*/
connection -> driver_dbc =
cl_connection -> driver_dbc;
}
return ret;
}
|