Skip to content

Commit

Permalink
- Implement random access to ODBC tables
Browse files Browse the repository at this point in the history
modified:
  storage/connect/odbconn.cpp
  storage/connect/odbconn.h

- Fix get proper length of ODBC DECIMAL column in discovery
modified:
  storage/connect/ha_connect.cc
  storage/connect/mysql-test/connect/r/odbc_oracle.result

- Implement random access to JSON tables
modified:
  storage/connect/tabjson.cpp
  storage/connect/tabjson.h

- Fix MDEV-7636
modified:
  storage/connect/tabutil.cpp
  • Loading branch information
Buggynours committed Feb 28, 2015
1 parent aa107ef commit d862d7c
Show file tree
Hide file tree
Showing 9 changed files with 209 additions and 74 deletions.
2 changes: 2 additions & 0 deletions storage/connect/ha_connect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5462,7 +5462,9 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd,
case TYPE_DOUBLE:
// Some data sources do not count dec in length (prec)
prec += (dec + 2); // To be safe
break;
case TYPE_DECIM:
prec= len;
break;
default:
dec= 0;
Expand Down
10 changes: 5 additions & 5 deletions storage/connect/mysql-test/connect/r/odbc_oracle.result
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ TABNAME='T1';
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`A` decimal(38,0) DEFAULT NULL,
`A` decimal(40,0) DEFAULT NULL,
`B` double(40,0) DEFAULT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='DSN=ConnectEngineOracle;UID=mtr;PWD=mtr' `TABLE_TYPE`='ODBC' `TABNAME`='T1'
SELECT * FROM t1 ORDER BY A;
Expand All @@ -138,7 +138,7 @@ CREATE TABLE t2 AS SELECT * FROM t1;
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
`A` decimal(38,0) DEFAULT NULL,
`A` decimal(40,0) DEFAULT NULL,
`B` double(40,0) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
SELECT * FROM t2;
Expand All @@ -162,7 +162,7 @@ TABNAME='MTR.T1';
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`A` decimal(38,0) DEFAULT NULL,
`A` decimal(40,0) DEFAULT NULL,
`B` double(40,0) DEFAULT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='DSN=ConnectEngineOracle;UID=mtr;PWD=mtr' `TABLE_TYPE`='ODBC' `TABNAME`='MTR.T1'
SELECT * FROM t1;
Expand All @@ -178,7 +178,7 @@ TABNAME='MTR.V1';
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`A` decimal(38,0) DEFAULT NULL,
`A` decimal(40,0) DEFAULT NULL,
`B` double(40,0) DEFAULT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='DSN=ConnectEngineOracle;UID=mtr;PWD=mtr' `TABLE_TYPE`='ODBC' `TABNAME`='MTR.V1'
SELECT * FROM t1;
Expand All @@ -190,7 +190,7 @@ CREATE TABLE t2 AS SELECT * FROM t1;
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
`A` decimal(38,0) DEFAULT NULL,
`A` decimal(40,0) DEFAULT NULL,
`B` double(40,0) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
SELECT * FROM t2;
Expand Down
73 changes: 36 additions & 37 deletions storage/connect/odbconn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ static int GetSQLCType(int type)
case TYPE_BIGINT: tp = SQL_C_SBIGINT; break;
case TYPE_DOUBLE: tp = SQL_C_DOUBLE; break;
case TYPE_TINY : tp = SQL_C_TINYINT; break;
//#if (ODBCVER >= 0x0300)
// case TYPE_DECIM: tp = SQL_C_NUMERIC; break; (CRASH!!!)
//#else
case TYPE_DECIM: tp = SQL_C_CHAR; break;
//#endif

} // endswitch type

return tp;
Expand Down Expand Up @@ -923,13 +928,13 @@ ODBConn::ODBConn(PGLOBAL g, TDBODBC *tdbp)
m_RowsetSize = (DWORD)((tdbp) ? tdbp->Rows : 10);
m_Catver = (tdbp) ? tdbp->Catver : 0;
m_Rows = 0;
m_Fetch = 0;
m_Connect = NULL;
m_User = NULL;
m_Pwd = NULL;
m_Updatable = true;
m_Transact = false;
m_Scrollable = (tdbp) ? tdbp->Scrollable : false;
m_First = true;
m_Full = false;
m_UseCnc = false;
m_IDQuoteChar[0] = '"';
Expand Down Expand Up @@ -984,7 +989,7 @@ void ODBConn::ThrowDBX(RETCODE rc, PSZ msg, HSTMT hstmt)

