+bool wxDb::Open(wxDbConnectInf *dbConnectInf, bool failOnDataTypeUnsupported)
+{
+ wxASSERT(dbConnectInf);
+
+ // Use the connection string if one is present
+ if (dbConnectInf->UseConnectionStr())
+ return Open(GetConnectionInStr(), failOnDataTypeUnsupported);
+ else
+ return Open(dbConnectInf->GetDsn(), dbConnectInf->GetUserID(),
+ dbConnectInf->GetPassword(), failOnDataTypeUnsupported);
+} // wxDb::Open()
+
+
+bool wxDb::Open(wxDb *copyDb)
+{
+ dsn = copyDb->GetDatasourceName();
+ uid = copyDb->GetUsername();
+ authStr = copyDb->GetPassword();
+ inConnectionStr = copyDb->GetConnectionInStr();
+ outConnectionStr = copyDb->GetConnectionOutStr();
+
+ RETCODE retcode;
+
+ if (!FwdOnlyCursors())
+ {
+ // Specify that the ODBC cursor library be used, if needed. This must be
+ // specified before the connection is made.
+ retcode = SQLSetConnectOption(hdbc, SQL_ODBC_CURSORS, SQL_CUR_USE_IF_NEEDED);
+
+#ifdef DBDEBUG_CONSOLE
+ if (retcode == SQL_SUCCESS)
+ cout << wxT("SQLSetConnectOption(CURSOR_LIB) successful") << endl;
+ else
+ cout << wxT("SQLSetConnectOption(CURSOR_LIB) failed") << endl;
+#else
+ wxUnusedVar( retcode );
+#endif
+ }
+
+ if (copyDb->OpenedWithConnectionString())
+ {
+ // Connect to the data source
+ SQLTCHAR outConnectBuffer[SQL_MAX_CONNECTSTR_LEN+1];
+ short outConnectBufferLen;
+
+ inConnectionStr = copyDb->GetConnectionInStr();
+
+ retcode = SQLDriverConnect(hdbc, NULL, (SQLTCHAR FAR *)inConnectionStr.c_str(),
+ inConnectionStr.Length(), (SQLTCHAR FAR *)outConnectBuffer,
+ sizeof(outConnectBuffer), &outConnectBufferLen, SQL_DRIVER_COMPLETE);
+
+ if ((retcode != SQL_SUCCESS) &&
+ (retcode != SQL_SUCCESS_WITH_INFO))
+ return(DispAllErrors(henv, hdbc));
+
+ outConnectBuffer[outConnectBufferLen] = 0;
+ outConnectionStr = outConnectBuffer;
+ dbOpenedWithConnectionString = true;
+ }
+ else
+ {
+ // Connect to the data source
+ retcode = SQLConnect(hdbc, (SQLTCHAR FAR *) dsn.c_str(), SQL_NTS,
+ (SQLTCHAR FAR *) uid.c_str(), SQL_NTS,
+ (SQLTCHAR FAR *) authStr.c_str(), SQL_NTS);
+ }
+
+ if ((retcode != SQL_SUCCESS) &&
+ (retcode != SQL_SUCCESS_WITH_INFO))
+ return(DispAllErrors(henv, hdbc));
+
+/*
+ If using Intersolv branded ODBC drivers, this is the place where you would substitute
+ your branded driver license information
+
+ SQLSetConnectOption(hdbc, 1041, (UDWORD) wxEmptyString);
+ SQLSetConnectOption(hdbc, 1042, (UDWORD) wxEmptyString);
+*/
+
+ // Mark database as open
+ dbIsOpen = true;
+
+ // Allocate a statement handle for the database connection
+ if (SQLAllocStmt(hdbc, &hstmt) != SQL_SUCCESS)
+ return(DispAllErrors(henv, hdbc));
+
+ // Set Connection Options
+ if (!setConnectionOptions())
+ return false;
+
+ // Instead of Querying the data source for info about itself, it can just be copied
+ // from the wxDb instance that was passed in (copyDb).
+ wxStrcpy(dbInf.serverName,copyDb->dbInf.serverName);
+ wxStrcpy(dbInf.databaseName,copyDb->dbInf.databaseName);
+ wxStrcpy(dbInf.dbmsName,copyDb->dbInf.dbmsName);
+ wxStrcpy(dbInf.dbmsVer,copyDb->dbInf.dbmsVer);
+ dbInf.maxConnections = copyDb->dbInf.maxConnections;
+ dbInf.maxStmts = copyDb->dbInf.maxStmts;
+ wxStrcpy(dbInf.driverName,copyDb->dbInf.driverName);
+ wxStrcpy(dbInf.odbcVer,copyDb->dbInf.odbcVer);
+ wxStrcpy(dbInf.drvMgrOdbcVer,copyDb->dbInf.drvMgrOdbcVer);
+ wxStrcpy(dbInf.driverVer,copyDb->dbInf.driverVer);
+ dbInf.apiConfLvl = copyDb->dbInf.apiConfLvl;
+ dbInf.cliConfLvl = copyDb->dbInf.cliConfLvl;
+ dbInf.sqlConfLvl = copyDb->dbInf.sqlConfLvl;
+ wxStrcpy(dbInf.outerJoins,copyDb->dbInf.outerJoins);
+ wxStrcpy(dbInf.procedureSupport,copyDb->dbInf.procedureSupport);
+ wxStrcpy(dbInf.accessibleTables,copyDb->dbInf.accessibleTables);
+ dbInf.cursorCommitBehavior = copyDb->dbInf.cursorCommitBehavior;
+ dbInf.cursorRollbackBehavior = copyDb->dbInf.cursorRollbackBehavior;
+ dbInf.supportNotNullClause = copyDb->dbInf.supportNotNullClause;
+ wxStrcpy(dbInf.supportIEF,copyDb->dbInf.supportIEF);
+ dbInf.txnIsolation = copyDb->dbInf.txnIsolation;
+ dbInf.txnIsolationOptions = copyDb->dbInf.txnIsolationOptions;
+ dbInf.fetchDirections = copyDb->dbInf.fetchDirections;
+ dbInf.lockTypes = copyDb->dbInf.lockTypes;
+ dbInf.posOperations = copyDb->dbInf.posOperations;
+ dbInf.posStmts = copyDb->dbInf.posStmts;
+ dbInf.scrollConcurrency = copyDb->dbInf.scrollConcurrency;
+ dbInf.scrollOptions = copyDb->dbInf.scrollOptions;
+ dbInf.staticSensitivity = copyDb->dbInf.staticSensitivity;
+ dbInf.txnCapable = copyDb->dbInf.txnCapable;
+ dbInf.loginTimeout = copyDb->dbInf.loginTimeout;
+
+ // VARCHAR = Variable length character string
+ typeInfVarchar.FsqlType = copyDb->typeInfVarchar.FsqlType;
+ typeInfVarchar.TypeName = copyDb->typeInfVarchar.TypeName;
+ typeInfVarchar.Precision = copyDb->typeInfVarchar.Precision;
+ typeInfVarchar.CaseSensitive = copyDb->typeInfVarchar.CaseSensitive;
+ typeInfVarchar.MaximumScale = copyDb->typeInfVarchar.MaximumScale;
+
+ // Float
+ typeInfFloat.FsqlType = copyDb->typeInfFloat.FsqlType;
+ typeInfFloat.TypeName = copyDb->typeInfFloat.TypeName;
+ typeInfFloat.Precision = copyDb->typeInfFloat.Precision;
+ typeInfFloat.CaseSensitive = copyDb->typeInfFloat.CaseSensitive;
+ typeInfFloat.MaximumScale = copyDb->typeInfFloat.MaximumScale;
+
+ // Integer
+ typeInfInteger.FsqlType = copyDb->typeInfInteger.FsqlType;
+ typeInfInteger.TypeName = copyDb->typeInfInteger.TypeName;
+ typeInfInteger.Precision = copyDb->typeInfInteger.Precision;
+ typeInfInteger.CaseSensitive = copyDb->typeInfInteger.CaseSensitive;
+ typeInfInteger.MaximumScale = copyDb->typeInfInteger.MaximumScale;
+
+ // Date/Time
+ typeInfDate.FsqlType = copyDb->typeInfDate.FsqlType;
+ typeInfDate.TypeName = copyDb->typeInfDate.TypeName;
+ typeInfDate.Precision = copyDb->typeInfDate.Precision;
+ typeInfDate.CaseSensitive = copyDb->typeInfDate.CaseSensitive;
+ typeInfDate.MaximumScale = copyDb->typeInfDate.MaximumScale;
+
+ // Blob
+ typeInfBlob.FsqlType = copyDb->typeInfBlob.FsqlType;
+ typeInfBlob.TypeName = copyDb->typeInfBlob.TypeName;
+ typeInfBlob.Precision = copyDb->typeInfBlob.Precision;
+ typeInfBlob.CaseSensitive = copyDb->typeInfBlob.CaseSensitive;
+ typeInfBlob.MaximumScale = copyDb->typeInfBlob.MaximumScale;
+
+#ifdef DBDEBUG_CONSOLE
+ cout << wxT("VARCHAR DATA TYPE: ") << typeInfVarchar.TypeName << endl;
+ cout << wxT("INTEGER DATA TYPE: ") << typeInfInteger.TypeName << endl;
+ cout << wxT("FLOAT DATA TYPE: ") << typeInfFloat.TypeName << endl;
+ cout << wxT("DATE DATA TYPE: ") << typeInfDate.TypeName << endl;
+ cout << wxT("BLOB DATA TYPE: ") << typeInfBlob.TypeName << endl;
+ cout << endl;
+#endif
+
+ // Completed Successfully
+ return true;
+} // wxDb::Open() 2
+
+