summaryrefslogtreecommitdiff
path: root/storage/connect/odbconn.cpp
diff options
context:
space:
mode:
authorOlivier Bertrand <bertrandop@gmail.com>2014-11-15 18:28:24 +0100
committerOlivier Bertrand <bertrandop@gmail.com>2014-11-15 18:28:24 +0100
commit5d8311960a8f993591075b3da6106559922183b4 (patch)
tree1efe45e1188606c895a4069c05a2501826e1f293 /storage/connect/odbconn.cpp
parent9ade2d088d12f6a2a6f901148ed72a45dd15e9ff (diff)
downloadmariadb-git-5d8311960a8f993591075b3da6106559922183b4.tar.gz
- Implement the NEWMSG and XMSG methods
They are still experimental and should not be used in production. added: storage/connect/encas.h storage/connect/english.msg storage/connect/enids.h storage/connect/frcas.h storage/connect/french.msg storage/connect/frids.h storage/connect/frmsg.h modified: storage/connect/connect.cc storage/connect/engmsg.h storage/connect/filamdbf.cpp storage/connect/global.h storage/connect/ha_connect.cc storage/connect/msgid.h storage/connect/plgdbutl.cpp storage/connect/plugutil.c storage/connect/rcmsg.c storage/connect/resource.h storage/connect/tabfmt.h - Fix global variable not being properly initialized (MDEV-6690, MDEV-7094) modified: storage/connect/ha_connect.cc storage/connect/plugutil.c storage/connect/user_connect.cc storage/connect/xindex.cpp - Implement Rewind for ODBC tables (MDEV-7097) modified: storage/connect/odbconn.cpp storage/connect/odbconn.h storage/connect/tabmysql.cpp storage/connect/tabodbc.cpp - Reset N when reopening MYSQL tables modified: storage/connect/tabmysql.cpp
Diffstat (limited to 'storage/connect/odbconn.cpp')
-rw-r--r--storage/connect/odbconn.cpp84
1 files changed, 61 insertions, 23 deletions
diff --git a/storage/connect/odbconn.cpp b/storage/connect/odbconn.cpp
index 4f4bde36b94..bef735b4a6d 100644
--- a/storage/connect/odbconn.cpp
+++ b/storage/connect/odbconn.cpp
@@ -1,7 +1,7 @@
/************ Odbconn C++ Functions Source Code File (.CPP) ************/
-/* Name: ODBCONN.CPP Version 1.9 */
+/* Name: ODBCONN.CPP Version 2.0 */
/* */
-/* (C) Copyright to the author Olivier BERTRAND 1998-2013 */
+/* (C) Copyright to the author Olivier BERTRAND 1998-2014 */
/* */
/* This file contains the ODBC connection classes functions. */
/***********************************************************************/
@@ -830,7 +830,7 @@ DBX::DBX(RETCODE rc, PSZ msg)
/***********************************************************************/
/* This function is called by ThrowDBX. */
/***********************************************************************/
-void DBX::BuildErrorMessage(ODBConn* pdb, HSTMT hstmt)
+bool DBX::BuildErrorMessage(ODBConn* pdb, HSTMT hstmt)
{
if (pdb) {
SWORD len;
@@ -843,7 +843,9 @@ void DBX::BuildErrorMessage(ODBConn* pdb, HSTMT hstmt)
rc = SQLError(pdb->m_henv, pdb->m_hdbc, hstmt, state,
&native, msg, SQL_MAX_MESSAGE_LENGTH - 1, &len);
- if (rc != SQL_INVALID_HANDLE) {
+ if (rc == SQL_NO_DATA_FOUND)
+ return false;
+ else if (rc != SQL_INVALID_HANDLE) {
// Skip non-errors
for (int i = 0; i < MAX_NUM_OF_MSG
&& (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO)
@@ -859,7 +861,7 @@ void DBX::BuildErrorMessage(ODBConn* pdb, HSTMT hstmt)
} // endfor i
- return;
+ return true;
} else {
snprintf((char*)msg, SQL_MAX_MESSAGE_LENGTH + 1, "%s: %s", m_Msg,
MSG(BAD_HANDLE_VAL));
@@ -869,7 +871,7 @@ void DBX::BuildErrorMessage(ODBConn* pdb, HSTMT hstmt)
if (trace)
htrc("%s: rc=%hd\n", SVP(m_ErrMsg[0]), m_RC);
- return;
+ return true;
} // endif rc
} else
@@ -878,6 +880,7 @@ void DBX::BuildErrorMessage(ODBConn* pdb, HSTMT hstmt)
if (trace)
htrc("%s: rc=%hd (%s)\n", SVP(m_Msg), m_RC, SVP(m_ErrMsg[0]));
+ return true;
} // end of BuildErrorMessage
const char *DBX::GetErrorMessage(int i)
@@ -910,6 +913,7 @@ ODBConn::ODBConn(PGLOBAL g, TDBODBC *tdbp)
m_Connect = NULL;
m_Updatable = true;
m_Transact = false;
+ m_Scrollable = (tdbp) ? tdbp->Scrollable : false;
m_IDQuoteChar[0] = '"';
m_IDQuoteChar[1] = 0;
//*m_ErrMsg = '\0';
@@ -932,9 +936,10 @@ bool ODBConn::Check(RETCODE rc)
if (trace) {
DBX x(rc);
- x.BuildErrorMessage(this, m_hstmt);
- htrc("ODBC Success With Info, hstmt=%p %s\n",
- m_hstmt, x.GetErrorMessage(0));
+ if (x.BuildErrorMessage(this, m_hstmt))
+ htrc("ODBC Success With Info, hstmt=%p %s\n",
+ m_hstmt, x.GetErrorMessage(0));
+
} // endif trace
// Fall through
@@ -953,8 +958,10 @@ void ODBConn::ThrowDBX(RETCODE rc, PSZ msg, HSTMT hstmt)
{
DBX* xp = new(m_G) DBX(rc, msg);
- xp->BuildErrorMessage(this, hstmt);
- throw xp;
+ // Don't throw if no error
+ if (xp->BuildErrorMessage(this, hstmt))
+ throw xp;
+
} // end of ThrowDBX
void ODBConn::ThrowDBX(PSZ msg)
@@ -1298,25 +1305,28 @@ int ODBConn::ExecDirectSQL(char *sql, ODBCCOL *tocols)
b = false;
if (m_hstmt) {
-// All this did not seems to make sense and was been commented out
-// if (IsOpen())
-// Close(SQL_CLOSE);
-
+ // This is a Requery
rc = SQLFreeStmt(m_hstmt, SQL_CLOSE);
- if (trace && !Check(rc))
- htrc("Error: SQLFreeStmt rc=%d\n", rc);
+ if (!Check(rc))
+ ThrowDBX(rc, "SQLFreeStmt");
- hstmt = m_hstmt;
m_hstmt = NULL;
- ThrowDBX(MSG(SEQUENCE_ERROR));
- } else {
- rc = SQLAllocStmt(m_hdbc, &hstmt);
+ } // endif m_hstmt
+
+ rc = SQLAllocStmt(m_hdbc, &hstmt);
+
+ if (!Check(rc))
+ ThrowDBX(rc, "SQLAllocStmt");
+
+ if (m_Scrollable) {
+ rc = SQLSetStmtAttr(hstmt, SQL_ATTR_CURSOR_SCROLLABLE,
+ (void*)SQL_SCROLLABLE, 0);
if (!Check(rc))
- ThrowDBX(SQL_INVALID_HANDLE, "SQLAllocStmt");
+ ThrowDBX(rc, "SQLSetStmtAttr");
- } // endif hstmt
+ } // endif m_Scrollable
OnSetOptions(hstmt);
b = true;
@@ -2333,6 +2343,34 @@ int ODBConn::GetCatInfo(CATPARM *cap)
} // end of GetCatInfo
/***********************************************************************/
+/* Restart from beginning of result set */
+/***********************************************************************/
+bool ODBConn::Rewind(char *sql, ODBCCOL *tocols)
+ {
+ RETCODE rc;
+
+ if (!m_hstmt)
+ return false;
+
+ if (m_Scrollable) {
+ try {
+ rc = SQLFetchScroll(m_hstmt, SQL_FETCH_ABSOLUTE, 0);
+
+ if (rc != SQL_NO_DATA_FOUND)
+ ThrowDBX(rc, "SQLFetchScroll", m_hstmt);
+
+ } catch(DBX *x) {
+ strcpy(m_G->Message, x->GetErrorMessage(0));
+ return true;
+ } // end try/catch
+
+ } else if (ExecDirectSQL(sql, tocols) < 0)
+ return true;
+
+ return false;
+ } // end of Rewind
+
+/***********************************************************************/
/* Disconnect connection */
/***********************************************************************/
void ODBConn::Close()