void ODBConn::ThrowDBX(PSZ msg)
{
DBX* xp = new(m_G) DBX(0, msg);
DBX* xp = new(m_G) DBX(0, "Error");

xp->m_ErrMsg[0] = msg;
throw xp;
Expand Down Expand Up @@ -1099,8 +1104,7 @@ int ODBConn::Open(PSZ ConnectString, POPARM sop, DWORD options)
// VerifyConnect(); Deprecated
GetConnectInfo();
} catch(DBX *xp) {
// strcpy(g->Message, xp->m_ErrMsg[0]);
strcpy(g->Message, xp->GetErrorMessage(0));
sprintf(g->Message, "%s: %s", xp->m_Msg, xp->GetErrorMessage(0));
Close();
// Free();
return -1;
Expand Down Expand Up @@ -1356,7 +1360,7 @@ int ODBConn::ExecDirectSQL(char *sql, ODBCCOL *tocols)
rc = SQLFreeStmt(m_hstmt, SQL_CLOSE);

if (!Check(rc))
ThrowDBX(rc, "SQLFreeStmt");
ThrowDBX(rc, "SQLFreeStmt", m_hstmt);

m_hstmt = NULL;
} // endif m_hstmt
Expand All @@ -1371,7 +1375,7 @@ int ODBConn::ExecDirectSQL(char *sql, ODBCCOL *tocols)
(void*)SQL_SCROLLABLE, 0);

if (!Check(rc))
ThrowDBX(rc, "SQLSetStmtAttr");
ThrowDBX(rc, "Scrollable", hstmt);

} // endif m_Scrollable

Expand Down Expand Up @@ -1422,7 +1426,7 @@ int ODBConn::ExecDirectSQL(char *sql, ODBCCOL *tocols)

for (n = 0, colp = tocols; colp; colp = (PODBCCOL)colp->GetNext())
if (!colp->IsSpecial())
n++;
n++;

// n can be 0 for query such as Select count(*) from table
if (n && n != (UWORD)ncol)
Expand Down Expand Up @@ -1458,7 +1462,7 @@ int ODBConn::ExecDirectSQL(char *sql, ODBCCOL *tocols)
for (int i = 0; i < MAX_NUM_OF_MSG && x->m_ErrMsg[i]; i++)
htrc(x->m_ErrMsg[i]);

strcpy(m_G->Message, x->GetErrorMessage(0));
sprintf(m_G->Message, "%s: %s", x->m_Msg, x->GetErrorMessage(0));

if (b)
SQLCancel(hstmt);
Expand Down Expand Up @@ -1521,7 +1525,7 @@ int ODBConn::GetResultSize(char *sql, ODBCCOL *colp)
/***********************************************************************/
/* Fetch next row. */
/***********************************************************************/
int ODBConn::Fetch()
int ODBConn::Fetch(int pos)
{
ASSERT(m_hstmt);
int irc;
Expand All @@ -1531,7 +1535,9 @@ int ODBConn::Fetch()

try {
// do {
if (m_RowsetSize) {
if (pos) {
rc = SQLExtendedFetch(m_hstmt, SQL_FETCH_ABSOLUTE, pos, &crow, NULL);
} else if (m_RowsetSize) {
rc = SQLExtendedFetch(m_hstmt, SQL_FETCH_NEXT, 1, &crow, NULL);
} else {
rc = SQLFetch(m_hstmt);
Expand All @@ -1544,29 +1550,22 @@ int ODBConn::Fetch()
m_hstmt, m_RowsetSize, rc);

if (!Check(rc))
ThrowDBX(rc, "Fetch", m_hstmt);

irc = (rc == SQL_NO_DATA_FOUND) ? 0 : (int)crow;

if (m_First) {
// First fetch. Check whether the full table was read
if ((m_Full = irc < (signed)m_RowsetSize)) {
m_Tdb->Memory = 0; // Not needed anymore
m_Rows = irc; // Table size
} // endif m_Full

m_First = false;
} // endif m_First
ThrowDBX(rc, "Fetching", m_hstmt);

if (m_Tdb->Memory == 1)
m_Rows += irc;
if (rc == SQL_NO_DATA_FOUND) {
m_Full = (m_Fetch == 1);
irc = 0;
} else
irc = (int)crow;

m_Fetch++;
m_Rows += irc;
} catch(DBX *x) {
if (trace)
for (int i = 0; i < MAX_NUM_OF_MSG && x->m_ErrMsg[i]; i++)
htrc(x->m_ErrMsg[i]);

strcpy(g->Message, x->GetErrorMessage(0));
sprintf(g->Message, "%s: %s", x->m_Msg, x->GetErrorMessage(0));
irc = -1;
} // end try/catch

Expand Down Expand Up @@ -1602,7 +1601,7 @@ int ODBConn::PrepareSQL(char *sql)
for (int i = 0; i < MAX_NUM_OF_MSG && x->m_ErrMsg[i]; i++)
htrc(x->m_ErrMsg[i]);

strcpy(g->Message, x->GetErrorMessage(0));
sprintf(g->Message, "%s: %s", x->m_Msg, x->GetErrorMessage(0));
} // end try/catch

} // endif Mode
Expand Down Expand Up @@ -1648,7 +1647,7 @@ int ODBConn::PrepareSQL(char *sql)
for (int i = 0; i < MAX_NUM_OF_MSG && x->m_ErrMsg[i]; i++)
htrc(x->m_ErrMsg[i]);

