/*-----------------------------------------------------------------------------*/ void ODBCUserTables() { struct Cursor *cur = (struct Cursor *)ptoc_int(2); UWORD TablePrivilegeExists; RETCODE rc; /* since some ODBC drivers don't implement the function SQLTablePrivileges*/ /* we check it first*/ SQLGetFunctions(cur->hdbc,SQL_API_SQLTABLEPRIVILEGES,&TablePrivilegeExists); if (!TablePrivilegeExists) { printf("Privilege concept does not exist in this DVMS: you probably can access any of the existing tables\n"); ctop_int(3, 2); return; } if (((rc=SQLTablePrivileges(cur->hstmt, NULL, 0, NULL, 0, NULL, 0)) == SQL_SUCCESS) || (rc == SQL_SUCCESS_WITH_INFO)) ctop_int(3,0); else { ctop_int(3,PrintErrorMsg(cur)); SetCursorClose(cur); } return; }
int ODBC_Connect (char *connStr) { short buflen; SQLCHAR dataSource[1024]; SQLTCHAR dsn[33]; SQLTCHAR desc[255]; SQLTCHAR driverInfo[255]; SQLSMALLINT len1, len2; int status; #ifdef UNICODE SQLWCHAR wdataSource[1024]; #endif #if (ODBCVER < 0x0300) if (SQLAllocEnv (&henv) != SQL_SUCCESS) return -1; if (SQLAllocConnect (henv, &hdbc) != SQL_SUCCESS) return -1; #else if (SQLAllocHandle (SQL_HANDLE_ENV, NULL, &henv) != SQL_SUCCESS) return -1; SQLSetEnvAttr (henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, SQL_IS_UINTEGER); if (SQLAllocHandle (SQL_HANDLE_DBC, henv, &hdbc) != SQL_SUCCESS) return -1; #endif /* * Set the application name */ SQLSetConnectOption (hdbc, SQL_APPLICATION_NAME, (SQLULEN) TEXT ("odbctest")); /* * Show the version number of the driver manager */ status = SQLGetInfo (hdbc, SQL_DM_VER, driverInfo, sizeof (driverInfo), &len1); if (status == SQL_SUCCESS) { #ifdef UNICODE printf ("Driver Manager: %S\n", driverInfo); #else printf ("Driver Manager: %s\n", driverInfo); #endif } /* * Either use the connect string provided on the command line or * ask for one. If an empty string or a ? is given, show a nice * list of options */ if (connStr && *connStr) strcpy ((char *) dataSource, connStr); else while (1) { /* * Ask for the connect string */ printf ("\nEnter ODBC connect string (? shows list): "); if (fgets ((char *) dataSource, sizeof (dataSource), stdin) == NULL) return 1; /* * Remove trailing '\n' */ dataSource[strlen ((char *) dataSource) - 1] = '\0'; /* * Check if the user wants to quit */ if (!strcmp ((char *)dataSource, "quit") || !strcmp ((char *)dataSource, "exit")) return -1; /* * If the user entered something other than a ? * break out of the while loop */ if (*dataSource && *dataSource != '?') break; /* * Print headers */ fprintf (stderr, "\n%-32s | %-40s\n", "DSN", "Driver"); fprintf (stderr, "------------------------------------------------------------------------------\n"); /* * Goto the first record */ if (SQLDataSources (henv, SQL_FETCH_FIRST, dsn, NUMTCHAR (dsn), &len1, desc, NUMTCHAR (desc), &len2) != SQL_SUCCESS) continue; /* * Show all records */ do { #ifdef UNICODE fprintf (stderr, "%-32S | %-40S\n", dsn, desc); #else fprintf (stderr, "%-32s | %-40s\n", dsn, desc); #endif } while (SQLDataSources (henv, SQL_FETCH_NEXT, dsn, NUMTCHAR (dsn), &len1, desc, NUMTCHAR (desc), &len2) == SQL_SUCCESS); } #ifdef UNICODE strcpy_A2W (wdataSource, (char *) dataSource); status = SQLDriverConnectW (hdbc, 0, (SQLWCHAR *) wdataSource, SQL_NTS, (SQLWCHAR *) outdsn, NUMTCHAR (outdsn), &buflen, SQL_DRIVER_COMPLETE); if (status != SQL_SUCCESS) ODBC_Errors ("SQLDriverConnectW"); #else status = SQLDriverConnect (hdbc, 0, (SQLCHAR *) dataSource, SQL_NTS, (SQLCHAR *) outdsn, NUMTCHAR (outdsn), &buflen, SQL_DRIVER_COMPLETE); if (status != SQL_SUCCESS) ODBC_Errors ("SQLDriverConnect"); #endif if (status != SQL_SUCCESS && status != SQL_SUCCESS_WITH_INFO) return -1; connected = 1; /* * Print out the version number and the name of the connected driver */ status = SQLGetInfo (hdbc, SQL_DRIVER_VER, driverInfo, NUMTCHAR (driverInfo), &len1); if (status == SQL_SUCCESS) { #ifdef UNICODE printf ("Driver: %S", driverInfo); #else printf ("Driver: %s", driverInfo); #endif status = SQLGetInfo (hdbc, SQL_DRIVER_NAME, driverInfo, NUMTCHAR (driverInfo), &len1); if (status == SQL_SUCCESS) { #ifdef UNICODE printf (" (%S)", driverInfo); #else printf (" (%s)", driverInfo); #endif } printf ("\n"); } /* * Show the list of supported functions in trace log */ #if (ODBCVER < 0x0300) { SQLUSMALLINT exists[100]; SQLGetFunctions (hdbc, SQL_API_ALL_FUNCTIONS, exists); } #else { SQLUSMALLINT exists[SQL_API_ODBC3_ALL_FUNCTIONS_SIZE]; SQLGetFunctions (hdbc, SQL_API_ODBC3_ALL_FUNCTIONS, exists); } #endif /* * Allocate statement handle */ #if (ODBCVER < 0x0300) if (SQLAllocStmt (hdbc, &hstmt) != SQL_SUCCESS) return -1; #else if (SQLAllocHandle (SQL_HANDLE_STMT, hdbc, &hstmt) != SQL_SUCCESS) return -1; #endif return 0; }
SQLRETURN unixodbc_backend::do_get_functions(SQLHDBC connection_handle, SQLUSMALLINT function_id, SQLUSMALLINT * is_supported) const { return SQLGetFunctions(connection_handle, function_id, is_supported); }
/**************************** * OpenDatabase - do everything we have to do to get a viable connection to szDSN ***************************/ static int OpenDatabase( SQLHENV *phEnv, SQLHDBC *phDbc, char *szDSN, char *szUID, char *szPWD ) { if ( version3 ) { if ( SQLAllocHandle( SQL_HANDLE_ENV, NULL, phEnv ) != SQL_SUCCESS ) { fprintf( stderr, "[ISQL]ERROR: Could not SQLAllocHandle( SQL_HANDLE_ENV )\n" ); return 0; } if ( SQLSetEnvAttr( *phEnv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) 3, 0 ) != SQL_SUCCESS ) { if ( bVerbose ) DumpODBCLog( hEnv, 0, 0 ); fprintf( stderr, "[ISQL]ERROR: Could not SQLSetEnvAttr( SQL_HANDLE_DBC )\n" ); SQLFreeHandle( SQL_HANDLE_ENV, *phEnv ); return 0; } if ( SQLAllocHandle( SQL_HANDLE_DBC, *phEnv, phDbc ) != SQL_SUCCESS ) { if ( bVerbose ) DumpODBCLog( hEnv, 0, 0 ); fprintf( stderr, "[ISQL]ERROR: Could not SQLAllocHandle( SQL_HANDLE_DBC )\n" ); SQLFreeHandle( SQL_HANDLE_ENV, *phEnv ); return 0; } if ( !SQL_SUCCEEDED( SQLConnect( *phDbc, (SQLCHAR*)szDSN, SQL_NTS, (SQLCHAR*)szUID, SQL_NTS, (SQLCHAR*)szPWD, SQL_NTS ))) { if ( bVerbose ) DumpODBCLog( hEnv, hDbc, 0 ); fprintf( stderr, "[ISQL]ERROR: Could not SQLConnect\n" ); SQLFreeHandle( SQL_HANDLE_DBC, *phDbc ); SQLFreeHandle( SQL_HANDLE_ENV, *phEnv ); return 0; } } else { if ( SQLAllocEnv( phEnv ) != SQL_SUCCESS ) { fprintf( stderr, "[ISQL]ERROR: Could not SQLAllocEnv\n" ); return 0; } if ( SQLAllocConnect( *phEnv, phDbc ) != SQL_SUCCESS ) { if ( bVerbose ) DumpODBCLog( hEnv, 0, 0 ); fprintf( stderr, "[ISQL]ERROR: Could not SQLAllocConnect\n" ); SQLFreeEnv( *phEnv ); return 0; } if ( !SQL_SUCCEEDED( SQLConnect( *phDbc, (SQLCHAR*)szDSN, SQL_NTS, (SQLCHAR*)szUID, SQL_NTS, (SQLCHAR*)szPWD, SQL_NTS ))) { if ( bVerbose ) DumpODBCLog( hEnv, hDbc, 0 ); fprintf( stderr, "[ISQL]ERROR: Could not SQLConnect\n" ); SQLFreeConnect( *phDbc ); SQLFreeEnv( *phEnv ); return 0; } } /* * does the driver support SQLMoreResults */ if ( !SQL_SUCCEEDED( SQLGetFunctions( *phDbc, SQL_API_SQLMORERESULTS, &has_moreresults ))) { has_moreresults = 0; } return 1; }
static int odbc_dispatch11(void) { unsigned long retval; PWord rval; int rtype; PWord arg1; int type1; PWord arg2; int type2; PWord arg3; int type3; PWord arg4; int type4; PWord arg5; int type5; PI_getan(&arg1,&type1,1); if (type1 != PI_INT) if (!CI_get_integer((unsigned long *)&arg1,type1)) PI_FAIL; PI_getan(&arg2,&type2,2); if (type2 != PI_INT) if (!CI_get_integer((unsigned long *)&arg2,type2)) PI_FAIL; PI_getan(&arg3,&type3,3); if (type3 != PI_INT) if (!CI_get_integer((unsigned long *)&arg3,type3)) PI_FAIL; PI_getan(&arg4,&type4,4); if (type4 != PI_INT) if (!CI_get_integer((unsigned long *)&arg4,type4)) PI_FAIL; PI_getan(&arg5,&type5,5); switch(arg1) { case 0: retval = (unsigned long) SQLAllocHandleStd(((SQLSMALLINT ) arg2),((SQLHANDLE ) arg3),((SQLHANDLE * ) arg4)); break; case 1: retval = (unsigned long) SQLParamOptions(((SQLHSTMT ) arg2),((SQLUINTEGER ) arg3),((SQLUINTEGER * ) arg4)); break; case 2: retval = (unsigned long) SQLTransact(((SQLHENV ) arg2),((SQLHDBC ) arg3),((SQLUSMALLINT ) arg4)); break; case 3: retval = (unsigned long) SQLSetStmtOption(((SQLHSTMT ) arg2),((SQLUSMALLINT ) arg3),((SQLUINTEGER ) arg4)); break; case 4: retval = (unsigned long) SQLSetConnectOption(((SQLHDBC ) arg2),((SQLUSMALLINT ) arg3),((SQLUINTEGER ) arg4)); break; case 5: retval = (unsigned long) SQLPutData(((SQLHSTMT ) arg2),((SQLPOINTER ) arg3),((SQLINTEGER ) arg4)); break; case 6: retval = (unsigned long) SQLGetStmtOption(((SQLHSTMT ) arg2),((SQLUSMALLINT ) arg3),((SQLPOINTER ) arg4)); break; case 7: retval = (unsigned long) SQLGetFunctions(((SQLHDBC ) arg2),((SQLUSMALLINT ) arg3),((SQLUSMALLINT * ) arg4)); break; case 8: retval = (unsigned long) SQLGetConnectOption(((SQLHDBC ) arg2),((SQLUSMALLINT ) arg3),((SQLPOINTER ) arg4)); break; case 9: retval = (unsigned long) SQLFetchScroll(((SQLHSTMT ) arg2),((SQLSMALLINT ) arg3),((SQLINTEGER ) arg4)); break; case 10: retval = (unsigned long) SQLEndTran(((SQLSMALLINT ) arg2),((SQLHANDLE ) arg3),((SQLSMALLINT ) arg4)); break; case 11: retval = (unsigned long) SQLAllocHandle(((SQLSMALLINT ) arg2),((SQLHANDLE ) arg3),((SQLHANDLE * ) arg4)); break; default: PI_FAIL; } PI_makedouble(&rval,&rtype,(double) retval); if (PI_unify(arg5,type5,rval,rtype)) PI_SUCCEED; PI_FAIL; }