[Libreoffice-commits] core.git: 6 commits - connectivity/source

Andrzej J.R. Hunt andrzej at ahunt.org
Fri Aug 30 03:37:15 PDT 2013


 connectivity/source/drivers/firebird/DatabaseMetaData.cxx  |    2 
 connectivity/source/drivers/firebird/PreparedStatement.cxx |   34 +++++----
 connectivity/source/drivers/firebird/ResultSet.cxx         |   49 +++++++++----
 connectivity/source/drivers/firebird/Util.cxx              |   14 +--
 4 files changed, 61 insertions(+), 38 deletions(-)

New commits:
commit fc7e7b683112e9ccd23104f38d4acc3417e9d5b8
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date:   Fri Aug 30 11:29:51 2013 +0100

    Improve TIMESTAMP display. (firebird-sdbc)
    
    Change-Id: Ief7ec180e3787a3354e2034693052ebf05a30e81

diff --git a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx
index c35e03d..ef817b7 100644
--- a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx
+++ b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx
@@ -966,7 +966,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo()
 
         // SQL_TIMESTAMP
         // TODO: precision?
-        aRow[1] = new ORowSetValueDecorator(OUString("timestamp"));
+        aRow[1] = new ORowSetValueDecorator(OUString("TIMESTAMP"));
         aRow[2] = new ORowSetValueDecorator(getColumnTypeFromFBType(SQL_TIMESTAMP));
         aRow[3] = new ORowSetValueDecorator(sal_Int32(8)); // Prevision = max length
         aRow[6] = new ORowSetValueDecorator(); // Create Params
commit 026fe9c53bc97729cd506376dd966c9e66d34a8c
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date:   Fri Aug 30 11:27:30 2013 +0100

    Implement setTimeStamp. (firebird-sdbc)
    
    Change-Id: I58907d42ec9e1b4098e2947fdb89b1ab264358a6

diff --git a/connectivity/source/drivers/firebird/ResultSet.cxx b/connectivity/source/drivers/firebird/ResultSet.cxx
index 7b106c3..aec90bf 100644
--- a/connectivity/source/drivers/firebird/ResultSet.cxx
+++ b/connectivity/source/drivers/firebird/ResultSet.cxx
@@ -363,7 +363,7 @@ T OResultSet::retrieveValue(sal_Int32 columnIndex)
 {
     // TODO: check we have the right type.
     if ((m_bWasNull = isNull(columnIndex)))
-        return 0;
+        return T();
 
     return *((T*) m_pSqlda->sqlvar[columnIndex-1].sqldata);
 }
@@ -401,6 +401,7 @@ OUString OResultSet::retrieveValue(sal_Int32 columnIndex)
 template <>
 ISC_QUAD* OResultSet::retrieveValue(sal_Int32 columnIndex)
 {
+    // TODO: this is probably wrong
     if ((m_bWasNull = isNull(columnIndex)))
         return 0;
     return (ISC_QUAD*) m_pSqlda->sqlvar[columnIndex-1].sqldata;
@@ -505,11 +506,18 @@ Time SAL_CALL OResultSet::getTime(sal_Int32 nIndex)
     return Time(0, aCTime.tm_sec, aCTime.tm_min, aCTime.tm_hour, false);
 }
 
-DateTime SAL_CALL OResultSet::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
+DateTime SAL_CALL OResultSet::getTimestamp(sal_Int32 nIndex)
+    throw(SQLException, RuntimeException)
 {
-    (void) columnIndex;
-    return DateTime(); // TODO: implement
-//     return safelyRetrieveValue(columnIndex);
+    ISC_TIMESTAMP aISCTimestamp = safelyRetrieveValue< ISC_TIMESTAMP >(nIndex);
+
+    struct tm aCTime;
+    isc_decode_timestamp(&aISCTimestamp, &aCTime);
+
+    // first field is nanoseconds -- not supported in firebird or struct tm.
+    // last field denotes UTC (true) or unknown (false)
+    return DateTime(0, aCTime.tm_sec, aCTime.tm_min, aCTime.tm_hour, aCTime.tm_mday,
+                    aCTime.tm_mon, aCTime.tm_year, false);
 }
 
 // -------------------------------------------------------------------------
commit 437dd0369a759e32ef8788b1829bc3b355952518
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date:   Fri Aug 30 11:14:59 2013 +0100

    Cast pointer before dereferencing. (firebird-sdbc)
    
    We have a char* pointing to arbitrary data hence we need to cast
    to the right type, othwerwise we retrieve the first byte only.
    
    Change-Id: I6d3d08d15105a506c140044008c5255a8a8e4c39