strcpy(g->Message, x->GetErrorMessage(0));
sprintf(g->Message, "%s: %s", x->m_Msg, x->GetErrorMessage(0));

if (b)
SQLCancel(hstmt);
Expand Down Expand Up @@ -1700,7 +1699,7 @@ int ODBConn::ExecuteSQL(void)
} // endif ncol

} catch(DBX *x) {
strcpy(m_G->Message, x->GetErrorMessage(0));
sprintf(m_G->Message, "%s: %s", x->m_Msg, x->GetErrorMessage(0));
SQLCancel(m_hstmt);
rc = SQLFreeStmt(m_hstmt, SQL_DROP);
m_hstmt = NULL;
Expand Down Expand Up @@ -1737,7 +1736,7 @@ bool ODBConn::BindParam(ODBCCOL *colp)
ThrowDBX(rc, "SQLDescribeParam", m_hstmt);

} catch(DBX *x) {
strcpy(m_G->Message, x->GetErrorMessage(0));
sprintf(m_G->Message, "%s: %s", x->m_Msg, x->GetErrorMessage(0));
colsize = colp->GetPrecision();
sqlt = GetSQLType(buftype);
dec = IsTypeChar(buftype) ? 0 : colp->GetScale();
Expand Down Expand Up @@ -1845,7 +1844,7 @@ bool ODBConn::ExecSQLcommand(char *sql)
for (int i = 0; i < MAX_NUM_OF_MSG && x->m_ErrMsg[i]; i++)
htrc(x->m_ErrMsg[i]);

sprintf(g->Message, "Remote: %s", x->GetErrorMessage(0));
sprintf(g->Message, "Remote %s: %s", x->m_Msg, x->GetErrorMessage(0));

if (b)
SQLCancel(hstmt);
Expand Down Expand Up @@ -1930,7 +1929,7 @@ PQRYRES ODBConn::GetMetaData(PGLOBAL g, char *dsn, char *src)
} // endfor i

} catch(DBX *x) {
strcpy(g->Message, x->GetErrorMessage(0));
sprintf(g->Message, "%s: %s", x->m_Msg, x->GetErrorMessage(0));
goto err;
} // end try/catch

Expand Down Expand Up @@ -1981,7 +1980,7 @@ PQRYRES ODBConn::GetMetaData(PGLOBAL g, char *dsn, char *src)
} // endfor i

} catch(DBX *x) {
strcpy(g->Message, x->GetErrorMessage(0));
sprintf(g->Message, "%s: %s", x->m_Msg, x->GetErrorMessage(0));
qrp = NULL;
} // end try/catch

Expand Down Expand Up @@ -2033,7 +2032,7 @@ bool ODBConn::GetDataSources(PQRYRES qrp)
} // endfor i

} catch(DBX *x) {
strcpy(m_G->Message, x->GetErrorMessage(0));
sprintf(m_G->Message, "%s: %s", x->m_Msg, x->GetErrorMessage(0));
rv = true;
} // end try/catch

