From b2db891c1971a933104471b72877c90dd71aca53 Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Thu, 20 Nov 2014 23:18:51 +0100 Subject: [PATCH 1/4] - Remove gcc warning (variable n is set and not used) modified: storage/connect/odbconn.cpp --- storage/connect/odbconn.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/storage/connect/odbconn.cpp b/storage/connect/odbconn.cpp index 88b9978977a..b68b4648616 100644 --- a/storage/connect/odbconn.cpp +++ b/storage/connect/odbconn.cpp @@ -2373,8 +2373,6 @@ int ODBConn::GetCatInfo(CATPARM *cap) /***********************************************************************/ PQRYRES ODBConn::AllocateResult(PGLOBAL g) { -//char *fmt, v; - int n; bool uns; PODBCCOL colp; PCOLRES *pcrp, crp; @@ -2401,8 +2399,8 @@ PQRYRES ODBConn::AllocateResult(PGLOBAL g) qrp->Nblin = 0; qrp->Cursor = 0; - for (n = 1, colp = (PODBCCOL)m_Tdb->Columns; colp; - colp = (PODBCCOL)colp->GetNext()) + for (colp = (PODBCCOL)m_Tdb->Columns; colp; + colp = (PODBCCOL)colp->GetNext()) if (!colp->IsSpecial()) { *pcrp = (PCOLRES)PlugSubAlloc(g, NULL, sizeof(COLRES)); crp = *pcrp; From 6211708a95a64728350ad8d0d3cc374388d49307 Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Sun, 23 Nov 2014 16:12:26 +0100 Subject: [PATCH 2/4] - Fix a bug causing the day always printed as Sunday for date columns with a date format specifying DDD or DDDD. modified: storage/connect/ha_connect.cc storage/connect/value.cpp --- storage/connect/ha_connect.cc | 1 + storage/connect/value.cpp | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc index 1453c418025..957c28abd28 100644 --- a/storage/connect/ha_connect.cc +++ b/storage/connect/ha_connect.cc @@ -1326,6 +1326,7 @@ void *ha_connect::GetColumnOption(PGLOBAL g, void *field, PCOLINFO pcf) datm.tm_mday= 12; datm.tm_mon= 11; datm.tm_year= 112; + mktime(&datm); // to get proper day name len= strftime(buf, 256, pdtp->OutFmt, &datm); } else len= 0; diff --git a/storage/connect/value.cpp b/storage/connect/value.cpp index 81d00862703..11793a7b141 100644 --- a/storage/connect/value.cpp +++ b/storage/connect/value.cpp @@ -2484,8 +2484,10 @@ char *DTVAL::GetCharString(char *p) size_t n = 0; struct tm tm, *ptm= GetGmTime(&tm); - if (ptm) + if (ptm) { + mktime(ptm); // Populate tm_wday and tm_yday to get day name n = strftime(Sdate, Len + 1, Pdtp->OutFmt, ptm); + } // endif ptm if (!n) { *Sdate = '\0'; @@ -2511,6 +2513,8 @@ char *DTVAL::ShowValue(char *buf, int len) if (!Null) { size_t m, n = 0; struct tm tm, *ptm = GetGmTime(&tm); + + if (Len < len) { p = buf; @@ -2520,8 +2524,10 @@ char *DTVAL::ShowValue(char *buf, int len) m = Len + 1; } // endif Len - if (ptm) + if (ptm) { + mktime(ptm); // Populate tm_wday and tm_yday to get day name n = strftime(p, m, Pdtp->OutFmt, ptm); + } // endif ptm if (!n) { *p = '\0'; From c89b8a38de20c00bb6d9d822f7f027ce9fcf51d8 Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Mon, 24 Nov 2014 18:26:44 +0100 Subject: [PATCH 3/4] - Enhance the implementation of ODBC tables when using scrollable cursor modified: storage/connect/odbconn.cpp storage/connect/odbconn.h storage/connect/tabodbc.cpp --- storage/connect/odbconn.cpp | 22 ++++++++++++---------- storage/connect/odbconn.h | 2 +- storage/connect/tabodbc.cpp | 8 +++----- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/storage/connect/odbconn.cpp b/storage/connect/odbconn.cpp index b68b4648616..e614980a57a 100644 --- a/storage/connect/odbconn.cpp +++ b/storage/connect/odbconn.cpp @@ -2439,29 +2439,31 @@ PQRYRES ODBConn::AllocateResult(PGLOBAL g) /***********************************************************************/ /* Restart from beginning of result set */ /***********************************************************************/ -bool ODBConn::Rewind(char *sql, ODBCCOL *tocols) +int ODBConn::Rewind(char *sql, ODBCCOL *tocols) { - RETCODE rc; + int rc, rbuf = -1; if (!m_hstmt) - return false; + return rbuf; if (m_Scrollable) { + SQLULEN crow; + try { - rc = SQLFetchScroll(m_hstmt, SQL_FETCH_ABSOLUTE, 0); + rc = SQLExtendedFetch(m_hstmt, SQL_FETCH_FIRST, 1, &crow, NULL); - if (rc != SQL_NO_DATA_FOUND) - ThrowDBX(rc, "SQLFetchScroll", m_hstmt); + if (!Check(rc)) + ThrowDBX(rc, "SQLExtendedFetch", m_hstmt); + rbuf = (int)crow; } catch(DBX *x) { strcpy(m_G->Message, x->GetErrorMessage(0)); - return true; } // end try/catch - } else if (ExecDirectSQL(sql, tocols) < 0) - return true; + } else if (ExecDirectSQL(sql, tocols) >= 0) + rbuf = 0; - return false; + return rbuf; } // end of Rewind /***********************************************************************/ diff --git a/storage/connect/odbconn.h b/storage/connect/odbconn.h index 13d58488b39..ff8357c4591 100644 --- a/storage/connect/odbconn.h +++ b/storage/connect/odbconn.h @@ -124,7 +124,7 @@ class ODBConn : public BLOCK { forceOdbcDialog = 0x0010}; // Always display ODBC connect dialog int Open(PSZ ConnectString, DWORD Options = 0); - bool Rewind(char *sql, ODBCCOL *tocols); + int Rewind(char *sql, ODBCCOL *tocols); void Close(void); PQRYRES AllocateResult(PGLOBAL g); diff --git a/storage/connect/tabodbc.cpp b/storage/connect/tabodbc.cpp index cb21f33c1b1..6608083f1b4 100644 --- a/storage/connect/tabodbc.cpp +++ b/storage/connect/tabodbc.cpp @@ -130,10 +130,7 @@ bool ODBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) Quoted = GetIntCatInfo("Quoted", 0); Options = ODBConn::noOdbcDialog; //Options = ODBConn::noOdbcDialog | ODBConn::useCursorLib; - - if ((Scrollable = GetBoolCatInfo("Scrollable", false))) - Elemt = 0; // Not compatible with extended fetch - + Scrollable = GetBoolCatInfo("Scrollable", false); Memory = GetBoolCatInfo("Memory", false); Pseudo = 2; // FILID is Ok but not ROWID return false; @@ -775,13 +772,14 @@ bool TDBODBC::OpenDB(PGLOBAL g) if (Memory < 3) { // Method will depend on cursor type - if (Ocp->Rewind(Query, (PODBCCOL)Columns)) { + if ((Rbuf = Ocp->Rewind(Query, (PODBCCOL)Columns)) < 0) { Ocp->Close(); return true; } // endif Rewind } // endif Memory + CurNum = 0; Fpos = 0; return false; } // endif use From c3b0894f7d25a397aa7ec9af9c9afcbe129ae4fa Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Mon, 24 Nov 2014 18:32:44 +0100 Subject: [PATCH 4/4] - Make the fix for getting day names of dates more general modified: storage/connect/ha_connect.cc storage/connect/value.cpp --- storage/connect/ha_connect.cc | 2 +- storage/connect/value.cpp | 15 ++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc index 957c28abd28..ae8f7f0efa8 100644 --- a/storage/connect/ha_connect.cc +++ b/storage/connect/ha_connect.cc @@ -1326,7 +1326,7 @@ void *ha_connect::GetColumnOption(PGLOBAL g, void *field, PCOLINFO pcf) datm.tm_mday= 12; datm.tm_mon= 11; datm.tm_year= 112; - mktime(&datm); // to get proper day name + mktime(&datm); // set other fields get proper day name len= strftime(buf, 256, pdtp->OutFmt, &datm); } else len= 0; diff --git a/storage/connect/value.cpp b/storage/connect/value.cpp index 11793a7b141..0f2cf0ee936 100644 --- a/storage/connect/value.cpp +++ b/storage/connect/value.cpp @@ -2190,7 +2190,8 @@ static void TIME_to_localtime(struct tm *tm, const MYSQL_TIME *ltime) tm->tm_hour= ltime->hour; tm->tm_min= ltime->minute; tm->tm_sec= ltime->second; -} + mktime(tm); // set other tm fields to get proper day name (OB) +} // end of TIME_to_localtime // Added by Alexander Barkov static struct tm *gmtime_mysql(const time_t *timep, struct tm *tm) @@ -2199,7 +2200,7 @@ static struct tm *gmtime_mysql(const time_t *timep, struct tm *tm) thd_gmt_sec_to_TIME(current_thd, <ime, (my_time_t) *timep); TIME_to_localtime(tm, <ime); return tm; -} +} // end of gmtime_mysql /***********************************************************************/ /* GetGmTime: returns a pointer to a static tm structure obtained */ @@ -2484,10 +2485,8 @@ char *DTVAL::GetCharString(char *p) size_t n = 0; struct tm tm, *ptm= GetGmTime(&tm); - if (ptm) { - mktime(ptm); // Populate tm_wday and tm_yday to get day name + if (ptm) n = strftime(Sdate, Len + 1, Pdtp->OutFmt, ptm); - } // endif ptm if (!n) { *Sdate = '\0'; @@ -2524,10 +2523,8 @@ char *DTVAL::ShowValue(char *buf, int len) m = Len + 1; } // endif Len - if (ptm) { - mktime(ptm); // Populate tm_wday and tm_yday to get day name + if (ptm) n = strftime(p, m, Pdtp->OutFmt, ptm); - } // endif ptm if (!n) { *p = '\0'; @@ -2602,7 +2599,7 @@ bool DTVAL::WeekNum(PGLOBAL g, int& nval) /***********************************************************************/ bool DTVAL::FormatValue(PVAL vp, char *fmt) { - char *buf = (char*)vp->GetTo_Val(); // Should be big enough + char *buf = (char*)vp->GetTo_Val(); // Should be big enough struct tm tm, *ptm = GetGmTime(&tm); if (trace > 1)