diff --git a/connectivity/source/drivers/firebird/ResultSet.cxx b/connectivity/source/drivers/firebird/ResultSet.cxx
index 21d4152..7b106c3 100644
--- a/connectivity/source/drivers/firebird/ResultSet.cxx
+++ b/connectivity/source/drivers/firebird/ResultSet.cxx
@@ -361,10 +361,11 @@ bool OResultSet::isNull(sal_Int32 columnIndex)
 template <typename T>
 T OResultSet::retrieveValue(sal_Int32 columnIndex)
 {
+    // TODO: check we have the right type.
     if ((m_bWasNull = isNull(columnIndex)))
         return 0;
 
-    return *m_pSqlda->sqlvar[columnIndex-1].sqldata;
+    return *((T*) m_pSqlda->sqlvar[columnIndex-1].sqldata);
 }
 
 template <>
commit 3f56234ecb4b8b07becfdcbbc3d7facbd95e6f60
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date:   Fri Aug 30 09:05:57 2013 +0100

    Implement set[Date|Time]. (firebird-sdbc)
    
    Change-Id: Ibf3bc34f316c0a299afc2e015ff4c49ad57099a5

diff --git a/connectivity/source/drivers/firebird/ResultSet.cxx b/connectivity/source/drivers/firebird/ResultSet.cxx
index a0a4f58..21d4152 100644
--- a/connectivity/source/drivers/firebird/ResultSet.cxx
+++ b/connectivity/source/drivers/firebird/ResultSet.cxx
@@ -27,6 +27,7 @@
 #include <propertyids.hxx>
 #include <rtl/string.hxx>
 #include <rtl/ustrbuf.hxx>
+#include <time.h>
 #include <TConnection.hxx>
 
 #include <com/sun/star/beans/PropertyAttribute.hpp>
@@ -479,26 +480,37 @@ OUString SAL_CALL OResultSet::getString(sal_Int32 columnIndex)
     return safelyRetrieveValue< OUString >(columnIndex);
 }
 