Expand Down Expand Up @@ -2084,7 +2083,7 @@ bool ODBConn::GetDrivers(PQRYRES qrp)
} // endfor n

} catch(DBX *x) {
strcpy(m_G->Message, x->GetErrorMessage(0));
sprintf(m_G->Message, "%s: %s", x->m_Msg, x->GetErrorMessage(0));
rv = true;
} // end try/catch

Expand Down Expand Up @@ -2402,7 +2401,7 @@ int ODBConn::GetCatInfo(CATPARM *cap)
for (int i = 0; i < MAX_NUM_OF_MSG && x->m_ErrMsg[i]; i++)
htrc(x->m_ErrMsg[i]);

strcpy(g->Message, x->GetErrorMessage(0));
sprintf(g->Message, "%s: %s", x->m_Msg, x->GetErrorMessage(0));
irc = -1;
} // end try/catch

Expand Down Expand Up @@ -2506,7 +2505,7 @@ int ODBConn::Rewind(char *sql, ODBCCOL *tocols)

rbuf = (int)crow;
} catch(DBX *x) {
strcpy(m_G->Message, x->GetErrorMessage(0));
sprintf(m_G->Message, "%s: %s", x->m_Msg, x->GetErrorMessage(0));
rbuf = -1;
} // end try/catch

Expand Down
4 changes: 2 additions & 2 deletions storage/connect/odbconn.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class ODBConn : public BLOCK {
//void SetUserPwd(PSZ pwd) {m_Pwd = pwd;}
int GetResultSize(char *sql, ODBCCOL *colp);
int ExecDirectSQL(char *sql, ODBCCOL *tocols);
int Fetch(void);
int Fetch(int pos = 0);
int PrepareSQL(char *sql);
int ExecuteSQL(void);
bool BindParam(ODBCCOL *colp);
Expand Down Expand Up @@ -192,10 +192,10 @@ class ODBConn : public BLOCK {
PSZ m_Pwd;
int m_Catver;
int m_Rows;
int m_Fetch;
bool m_Updatable;
bool m_Transact;
bool m_Scrollable;
bool m_UseCnc;
bool m_First;
bool m_Full;
}; // end of ODBConn class definition
45 changes: 45 additions & 0 deletions storage/connect/tabjson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,51 @@ int TDBJSON::MakeIndex(PGLOBAL g, PIXDEF pxdf, bool add)

} // end of MakeIndex

/***********************************************************************/
/* Return the position in the table. */
/***********************************************************************/
int TDBJSON::GetRecpos(void)
{
#if 0
union {
uint Rpos;
BYTE Spos[4];
};

Rpos = htonl(Fpos);
Spos[0] = (BYTE)NextSame;
return Rpos;
#endif // 0
return Fpos;
} // end of GetRecpos

/***********************************************************************/
/* Set the position in the table. */
/***********************************************************************/
bool TDBJSON::SetRecpos(PGLOBAL g, int recpos)
{
#if 0
union {
uint Rpos;
BYTE Spos[4];
};

Rpos = recpos;
NextSame = Spos[0];
Spos[0] = 0;
Fpos = (signed)ntohl(Rpos);

//if (Fpos != (signed)ntohl(Rpos)) {
// Fpos = ntohl(Rpos);
// same = false;
//} else
// same = true;
#endif // 0

Fpos = recpos - 1;
return false;
} // end of SetRecpos

/***********************************************************************/
/* JSON Access Method opening routine. */
/***********************************************************************/
Expand Down
5 changes: 2 additions & 3 deletions storage/connect/tabjson.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,9 @@ class TDBJSON : public TDBJSN {
virtual int Cardinality(PGLOBAL g);
virtual int GetMaxSize(PGLOBAL g);
virtual void ResetSize(void);
virtual int GetRecpos(void) {return Fpos;}
virtual int GetProgCur(void) {return N;}
virtual bool SetRecpos(PGLOBAL g, int recpos)
{Fpos = recpos - 1; return false;}
virtual int GetRecpos(void);
virtual bool SetRecpos(PGLOBAL g, int recpos);
virtual bool OpenDB(PGLOBAL g);
virtual int ReadDB(PGLOBAL g);
virtual bool PrepareWriting(PGLOBAL g) {return false;}
Expand Down
Loading

0 comments on commit d862d7c

Please sign in to comment.