/* disconnect from the database. Return true if * an error occurs that is trapped by the application. */ static bool disconnect(void) { stmt_text = 0; hstmt = SQL_NULL_HSTMT; if(!sql_database) return false; /* already disconnected */ stmt_text = "disconnect"; debugStatement(); rc = SQLDisconnect(hdbc); if(errorTrap(0)) return true; clearAllCursors(); /* those handles are freed as well */ translevel = 0; sql_database = 0; return false; } /* disconnect */
IMCursorManager::~IMCursorManager() { clearAllCursors(); }
void sql_connect(const char *db, const char *login, const char *pw) { short waste; char constring[200]; char outstring[200]; char drivername[40]; char *s; if(isnullstring(db)) errorPrint ("2sql_connect receives no data source, check your edbrowse config file"); if(debugLevel >= 1) i_printf(MSG_DBConnecting, db); /* first disconnect the old one */ if(disconnect()) return; /* initial call to sql_connect sets up ODBC */ if(henv == SQL_NULL_HENV) { char verstring[6]; /* Allocate environment and connection handles */ /* these two handles are never freed */ rc = SQLAllocEnv(&henv); if(rc) errorPrint("@could not alloc ODBC environment handle"); rc = SQLAllocConnect(henv, &hdbc); if(rc) errorPrint("@could not alloc ODBC connection handle"); /* Establish the ODBC major version number. * Course the call to make this determination doesn't exist * prior to version 2.0. */ odbc_version = 1; rc = SQLGetInfo(hdbc, SQL_DRIVER_ODBC_VER, verstring, 6, &waste); if(!rc) { verstring[2] = 0; odbc_version = atoi(verstring); } } /* connect to the database */ sprintf(constring, "DSN=%s", db); if(login) { s = constring + strlen(constring); sprintf(s, ";UID=%s", login); } if(pw) { s = constring + strlen(constring); sprintf(s, ";PWD=%s", pw); } stmt_text = constring; debugStatement(); rc = SQLDriverConnect(hdbc, NULL, constring, SQL_NTS, outstring, sizeof (outstring), &waste, SQL_DRIVER_NOPROMPT); if(errorTrap(0)) return; sql_database = db; exclist = 0; /* Set the persistent connect/statement options. * Note that some of these merely reassert the default, * but it's good documentation to spell it out here. */ stmt_text = "noscan on"; rc = SQLSetConnectOption(hdbc, SQL_NOSCAN, SQL_NOSCAN_ON); stmt_text = "repeatable read"; rc = SQLSetConnectOption(hdbc, SQL_TXN_ISOLATION, SQL_TXN_REPEATABLE_READ); /* fail */ stmt_text = "rowset size"; rc = SQLSetConnectOption(hdbc, SQL_ROWSET_SIZE, 1); stmt_text = "login timeout"; rc = SQLSetConnectOption(hdbc, SQL_LOGIN_TIMEOUT, 15); /* fail */ stmt_text = "query timeout"; rc = SQLSetConnectOption(hdbc, SQL_QUERY_TIMEOUT, 0); /* fail */ stmt_text = "async disable"; rc = SQLSetConnectOption(hdbc, SQL_ASYNC_ENABLE, SQL_ASYNC_ENABLE_OFF); /* fail */ stmt_text = "autocommit"; rc = SQLSetConnectOption(hdbc, SQL_AUTOCOMMIT, SQL_AUTOCOMMIT_ON); stmt_text = "cursor forward"; rc = SQLSetConnectOption(hdbc, SQL_CURSOR_TYPE, SQL_CURSOR_FORWARD_ONLY); stmt_text = "concurrent reads"; rc = SQLSetConnectOption(hdbc, SQL_CONCURRENCY, SQL_CONCUR_READ_ONLY); stmt_text = "use driver"; rc = SQLSetConnectOption(hdbc, SQL_ODBC_CURSORS, SQL_CUR_USE_DRIVER); /* fail */ stmt_text = "no bookmarks"; rc = SQLSetConnectOption(hdbc, SQL_USE_BOOKMARKS, SQL_UB_OFF); /* fail */ /* this call is only necessary if SQL_NULL_HSTMT != 0 */ clearAllCursors(); /* set defaults, in case the GetInfo command fails */ cursors_under_commit = cursors_under_rollback = SQL_CB_DELETE; SQLGetInfo(hdbc, SQL_CURSOR_COMMIT_BEHAVIOR, &cursors_under_commit, 4, &waste); SQLGetInfo(hdbc, SQL_CURSOR_ROLLBACK_BEHAVIOR, &cursors_under_rollback, 4, &waste); getdata_opts = 0; SQLGetInfo(hdbc, SQL_GETDATA_EXTENSIONS, &getdata_opts, 4, &waste); bookmarkBits = false; SQLGetInfo(hdbc, SQL_BOOKMARK_PERSISTENCE, &bookmarkBits, 4, &waste); exclist = 0; /* Time to find out what the driver is, so we can have driver specific tweaks. */ SQLGetInfo(hdbc, SQL_DRIVER_NAME, drivername, sizeof (drivername), &waste); current_driver = DRIVER_NONE; if(stringEqual(drivername, "libsqliteodbc.so") || stringEqual(drivername, "sqlite3odbc.so")) current_driver = DRIVER_SQLITE; if(stringEqual(drivername, "libmyodbc.so")) current_driver = DRIVER_MYSQL; if(stringEqual(drivername, "libodbcpsql.so")) current_driver = DRIVER_POSTGRESQL; if(stringEqual(drivername, "iclis09b.so")) current_driver = DRIVER_INFORMIX; if(stringEqual(drivername, "libtdsodbc.so")) { current_driver = DRIVER_TDS; openfirst = true; } if(sql_debug) { if(current_driver) appendFile(sql_debuglog, "driver is %d", current_driver); else appendFile(sql_debuglog, "driver string is %s", drivername); } exclist = 0; } /* sql_connect */