-Time SAL_CALL OResultSet::getTime( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
+Date SAL_CALL OResultSet::getDate(sal_Int32 nIndex)
+    throw(SQLException, RuntimeException)
 {
-    (void) columnIndex;
-    return Time();
-//     return safelyRetrieveValue(columnIndex);
+    ISC_DATE aISCDate = safelyRetrieveValue< ISC_DATE >(nIndex);
+
+    struct tm aCTime;
+    isc_decode_sql_date(&aISCDate, &aCTime);
+
+    return Date(aCTime.tm_mday, aCTime.tm_mon, aCTime.tm_year);
 }
 
-DateTime SAL_CALL OResultSet::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
+Time SAL_CALL OResultSet::getTime(sal_Int32 nIndex)
+    throw(SQLException, RuntimeException)
 {
-    (void) columnIndex;
-    return DateTime(); // TODO: implement
-//     return safelyRetrieveValue(columnIndex);
+    ISC_TIME aISCTime = safelyRetrieveValue< ISC_TIME >(nIndex);
+
+    struct tm aCTime;
+    isc_decode_sql_time(&aISCTime, &aCTime);
+
+    // first field is nanoseconds -- not supported in firebird or struct tm.
+    // last field denotes UTC (true) or unknown (false)
+    return Time(0, aCTime.tm_sec, aCTime.tm_min, aCTime.tm_hour, false);
 }
 
-Date SAL_CALL OResultSet::getDate( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
+DateTime SAL_CALL OResultSet::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
 {
     (void) columnIndex;
-    return Date(); // TODO: implement
+    return DateTime(); // TODO: implement
 //     return safelyRetrieveValue(columnIndex);
 }
+
 // -------------------------------------------------------------------------
 uno::Reference< XResultSetMetaData > SAL_CALL OResultSet::getMetaData(  ) throw(SQLException, RuntimeException)
 {
commit 73720f9a8330495b5dc130d761c577faa1a00ed1
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date:   Thu Aug 29 13:36:16 2013 +0100

    Implement malloc'ing of date/time/timestamp (firebird-sdbc)
    
    Change-Id: I22abb334a337ae2e25188ae43696789d37ecd7d4

diff --git a/connectivity/source/drivers/firebird/Util.cxx b/connectivity/source/drivers/firebird/Util.cxx
index 6941835..3c80952 100644
--- a/connectivity/source/drivers/firebird/Util.cxx
+++ b/connectivity/source/drivers/firebird/Util.cxx
@@ -216,7 +216,7 @@ void firebird::mallocSQLVAR(XSQLDA* pSqlda)
             pVar->sqldata = (char *)malloc(sizeof(double));
             break;
         case SQL_TIMESTAMP:
-            pVar->sqldata = (char *)malloc(sizeof(time_t));
+            pVar->sqldata = (char*) malloc(sizeof(ISC_TIMESTAMP));
             break;
         case SQL_BLOB:
             pVar->sqldata = (char*) malloc(sizeof(ISC_QUAD));
@@ -225,10 +225,10 @@ void firebird::mallocSQLVAR(XSQLDA* pSqlda)
             assert(false); // TODO: implement
             break;
         case SQL_TYPE_TIME:
-            assert(false); // TODO: implement
+            pVar->sqldata = (char*) malloc(sizeof(ISC_TIME));
             break;
         case SQL_TYPE_DATE:
-            assert(false); // TODO: implement
+            pVar->sqldata = (char*) malloc(sizeof(ISC_DATE));
             break;
         case SQL_INT64:
             pVar->sqldata = (char *)malloc(sizeof(int));
@@ -269,17 +269,13 @@ void firebird::freeSQLVAR(XSQLDA* pSqlda)
         case SQL_TIMESTAMP:
         case SQL_BLOB:
         case SQL_INT64:
+        case SQL_TYPE_TIME:
+        case SQL_TYPE_DATE:
             free(pVar->sqldata);
             break;
         case SQL_ARRAY:
             assert(false); // TODO: implement
             break;
-        case SQL_TYPE_TIME:
-            assert(false); // TODO: implement
-            break;
-        case SQL_TYPE_DATE:
-            assert(false); // TODO: implement
-            break;
         case SQL_NULL:
             assert(false); // TODO: implement
             break;
commit 84fe40e3699adea7b7ef6476d324d63aada9c5ad
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date:   Thu Aug 29 10:49:01 2013 +0100

    Implement set[Date|Time]. (firebird-sdbc)
    
    Change-Id: Ia519b2ec9c6be94f6f21bbd2951a295da8079479

diff --git a/connectivity/source/drivers/firebird/PreparedStatement.cxx b/connectivity/source/drivers/firebird/PreparedStatement.cxx
index c38e8d3..0069d71 100644
--- a/connectivity/source/drivers/firebird/PreparedStatement.cxx
+++ b/connectivity/source/drivers/firebird/PreparedStatement.cxx
@@ -390,26 +390,32 @@ void SAL_CALL OPreparedStatement::setDouble(sal_Int32 nIndex, double nValue)
     setValue< double >(nIndex, nValue, SQL_DOUBLE); // TODO: SQL_D_FLOAT?
 }
 
-// -------------------------------------------------------------------------
-
-void SAL_CALL OPreparedStatement::setDate( sal_Int32 parameterIndex, const Date& aData ) throw(SQLException, RuntimeException)
+void SAL_CALL OPreparedStatement::setDate(sal_Int32 nIndex, const Date& rDate)
+    throw(SQLException, RuntimeException)
 {
-    (void) parameterIndex;
-    (void) aData;
-    ::osl::MutexGuard aGuard( m_pConnection->getMutex() );
-    checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
+    struct tm aCTime;
+    aCTime.tm_mday = rDate.Day;
+    aCTime.tm_mon = rDate.Month;
+    aCTime.tm_year = rDate.Year;
 
-}
-// -------------------------------------------------------------------------
+    ISC_DATE aISCDate;
+    isc_encode_sql_date(&aCTime, &aISCDate);
 
+    setValue< ISC_DATE >(nIndex, aISCDate, SQL_TYPE_DATE);
+}
 
-void SAL_CALL OPreparedStatement::setTime( sal_Int32 parameterIndex, const Time& aVal ) throw(SQLException, RuntimeException)
+void SAL_CALL OPreparedStatement::setTime( sal_Int32 nIndex, const Time& rTime)
+    throw(SQLException, RuntimeException)
 {
-    (void) parameterIndex;
-    (void) aVal;
-    ::osl::MutexGuard aGuard( m_pConnection->getMutex() );
-    checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
+    struct tm aCTime;
+    aCTime.tm_sec = rTime.Seconds;
+    aCTime.tm_min = rTime.Minutes;
+    aCTime.tm_hour = rTime.Hours;
+
+    ISC_TIME aISCTime;
+    isc_encode_sql_time(&aCTime, &aISCTime);
 
+    setValue< ISC_TIME >(nIndex, aISCTime, SQL_TYPE_TIME);
 }
 
 void SAL_CALL OPreparedStatement::setTimestamp(sal_Int32 nIndex, const DateTime& rTimestamp)


More information about the Libreoffice-commits mailing list