summaryrefslogtreecommitdiff
path: root/storage/connect/tabodbc.cpp
diff options
context:
space:
mode:
authorOlivier Bertrand <bertrandop@gmail.com>2014-11-20 11:00:02 +0100
committerOlivier Bertrand <bertrandop@gmail.com>2014-11-20 11:00:02 +0100
commitc144cf38bd235904f3b4ada2f16327dee7b01d7a (patch)
tree683ad574ab255d8e3b4aaa95047bf53f64efbda3 /storage/connect/tabodbc.cpp
parentcfa872f6c80e18d440f01ed0cc8f21a94eebd0d9 (diff)
downloadmariadb-git-c144cf38bd235904f3b4ada2f16327dee7b01d7a.tar.gz
- Implement putting in memory the result set from an ODBC query.
modified: storage/connect/odbconn.cpp storage/connect/odbconn.h storage/connect/tabodbc.cpp storage/connect/tabodbc.h - Moving the calls to VerifyConnect and GetConnectInfo into the try block in ODBConn::Open (potential crash in case of throw) modified: storage/connect/odbconn.cpp - Handling all ODBC data date types (91, 92, 93) modified: storage/connect/ha_connect.cc storage/connect/odbconn.cpp - Not assuming string results from ODBC catalog functions are zero terminated modified: storage/connect/odbconn.cpp
Diffstat (limited to 'storage/connect/tabodbc.cpp')
-rw-r--r--storage/connect/tabodbc.cpp90
1 files changed, 71 insertions, 19 deletions
diff --git a/storage/connect/tabodbc.cpp b/storage/connect/tabodbc.cpp
index bbc17129aaf..cb21f33c1b1 100644
--- a/storage/connect/tabodbc.cpp
+++ b/storage/connect/tabodbc.cpp
@@ -134,6 +134,7 @@ bool ODBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
if ((Scrollable = GetBoolCatInfo("Scrollable", false)))
Elemt = 0; // Not compatible with extended fetch
+ Memory = GetBoolCatInfo("Memory", false);
Pseudo = 2; // FILID is Ok but not ROWID
return false;
} // end of DefineAM
@@ -198,6 +199,7 @@ TDBODBC::TDBODBC(PODEF tdp) : TDBASE(tdp)
Quoted = MY_MAX(0, tdp->GetQuoted());
Rows = tdp->GetElemt();
Catver = tdp->Catver;
+ Memory = (tdp->Memory) ? 1 : 0;
Scrollable = tdp->Scrollable;
} else {
Connect = NULL;
@@ -211,6 +213,7 @@ TDBODBC::TDBODBC(PODEF tdp) : TDBASE(tdp)
Quoted = 0;
Rows = 0;
Catver = 0;
+ Memory = 0;
Scrollable = false;
} // endif tdp
@@ -220,6 +223,7 @@ TDBODBC::TDBODBC(PODEF tdp) : TDBASE(tdp)
//Where = NULL;
MulConn = NULL;
DBQ = NULL;
+ Qrp = NULL;
Fpos = 0;
AftRows = 0;
CurNum = 0;
@@ -238,6 +242,7 @@ TDBODBC::TDBODBC(PTDBODBC tdbp) : TDBASE(tdbp)
Catalog = tdbp->Catalog;
Srcdef = tdbp->Srcdef;
Qrystr = tdbp->Qrystr;
+ Memory = tdbp->Memory;
Scrollable = tdbp->Scrollable;
Quote = tdbp->Quote;
Query = tdbp->Query;
@@ -256,6 +261,7 @@ TDBODBC::TDBODBC(PTDBODBC tdbp) : TDBASE(tdbp)
Rbuf = tdbp->Rbuf;
BufSize = tdbp->BufSize;
Nparm = tdbp->Nparm;
+ Qrp = tdbp->Qrp;
} // end of TDBODBC copy constructor
// Method
@@ -758,17 +764,23 @@ bool TDBODBC::OpenDB(PGLOBAL g)
/*******************************************************************/
/* Table already open, just replace it at its beginning. */
/*******************************************************************/
-// if (To_Kindex)
- /*****************************************************************/
- /* Table is to be accessed through a sorted index table. */
- /*****************************************************************/
-// To_Kindex->Reset();
-
-// rewind(Stream); >>>>>>> Something to be done with Cursor <<<<<<<
- if (Ocp->Rewind(Query, (PODBCCOL)Columns)) {
- Ocp->Close();
- return true;
- } // endif Rewind
+ if (Memory == 1) {
+ if ((Qrp = Ocp->AllocateResult(g)))
+ Memory = 2; // Must be filled
+ else
+ Memory = 0; // Allocation failed, don't use it
+
+ } else if (Memory == 2)
+ Memory = 3; // Ok to use memory result
+
+ if (Memory < 3) {
+ // Method will depend on cursor type
+ if (Ocp->Rewind(Query, (PODBCCOL)Columns)) {
+ Ocp->Close();
+ return true;
+ } // endif Rewind
+
+ } // endif Memory
Fpos = 0;
return false;
@@ -877,13 +889,22 @@ int TDBODBC::ReadDB(PGLOBAL g)
/* Now start the reading process. */
/* Here is the place to fetch the line(s). */
/*********************************************************************/
- if (++CurNum >= Rbuf) {
- Rbuf = Ocp->Fetch();
- CurNum = 0;
- } // endif CurNum
+ if (Memory != 3) {
+ if (++CurNum >= Rbuf) {
+ Rbuf = Ocp->Fetch();
+ CurNum = 0;
+ } // endif CurNum
+
+ rc = (Rbuf > 0) ? RC_OK : (Rbuf == 0) ? RC_EF : RC_FX;
+ } else // Getting result from memory
+ rc = (Fpos < Qrp->Nblin) ? RC_OK : RC_EF;
- rc = (Rbuf > 0) ? RC_OK : (Rbuf == 0) ? RC_EF : RC_FX;
- Fpos++; // Used for progress info
+ if (rc == RC_OK) {
+ if (Memory == 2)
+ Qrp->Nblin++;
+
+ Fpos++; // Used for memory
+ } // endif rc
if (trace > 1)
htrc(" Read: Rbuf=%d rc=%d\n", Rbuf, rc);
@@ -966,6 +987,7 @@ ODBCCOL::ODBCCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PSZ am)
} // endif cprec
// Set additional ODBC access method information for column.
+ Crp = NULL;
//Long = cdp->GetLong();
Long = Precision;
//strcpy(F_Date, cdp->F_Date);
@@ -987,6 +1009,7 @@ ODBCCOL::ODBCCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PSZ am)
/***********************************************************************/
ODBCCOL::ODBCCOL(void) : COLBLK()
{
+ Crp = NULL;
Buf_Type = TYPE_INT; // This is a count(*) column
// Set additional Dos access method information for column.
Long = sizeof(int);
@@ -1005,6 +1028,7 @@ ODBCCOL::ODBCCOL(void) : COLBLK()
/***********************************************************************/
ODBCCOL::ODBCCOL(ODBCCOL *col1, PTDB tdbp) : COLBLK(col1, tdbp)
{
+ Crp = col1->Crp;
Long = col1->Long;
//strcpy(F_Date, col1->F_Date);
To_Val = col1->To_Val;
@@ -1070,7 +1094,20 @@ bool ODBCCOL::SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check)
void ODBCCOL::ReadColumn(PGLOBAL g)
{
PTDBODBC tdbp = (PTDBODBC)To_Tdb;
- int n = tdbp->CurNum;
+ int i = tdbp->Fpos - 1, n = tdbp->CurNum;
+
+ if (tdbp->Memory == 3) {
+ // Get the value from the stored memory
+ if (Crp->Nulls && Crp->Nulls[i] == '*') {
+ Value->Reset();
+ Value->SetNull(true);
+ } else {
+ Value->SetValue_pvblk(Crp->Kdata, i);
+ Value->SetNull(false);
+ } // endif Nulls
+
+ return;
+ } // endif Memory
if (StrLen[n] == SQL_NULL_DATA) {
// Null value
@@ -1078,7 +1115,7 @@ void ODBCCOL::ReadColumn(PGLOBAL g)
Value->SetNull(true);
Value->Reset();
- return;
+ goto put;
} else
Value->SetNull(false);
@@ -1117,6 +1154,21 @@ void ODBCCOL::ReadColumn(PGLOBAL g)
Name, tdbp->Rows, Bufp, Buf_Type, Value->GetCharString(buf));
} // endif Trace
+put:
+ if (tdbp->Memory != 2)
+ return;
+
+ /*********************************************************************/
+ /* Fill the allocated result structure. */
+ /*********************************************************************/
+ if (Value->IsNull()) {
+ if (Crp->Nulls)
+ Crp->Nulls[i] = '*'; // Null value
+
+ Crp->Kdata->Reset(i);
+ } else
+ Crp->Kdata->SetValue(Value, i);
+
} // end of ReadColumn
/***********************************************************************/