Commit 180b2be6 authored by Olivier Bertrand's avatar Olivier Bertrand

- Add the possibility to establish an ODBC connection via SQLConnect (the

  default being still to use SQLDriverConnect)
modified:
  storage/connect/ha_connect.cc
  storage/connect/odbccat.h
  storage/connect/odbconn.cpp
  storage/connect/odbconn.h
  storage/connect/tabodbc.cpp
  storage/connect/tabodbc.h

- Cardinality testing not possible for TBL tables
modified:
  storage/connect/tabtbl.cpp

- Make all line ending LF instead of CRLF
modified:
  storage/connect/tabjson.cpp
parent fd1ca70b
...@@ -934,6 +934,9 @@ ulonglong ha_connect::table_flags() const ...@@ -934,6 +934,9 @@ ulonglong ha_connect::table_flags() const
char *GetListOption(PGLOBAL g, const char *opname, char *GetListOption(PGLOBAL g, const char *opname,
const char *oplist, const char *def) const char *oplist, const char *def)
{ {
if (!oplist)
return (char*)def;
char key[16], val[256]; char key[16], val[256];
char *pk, *pv, *pn; char *pk, *pv, *pn;
char *opval= (char*) def; char *opval= (char*) def;
...@@ -4847,10 +4850,12 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd, ...@@ -4847,10 +4850,12 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd,
int port= 0, hdr= 0, mxr __attribute__((unused))= 0, mxe= 0, rc= 0; int port= 0, hdr= 0, mxr __attribute__((unused))= 0, mxe= 0, rc= 0;
int cop __attribute__((unused)) = 0; int cop __attribute__((unused)) = 0;
#if defined(ODBC_SUPPORT) #if defined(ODBC_SUPPORT)
POPARM sop;
char *ucnc;
int cto= -1, qto= -1; int cto= -1, qto= -1;
#endif // ODBC_SUPPORT #endif // ODBC_SUPPORT
uint tm, fnc= FNC_NO, supfnc= (FNC_NO | FNC_COL); uint tm, fnc= FNC_NO, supfnc= (FNC_NO | FNC_COL);
bool bif, ok= false, dbf= false; bool bif, ok= false, dbf= false, cnc= false;;
TABTYPE ttp= TAB_UNDEF; TABTYPE ttp= TAB_UNDEF;
PQRYRES qrp= NULL; PQRYRES qrp= NULL;
PCOLRES crp; PCOLRES crp;
...@@ -4891,7 +4896,8 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd, ...@@ -4891,7 +4896,8 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd,
if (topt->oplist) { if (topt->oplist) {
host= GetListOption(g, "host", topt->oplist, "localhost"); host= GetListOption(g, "host", topt->oplist, "localhost");
user= GetListOption(g, "user", topt->oplist, "root"); user= GetListOption(g, "user", topt->oplist,
(ttp == TAB_ODBC ? NULL : "root"));
// Default value db can come from the DBNAME=xxx option. // Default value db can come from the DBNAME=xxx option.
db= GetListOption(g, "database", topt->oplist, db); db= GetListOption(g, "database", topt->oplist, db);
col= GetListOption(g, "colist", topt->oplist, col); col= GetListOption(g, "colist", topt->oplist, col);
...@@ -4910,6 +4916,8 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd, ...@@ -4910,6 +4916,8 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd,
mxr= atoi(GetListOption(g,"maxres", topt->oplist, "0")); mxr= atoi(GetListOption(g,"maxres", topt->oplist, "0"));
cto= atoi(GetListOption(g,"ConnectTimeout", topt->oplist, "-1")); cto= atoi(GetListOption(g,"ConnectTimeout", topt->oplist, "-1"));
qto= atoi(GetListOption(g,"QueryTimeout", topt->oplist, "-1")); qto= atoi(GetListOption(g,"QueryTimeout", topt->oplist, "-1"));
if ((ucnc= GetListOption(g, "UseDSN", topt->oplist)))
cnc= (!*ucnc || *ucnc == 'y' || *ucnc == 'Y' || atoi(ucnc) != 0);
#endif #endif
mxe= atoi(GetListOption(g,"maxerr", topt->oplist, "0")); mxe= atoi(GetListOption(g,"maxerr", topt->oplist, "0"));
#if defined(PROMPT_OK) #if defined(PROMPT_OK)
...@@ -4994,10 +5002,18 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd, ...@@ -4994,10 +5002,18 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd,
} // endif dsn } // endif dsn
#endif // PROMPT_OK #endif // PROMPT_OK
} else if (!dsn) } else if (!dsn) {
sprintf(g->Message, "Missing %s connection string", topt->type); sprintf(g->Message, "Missing %s connection string", topt->type);
else } else {
// Store ODBC additional parameters
sop= (POPARM)PlugSubAlloc(g, NULL, sizeof(ODBCPARM));
sop->User= (char*)user;
sop->Pwd= (char*)pwd;
sop->Cto= cto;
sop->Qto= qto;
sop->UseCnc=cnc;
ok= true; ok= true;
} // endif's
supfnc |= (FNC_TABLE | FNC_DSN | FNC_DRIVER); supfnc |= (FNC_TABLE | FNC_DSN | FNC_DRIVER);
break; break;
...@@ -5128,15 +5144,15 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd, ...@@ -5128,15 +5144,15 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd,
case FNC_NO: case FNC_NO:
case FNC_COL: case FNC_COL:
if (src) { if (src) {
qrp= ODBCSrcCols(g, dsn, (char*)src, cto, qto); qrp= ODBCSrcCols(g, dsn, (char*)src, sop);
src= NULL; // for next tests src= NULL; // for next tests
} else } else
qrp= ODBCColumns(g, dsn, shm, tab, NULL, qrp= ODBCColumns(g, dsn, shm, tab, NULL,
mxr, cto, qto, fnc == FNC_COL); mxr, fnc == FNC_COL, sop);
break; break;
case FNC_TABLE: case FNC_TABLE:
qrp= ODBCTables(g, dsn, shm, tab, mxr, cto, qto, true); qrp= ODBCTables(g, dsn, shm, tab, mxr, true, sop);
break; break;
case FNC_DSN: case FNC_DSN:
qrp= ODBCDataSources(g, mxr, true); qrp= ODBCDataSources(g, mxr, true);
......
...@@ -2,6 +2,14 @@ ...@@ -2,6 +2,14 @@
#define DEFAULT_LOGIN_TIMEOUT -1 // means do not set #define DEFAULT_LOGIN_TIMEOUT -1 // means do not set
#define DEFAULT_QUERY_TIMEOUT -1 // means do not set #define DEFAULT_QUERY_TIMEOUT -1 // means do not set
typedef struct odbc_parms {
char *User; // User connect info
char *Pwd; // Password connect info
int Cto; // Connect timeout
int Qto; // Query timeout
bool UseCnc; // Use SQLConnect (!SQLDriverConnect)
} ODBCPARM, *POPARM;
/***********************************************************************/ /***********************************************************************/
/* ODBC catalog function prototypes. */ /* ODBC catalog function prototypes. */
/***********************************************************************/ /***********************************************************************/
...@@ -10,8 +18,8 @@ char *ODBCCheckConnection(PGLOBAL g, char *dsn, int cop); ...@@ -10,8 +18,8 @@ char *ODBCCheckConnection(PGLOBAL g, char *dsn, int cop);
#endif // PROMPT_OK #endif // PROMPT_OK
PQRYRES ODBCDataSources(PGLOBAL g, int maxres, bool info); PQRYRES ODBCDataSources(PGLOBAL g, int maxres, bool info);
PQRYRES ODBCColumns(PGLOBAL g, char *dsn, char *db, char *table, PQRYRES ODBCColumns(PGLOBAL g, char *dsn, char *db, char *table,
char *colpat, int maxres, int cto, int qto, bool info); char *colpat, int maxres, bool info, POPARM sop);
PQRYRES ODBCSrcCols(PGLOBAL g, char *dsn, char *src, int cto, int qto); PQRYRES ODBCSrcCols(PGLOBAL g, char *dsn, char *src, POPARM sop);
PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *db, char *tabpat, PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *db, char *tabpat,
int maxres, int cto, int qto, bool info); int maxres, bool info, POPARM sop);
PQRYRES ODBCDrivers(PGLOBAL g, int maxres, bool info); PQRYRES ODBCDrivers(PGLOBAL g, int maxres, bool info);
...@@ -37,8 +37,8 @@ ...@@ -37,8 +37,8 @@
#include "xobject.h" #include "xobject.h"
//#include "kindex.h" //#include "kindex.h"
#include "xtable.h" #include "xtable.h"
#include "tabodbc.h"
#include "odbccat.h" #include "odbccat.h"
#include "tabodbc.h"
#include "plgcnx.h" // For DB types #include "plgcnx.h" // For DB types
#include "resource.h" #include "resource.h"
#include "valblk.h" #include "valblk.h"
...@@ -291,7 +291,7 @@ static void ResetNullValues(CATPARM *cap) ...@@ -291,7 +291,7 @@ static void ResetNullValues(CATPARM *cap)
/* of an ODBC table that will be retrieved by GetData commands. */ /* of an ODBC table that will be retrieved by GetData commands. */
/***********************************************************************/ /***********************************************************************/
PQRYRES ODBCColumns(PGLOBAL g, char *dsn, char *db, char *table, PQRYRES ODBCColumns(PGLOBAL g, char *dsn, char *db, char *table,
char *colpat, int maxres, int cto, int qto, bool info) char *colpat, int maxres, bool info, POPARM sop)
{ {
int buftyp[] = {TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_STRING, int buftyp[] = {TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_STRING,
TYPE_SHORT, TYPE_STRING, TYPE_INT, TYPE_INT, TYPE_SHORT, TYPE_STRING, TYPE_INT, TYPE_INT,
...@@ -310,10 +310,8 @@ PQRYRES ODBCColumns(PGLOBAL g, char *dsn, char *db, char *table, ...@@ -310,10 +310,8 @@ PQRYRES ODBCColumns(PGLOBAL g, char *dsn, char *db, char *table,
/************************************************************************/ /************************************************************************/
if (!info) { if (!info) {
ocp = new(g) ODBConn(g, NULL); ocp = new(g) ODBConn(g, NULL);
ocp->SetLoginTimeout((DWORD)cto);
ocp->SetQueryTimeout((DWORD)qto);
if (ocp->Open(dsn, 10) < 1) // openReadOnly + noODBCdialog if (ocp->Open(dsn, sop, 10) < 1) // openReadOnly + noODBCdialog
return NULL; return NULL;
if (table && !strchr(table, '%')) { if (table && !strchr(table, '%')) {
...@@ -388,12 +386,13 @@ PQRYRES ODBCColumns(PGLOBAL g, char *dsn, char *db, char *table, ...@@ -388,12 +386,13 @@ PQRYRES ODBCColumns(PGLOBAL g, char *dsn, char *db, char *table,
/* ODBCSrcCols: constructs the result blocks containing the */ /* ODBCSrcCols: constructs the result blocks containing the */
/* description of all the columns of a Srcdef option. */ /* description of all the columns of a Srcdef option. */
/**************************************************************************/ /**************************************************************************/
PQRYRES ODBCSrcCols(PGLOBAL g, char *dsn, char *src, int cto, int qto) PQRYRES ODBCSrcCols(PGLOBAL g, char *dsn, char *src, POPARM sop)
{ {
ODBConn *ocp = new(g) ODBConn(g, NULL); ODBConn *ocp = new(g) ODBConn(g, NULL);
ocp->SetLoginTimeout((DWORD)cto); if (ocp->Open(dsn, sop, 10) < 1) // openReadOnly + noOdbcDialog
ocp->SetQueryTimeout((DWORD)qto); return NULL;
return ocp->GetMetaData(g, dsn, src); return ocp->GetMetaData(g, dsn, src);
} // end of ODBCSrcCols } // end of ODBCSrcCols
...@@ -574,7 +573,7 @@ PQRYRES ODBCDataSources(PGLOBAL g, int maxres, bool info) ...@@ -574,7 +573,7 @@ PQRYRES ODBCDataSources(PGLOBAL g, int maxres, bool info)
/* an ODBC database that will be retrieved by GetData commands. */ /* an ODBC database that will be retrieved by GetData commands. */
/**************************************************************************/ /**************************************************************************/
PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *db, char *tabpat, PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *db, char *tabpat,
int maxres, int cto, int qto, bool info) int maxres, bool info, POPARM sop)
{ {
int buftyp[] = {TYPE_STRING, TYPE_STRING, TYPE_STRING, int buftyp[] = {TYPE_STRING, TYPE_STRING, TYPE_STRING,
TYPE_STRING, TYPE_STRING}; TYPE_STRING, TYPE_STRING};
...@@ -594,10 +593,8 @@ PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *db, char *tabpat, ...@@ -594,10 +593,8 @@ PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *db, char *tabpat,
/* Open the connection with the ODBC data source. */ /* Open the connection with the ODBC data source. */
/**********************************************************************/ /**********************************************************************/
ocp = new(g) ODBConn(g, NULL); ocp = new(g) ODBConn(g, NULL);
ocp->SetLoginTimeout((DWORD)cto);
ocp->SetQueryTimeout((DWORD)qto);
if (ocp->Open(dsn, 2) < 1) // 2 is openReadOnly if (ocp->Open(dsn, sop, 2) < 1) // 2 is openReadOnly
return NULL; return NULL;
if (!maxres) if (!maxres)
...@@ -925,6 +922,8 @@ ODBConn::ODBConn(PGLOBAL g, TDBODBC *tdbp) ...@@ -925,6 +922,8 @@ ODBConn::ODBConn(PGLOBAL g, TDBODBC *tdbp)
m_Catver = (tdbp) ? tdbp->Catver : 0; m_Catver = (tdbp) ? tdbp->Catver : 0;
m_Rows = 0; m_Rows = 0;
m_Connect = NULL; m_Connect = NULL;
m_User = NULL;
m_Pwd = NULL;
m_Updatable = true; m_Updatable = true;
m_Transact = false; m_Transact = false;
m_Scrollable = (tdbp) ? tdbp->Scrollable : false; m_Scrollable = (tdbp) ? tdbp->Scrollable : false;
...@@ -1061,7 +1060,7 @@ void ODBConn::OnSetOptions(HSTMT hstmt) ...@@ -1061,7 +1060,7 @@ void ODBConn::OnSetOptions(HSTMT hstmt)
/***********************************************************************/ /***********************************************************************/
/* Open: connect to a data source. */ /* Open: connect to a data source. */
/***********************************************************************/ /***********************************************************************/
int ODBConn::Open(PSZ ConnectString, DWORD options) int ODBConn::Open(PSZ ConnectString, POPARM sop, DWORD options)
{ {
PGLOBAL& g = m_G; PGLOBAL& g = m_G;
//ASSERT_VALID(this); //ASSERT_VALID(this);
...@@ -1070,6 +1069,11 @@ int ODBConn::Open(PSZ ConnectString, DWORD options) ...@@ -1070,6 +1069,11 @@ int ODBConn::Open(PSZ ConnectString, DWORD options)
m_Updatable = !(options & openReadOnly); m_Updatable = !(options & openReadOnly);
m_Connect = ConnectString; m_Connect = ConnectString;
m_User = sop->User;
m_Pwd = sop->Pwd;
m_LoginTimeout = sop->Cto;
m_QueryTimeout = sop->Qto;
m_UseCnc = sop->UseCnc;
// Allocate the HDBC and make connection // Allocate the HDBC and make connection
try { try {
...@@ -1078,10 +1082,22 @@ int ODBConn::Open(PSZ ConnectString, DWORD options) ...@@ -1078,10 +1082,22 @@ int ODBConn::Open(PSZ ConnectString, DWORD options)
AllocConnect(options); AllocConnect(options);
/*ver = GetStringInfo(SQL_ODBC_VER);*/ /*ver = GetStringInfo(SQL_ODBC_VER);*/
if (Connect(options)) { #if 0
// Connect using SQLDriverConnect
if (DriverConnect(options)) {
strcpy(g->Message, MSG(CONNECT_CANCEL)); strcpy(g->Message, MSG(CONNECT_CANCEL));
return 0; return 0;
} // endif } // endif
#endif // 0
if (!m_UseCnc) {
if (DriverConnect(options)) {
strcpy(g->Message, MSG(CONNECT_CANCEL));
return 0;
} // endif
} else // Connect using SQLConnect
Connect();
/*ver = GetStringInfo(SQL_DRIVER_ODBC_VER);*/ /*ver = GetStringInfo(SQL_DRIVER_ODBC_VER);*/
// Verify support for required functionality and cache info // Verify support for required functionality and cache info
...@@ -1163,10 +1179,27 @@ void ODBConn::AllocConnect(DWORD Options) ...@@ -1163,10 +1179,27 @@ void ODBConn::AllocConnect(DWORD Options)
return; return;
} // end of AllocConnect } // end of AllocConnect
/***********************************************************************/
/* Connect to data source using SQLConnect. */
/***********************************************************************/
void ODBConn::Connect(void)
{
SQLRETURN rc;
SQLSMALLINT ul = (m_User ? SQL_NTS : 0);
SQLSMALLINT pl = (m_Pwd ? SQL_NTS : 0);
rc = SQLConnect(m_hdbc, (SQLCHAR*)m_Connect, SQL_NTS,
(SQLCHAR*)m_User, ul, (SQLCHAR*)m_Pwd, pl);
if (!Check(rc))
ThrowDBX(rc, "SQLConnect");
} // end of Connect
/***********************************************************************/ /***********************************************************************/
/* Connect to data source using SQLDriverConnect. */ /* Connect to data source using SQLDriverConnect. */
/***********************************************************************/ /***********************************************************************/
bool ODBConn::Connect(DWORD Options) bool ODBConn::DriverConnect(DWORD Options)
{ {
RETCODE rc; RETCODE rc;
SWORD nResult; SWORD nResult;
...@@ -1213,7 +1246,7 @@ bool ODBConn::Connect(DWORD Options) ...@@ -1213,7 +1246,7 @@ bool ODBConn::Connect(DWORD Options)
// All done // All done
return false; return false;
} // end of Connect } // end of DriverConnect
void ODBConn::VerifyConnect() void ODBConn::VerifyConnect()
{ {
...@@ -1865,9 +1898,6 @@ PQRYRES ODBConn::GetMetaData(PGLOBAL g, char *dsn, char *src) ...@@ -1865,9 +1898,6 @@ PQRYRES ODBConn::GetMetaData(PGLOBAL g, char *dsn, char *src)
RETCODE rc; RETCODE rc;
HSTMT hstmt; HSTMT hstmt;
if (Open(dsn, 10) < 1) // openReadOnly + noOdbcDialog
return NULL;
try { try {
rc = SQLAllocStmt(m_hdbc, &hstmt); rc = SQLAllocStmt(m_hdbc, &hstmt);
......
...@@ -119,7 +119,7 @@ class ODBConn : public BLOCK { ...@@ -119,7 +119,7 @@ class ODBConn : public BLOCK {
noOdbcDialog = 0x0008, // Don't display ODBC Connect dialog noOdbcDialog = 0x0008, // Don't display ODBC Connect dialog
forceOdbcDialog = 0x0010}; // Always display ODBC connect dialog forceOdbcDialog = 0x0010}; // Always display ODBC connect dialog
int Open(PSZ ConnectString, DWORD Options = 0); int Open(PSZ ConnectString, POPARM sop, DWORD Options = 0);
int Rewind(char *sql, ODBCCOL *tocols); int Rewind(char *sql, ODBCCOL *tocols);
void Close(void); void Close(void);
PQRYRES AllocateResult(PGLOBAL g); PQRYRES AllocateResult(PGLOBAL g);
...@@ -135,8 +135,10 @@ class ODBConn : public BLOCK { ...@@ -135,8 +135,10 @@ class ODBConn : public BLOCK {
public: public:
// Operations // Operations
void SetLoginTimeout(DWORD sec) {m_LoginTimeout = sec;} //void SetLoginTimeout(DWORD sec) {m_LoginTimeout = sec;}
void SetQueryTimeout(DWORD sec) {m_QueryTimeout = sec;} //void SetQueryTimeout(DWORD sec) {m_QueryTimeout = sec;}
//void SetUserName(PSZ user) {m_User = user;}
//void SetUserPwd(PSZ pwd) {m_Pwd = pwd;}
int GetResultSize(char *sql, ODBCCOL *colp); int GetResultSize(char *sql, ODBCCOL *colp);
int ExecDirectSQL(char *sql, ODBCCOL *tocols); int ExecDirectSQL(char *sql, ODBCCOL *tocols);
int Fetch(void); int Fetch(void);
...@@ -155,7 +157,7 @@ class ODBConn : public BLOCK { ...@@ -155,7 +157,7 @@ class ODBConn : public BLOCK {
// Implementation // Implementation
public: public:
// virtual ~ODBConn(); //virtual ~ODBConn();
// ODBC operations // ODBC operations
protected: protected:
...@@ -163,7 +165,8 @@ class ODBConn : public BLOCK { ...@@ -163,7 +165,8 @@ class ODBConn : public BLOCK {
void ThrowDBX(RETCODE rc, PSZ msg, HSTMT hstmt = SQL_NULL_HSTMT); void ThrowDBX(RETCODE rc, PSZ msg, HSTMT hstmt = SQL_NULL_HSTMT);
void ThrowDBX(PSZ msg); void ThrowDBX(PSZ msg);
void AllocConnect(DWORD dwOptions); void AllocConnect(DWORD dwOptions);
bool Connect(DWORD Options); void Connect(void);
bool DriverConnect(DWORD Options);
void VerifyConnect(void); void VerifyConnect(void);
void GetConnectInfo(void); void GetConnectInfo(void);
void Free(void); void Free(void);
...@@ -185,11 +188,14 @@ class ODBConn : public BLOCK { ...@@ -185,11 +188,14 @@ class ODBConn : public BLOCK {
DWORD m_RowsetSize; DWORD m_RowsetSize;
char m_IDQuoteChar[2]; char m_IDQuoteChar[2];
PSZ m_Connect; PSZ m_Connect;
PSZ m_User;
PSZ m_Pwd;
int m_Catver; int m_Catver;
int m_Rows; int m_Rows;
bool m_Updatable; bool m_Updatable;
bool m_Transact; bool m_Transact;
bool m_Scrollable; bool m_Scrollable;
bool m_UseCnc;
bool m_First; bool m_First;
bool m_Full; bool m_Full;
}; // end of ODBConn class definition }; // end of ODBConn class definition
This diff is collapsed.
...@@ -66,8 +66,8 @@ ...@@ -66,8 +66,8 @@
#include "plgdbsem.h" #include "plgdbsem.h"
#include "mycat.h" #include "mycat.h"
#include "xtable.h" #include "xtable.h"
#include "tabodbc.h"
#include "odbccat.h" #include "odbccat.h"
#include "tabodbc.h"
#include "tabmul.h" #include "tabmul.h"
#include "reldef.h" #include "reldef.h"
#include "tabcol.h" #include "tabcol.h"
...@@ -93,9 +93,10 @@ bool ExactInfo(void); ...@@ -93,9 +93,10 @@ bool ExactInfo(void);
/***********************************************************************/ /***********************************************************************/
ODBCDEF::ODBCDEF(void) ODBCDEF::ODBCDEF(void)
{ {
Connect= Tabname= Tabschema= Tabcat= Srcdef= Qchar= Qrystr= Sep= NULL; Connect = Tabname = Tabschema = Username = Password = NULL;
Tabcat = Srcdef = Qchar = Qrystr = Sep = NULL;
Catver = Options = Cto = Qto = Quoted = Maxerr = Maxres = 0; Catver = Options = Cto = Qto = Quoted = Maxerr = Maxres = 0;
Scrollable = Memory = Xsrc = false; Scrollable = Memory = Xsrc = UseCnc = false;
} // end of ODBCDEF constructor } // end of ODBCDEF constructor
/***********************************************************************/ /***********************************************************************/
...@@ -117,6 +118,8 @@ bool ODBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) ...@@ -117,6 +118,8 @@ bool ODBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
Tabschema = GetStringCatInfo(g, "Schema", Tabschema); Tabschema = GetStringCatInfo(g, "Schema", Tabschema);
Tabcat = GetStringCatInfo(g, "Qualifier", NULL); Tabcat = GetStringCatInfo(g, "Qualifier", NULL);
Tabcat = GetStringCatInfo(g, "Catalog", Tabcat); Tabcat = GetStringCatInfo(g, "Catalog", Tabcat);
Username = GetStringCatInfo(g, "User", NULL);
Password = GetStringCatInfo(g, "Password", NULL);
if ((Srcdef = GetStringCatInfo(g, "Srcdef", NULL))) if ((Srcdef = GetStringCatInfo(g, "Srcdef", NULL)))
Read_Only = true; Read_Only = true;
...@@ -133,6 +136,7 @@ bool ODBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) ...@@ -133,6 +136,7 @@ bool ODBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
Cto= GetIntCatInfo("ConnectTimeout", DEFAULT_LOGIN_TIMEOUT); Cto= GetIntCatInfo("ConnectTimeout", DEFAULT_LOGIN_TIMEOUT);
Qto= GetIntCatInfo("QueryTimeout", DEFAULT_QUERY_TIMEOUT); Qto= GetIntCatInfo("QueryTimeout", DEFAULT_QUERY_TIMEOUT);
Scrollable = GetBoolCatInfo("Scrollable", false); Scrollable = GetBoolCatInfo("Scrollable", false);
UseCnc = GetBoolCatInfo("UseDSN", false);
Memory = GetBoolCatInfo("Memory", false); Memory = GetBoolCatInfo("Memory", false);
Pseudo = 2; // FILID is Ok but not ROWID Pseudo = 2; // FILID is Ok but not ROWID
return false; return false;
...@@ -190,34 +194,40 @@ TDBODBC::TDBODBC(PODEF tdp) : TDBASE(tdp) ...@@ -190,34 +194,40 @@ TDBODBC::TDBODBC(PODEF tdp) : TDBASE(tdp)
Connect = tdp->Connect; Connect = tdp->Connect;
TableName = tdp->Tabname; TableName = tdp->Tabname;
Schema = tdp->Tabschema; Schema = tdp->Tabschema;
Ops.User = tdp->Username;
Ops.Pwd = tdp->Password;
Catalog = tdp->Tabcat; Catalog = tdp->Tabcat;
Srcdef = tdp->Srcdef; Srcdef = tdp->Srcdef;
Qrystr = tdp->Qrystr; Qrystr = tdp->Qrystr;
Sep = tdp->GetSep(); Sep = tdp->GetSep();
Options = tdp->Options; Options = tdp->Options;
Cto = tdp->Cto; Ops.Cto = tdp->Cto;
Qto = tdp->Qto; Ops.Qto = tdp->Qto;
Quoted = MY_MAX(0, tdp->GetQuoted()); Quoted = MY_MAX(0, tdp->GetQuoted());
Rows = tdp->GetElemt(); Rows = tdp->GetElemt();
Catver = tdp->Catver; Catver = tdp->Catver;
Memory = (tdp->Memory) ? 1 : 0; Memory = (tdp->Memory) ? 1 : 0;
Scrollable = tdp->Scrollable; Scrollable = tdp->Scrollable;
Ops.UseCnc = tdp->UseCnc;
} else { } else {
Connect = NULL; Connect = NULL;
TableName = NULL; TableName = NULL;
Schema = NULL; Schema = NULL;
Ops.User = NULL;
Ops.Pwd = NULL;
Catalog = NULL; Catalog = NULL;
Srcdef = NULL; Srcdef = NULL;
Qrystr = NULL; Qrystr = NULL;
Sep = 0; Sep = 0;
Options = 0; Options = 0;
Cto = DEFAULT_LOGIN_TIMEOUT; Ops.Cto = DEFAULT_LOGIN_TIMEOUT;
Qto = DEFAULT_QUERY_TIMEOUT; Ops.Qto = DEFAULT_QUERY_TIMEOUT;
Quoted = 0; Quoted = 0;
Rows = 0; Rows = 0;
Catver = 0; Catver = 0;
Memory = 0; Memory = 0;
Scrollable = false; Scrollable = false;
Ops.UseCnc = false;
} // endif tdp } // endif tdp
Quote = NULL; Quote = NULL;
...@@ -242,6 +252,7 @@ TDBODBC::TDBODBC(PTDBODBC tdbp) : TDBASE(tdbp) ...@@ -242,6 +252,7 @@ TDBODBC::TDBODBC(PTDBODBC tdbp) : TDBASE(tdbp)
Connect = tdbp->Connect; Connect = tdbp->Connect;
TableName = tdbp->TableName; TableName = tdbp->TableName;
Schema = tdbp->Schema; Schema = tdbp->Schema;
Ops = tdbp->Ops;
Catalog = tdbp->Catalog; Catalog = tdbp->Catalog;
Srcdef = tdbp->Srcdef; Srcdef = tdbp->Srcdef;
Qrystr = tdbp->Qrystr; Qrystr = tdbp->Qrystr;
...@@ -254,8 +265,6 @@ TDBODBC::TDBODBC(PTDBODBC tdbp) : TDBASE(tdbp) ...@@ -254,8 +265,6 @@ TDBODBC::TDBODBC(PTDBODBC tdbp) : TDBASE(tdbp)
MulConn = tdbp->MulConn; MulConn = tdbp->MulConn;
DBQ = tdbp->DBQ; DBQ = tdbp->DBQ;
Options = tdbp->Options; Options = tdbp->Options;
Cto = tdbp->Cto;
Qto = tdbp->Qto;
Quoted = tdbp->Quoted; Quoted = tdbp->Quoted;
Rows = tdbp->Rows; Rows = tdbp->Rows;
Fpos = tdbp->Fpos; Fpos = tdbp->Fpos;
...@@ -698,10 +707,7 @@ int TDBODBC::Cardinality(PGLOBAL g) ...@@ -698,10 +707,7 @@ int TDBODBC::Cardinality(PGLOBAL g)
char qry[96], tbn[64]; char qry[96], tbn[64];
ODBConn *ocp = new(g) ODBConn(g, this); ODBConn *ocp = new(g) ODBConn(g, this);
ocp->SetLoginTimeout((DWORD)Cto); if (ocp->Open(Connect, &Ops, Options) < 1)
ocp->SetQueryTimeout((DWORD)Qto);
if (ocp->Open(Connect, Options) < 1)
return -1; return -1;
// Table name can be encoded in UTF-8 // Table name can be encoded in UTF-8
...@@ -802,14 +808,12 @@ bool TDBODBC::OpenDB(PGLOBAL g) ...@@ -802,14 +808,12 @@ bool TDBODBC::OpenDB(PGLOBAL g)
/* and if so to allocate just a new result set. But this only for */ /* and if so to allocate just a new result set. But this only for */
/* drivers allowing concurency in getting results ??? */ /* drivers allowing concurency in getting results ??? */
/*********************************************************************/ /*********************************************************************/
if (!Ocp) { if (!Ocp)
Ocp = new(g) ODBConn(g, this); Ocp = new(g) ODBConn(g, this);
Ocp->SetLoginTimeout((DWORD)Cto); else if (Ocp->IsOpen())
Ocp->SetQueryTimeout((DWORD)Qto);
} else if (Ocp->IsOpen())
Ocp->Close(); Ocp->Close();
if (Ocp->Open(Connect, Options) < 1) if (Ocp->Open(Connect, &Ops, Options) < 1)
return true; return true;
else if (Quoted) else if (Quoted)
Quote = Ocp->GetQuoteChar(); Quote = Ocp->GetQuoteChar();
...@@ -1415,12 +1419,10 @@ bool TDBXDBC::OpenDB(PGLOBAL g) ...@@ -1415,12 +1419,10 @@ bool TDBXDBC::OpenDB(PGLOBAL g)
/*********************************************************************/ /*********************************************************************/
if (!Ocp) { if (!Ocp) {
Ocp = new(g) ODBConn(g, this); Ocp = new(g) ODBConn(g, this);
Ocp->SetLoginTimeout((DWORD)Cto);
Ocp->SetQueryTimeout((DWORD)Qto);
} else if (Ocp->IsOpen()) } else if (Ocp->IsOpen())
Ocp->Close(); Ocp->Close();
if (Ocp->Open(Connect, Options) < 1) if (Ocp->Open(Connect, &Ops, Options) < 1)
return true; return true;
Use = USE_OPEN; // Do it now in case we are recursively called Use = USE_OPEN; // Do it now in case we are recursively called
...@@ -1554,8 +1556,10 @@ TDBOTB::TDBOTB(PODEF tdp) : TDBDRV(tdp) ...@@ -1554,8 +1556,10 @@ TDBOTB::TDBOTB(PODEF tdp) : TDBDRV(tdp)
Dsn = tdp->GetConnect(); Dsn = tdp->GetConnect();
Schema = tdp->GetTabschema(); Schema = tdp->GetTabschema();
Tab = tdp->GetTabname(); Tab = tdp->GetTabname();
Cto = tdp->Cto; Ops.User = tdp->Username;
Qto = tdp->Qto; Ops.Pwd = tdp->Password;
Ops.Cto = tdp->Cto;
Ops.Qto = tdp->Qto;
} // end of TDBOTB constructor } // end of TDBOTB constructor
/***********************************************************************/ /***********************************************************************/
...@@ -1563,7 +1567,7 @@ TDBOTB::TDBOTB(PODEF tdp) : TDBDRV(tdp) ...@@ -1563,7 +1567,7 @@ TDBOTB::TDBOTB(PODEF tdp) : TDBDRV(tdp)
/***********************************************************************/ /***********************************************************************/
PQRYRES TDBOTB::GetResult(PGLOBAL g) PQRYRES TDBOTB::GetResult(PGLOBAL g)
{ {
return ODBCTables(g, Dsn, Schema, Tab, Maxres, Cto, Qto, false); return ODBCTables(g, Dsn, Schema, Tab, Maxres, false, &Ops);
} // end of GetResult } // end of GetResult
/* ---------------------------TDBOCL class --------------------------- */ /* ---------------------------TDBOCL class --------------------------- */
...@@ -1573,7 +1577,7 @@ PQRYRES TDBOTB::GetResult(PGLOBAL g) ...@@ -1573,7 +1577,7 @@ PQRYRES TDBOTB::GetResult(PGLOBAL g)
/***********************************************************************/ /***********************************************************************/
PQRYRES TDBOCL::GetResult(PGLOBAL g) PQRYRES TDBOCL::GetResult(PGLOBAL g)
{ {
return ODBCColumns(g, Dsn, Schema, Tab, NULL, Maxres, Cto, Qto, false); return ODBCColumns(g, Dsn, Schema, Tab, NULL, Maxres, false, &Ops);
} // end of GetResult } // end of GetResult
/* ------------------------ End of Tabodbc --------------------------- */ /* ------------------------ End of Tabodbc --------------------------- */
...@@ -50,6 +50,8 @@ class DllExport ODBCDEF : public TABDEF { /* Logical table description */ ...@@ -50,6 +50,8 @@ class DllExport ODBCDEF : public TABDEF { /* Logical table description */
PSZ Connect; /* ODBC connection string */ PSZ Connect; /* ODBC connection string */
PSZ Tabname; /* External table name */ PSZ Tabname; /* External table name */
PSZ Tabschema; /* External table schema */ PSZ Tabschema; /* External table schema */
PSZ Username; /* User connect name */
PSZ Password; /* Password connect info */
PSZ Tabcat; /* External table catalog */ PSZ Tabcat; /* External table catalog */
PSZ Srcdef; /* The source table SQL definition */ PSZ Srcdef; /* The source table SQL definition */
PSZ Qchar; /* Identifier quoting character */ PSZ Qchar; /* Identifier quoting character */
...@@ -65,6 +67,7 @@ class DllExport ODBCDEF : public TABDEF { /* Logical table description */ ...@@ -65,6 +67,7 @@ class DllExport ODBCDEF : public TABDEF { /* Logical table description */
bool Scrollable; /* Use scrollable cursor */ bool Scrollable; /* Use scrollable cursor */
bool Memory; /* Put result set in memory */ bool Memory; /* Put result set in memory */
bool Xsrc; /* Execution type */ bool Xsrc; /* Execution type */
bool UseCnc; /* Use SQLConnect (!SQLDriverConnect) */
}; // end of ODBCDEF }; // end of ODBCDEF
#if !defined(NODBC) #if !defined(NODBC)
...@@ -124,9 +127,12 @@ class TDBODBC : public TDBASE { ...@@ -124,9 +127,12 @@ class TDBODBC : public TDBASE {
// Members // Members
ODBConn *Ocp; // Points to an ODBC connection class ODBConn *Ocp; // Points to an ODBC connection class
ODBCCOL *Cnp; // Points to count(*) column ODBCCOL *Cnp; // Points to count(*) column
ODBCPARM Ops; // Additional parameters
char *Connect; // Points to connection string char *Connect; // Points to connection string
char *TableName; // Points to ODBC table name char *TableName; // Points to ODBC table name
char *Schema; // Points to ODBC table Schema char *Schema; // Points to ODBC table Schema
char *User; // User connect info
char *Pwd; // Password connect info
char *Catalog; // Points to ODBC table Catalog char *Catalog; // Points to ODBC table Catalog
char *Srcdef; // The source table SQL definition char *Srcdef; // The source table SQL definition
char *Query; // Points to SQL statement char *Query; // Points to SQL statement
...@@ -151,6 +157,7 @@ class TDBODBC : public TDBASE { ...@@ -151,6 +157,7 @@ class TDBODBC : public TDBASE {
int Nparm; // The number of statement parameters int Nparm; // The number of statement parameters
int Memory; // 0: No 1: Alloc 2: Put 3: Get int Memory; // 0: No 1: Alloc 2: Put 3: Get
bool Scrollable; // Use scrollable cursor bool Scrollable; // Use scrollable cursor
bool UseCnc; // Use SQLConnect (!SQLDriverConnect)
PQRYRES Qrp; // Points to storage result PQRYRES Qrp; // Points to storage result
}; // end of class TDBODBC }; // end of class TDBODBC
...@@ -316,8 +323,7 @@ class TDBOTB : public TDBDRV { ...@@ -316,8 +323,7 @@ class TDBOTB : public TDBDRV {
char *Dsn; // Points to connection string char *Dsn; // Points to connection string
char *Schema; // Points to schema name or NULL char *Schema; // Points to schema name or NULL
char *Tab; // Points to ODBC table name or pattern char *Tab; // Points to ODBC table name or pattern
int Cto; // Connect timeout ODBCPARM Ops; // Additional parameters
int Qto; // Query timeout
}; // end of class TDBOTB }; // end of class TDBOTB
/***********************************************************************/ /***********************************************************************/
......
...@@ -352,7 +352,9 @@ bool TDBTBL::TestFil(PGLOBAL g, PCFIL filp, PTABLE tabp) ...@@ -352,7 +352,9 @@ bool TDBTBL::TestFil(PGLOBAL g, PCFIL filp, PTABLE tabp)
/***********************************************************************/ /***********************************************************************/
int TDBTBL::Cardinality(PGLOBAL g) int TDBTBL::Cardinality(PGLOBAL g)
{ {
if (Cardinal < 0) { if (!g)
return 0; // Cannot make the table list
else if (Cardinal < 0) {
int tsz; int tsz;
if (!Tablist && InitTableList(g)) if (!Tablist && InitTableList(g))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment