connectivity/Library_postgresql-sdbc-impl.mk | 1 connectivity/source/drivers/postgresql/pq_baseresultset.cxx | 10 connectivity/source/drivers/postgresql/pq_preparedstatement.cxx | 10 connectivity/source/drivers/postgresql/pq_tools.cxx | 105 ---------- connectivity/source/drivers/postgresql/pq_tools.hxx | 9 connectivity/source/drivers/postgresql/pq_updateableresultset.cxx | 10 6 files changed, 22 insertions(+), 123 deletions(-)
New commits: commit 2cc79aeaf0fb68ea5bed912ed229166c7af3e45d Author: Lionel Elie Mamane <lio...@mamane.lu> Date: Thu Jun 27 12:56:40 2013 +0200 Replace buggy pgsql-sdbc datetime functions with dbtools equivalents In particular, the string2time function segfaults when called on an empty string (unconditionally tries to access the n-th character without checking whether the string is that long) this happens in particular when reading a column of type TIME with a NULL value Change-Id: I302044f67a92fe20685ce677ba3affdb9b44cb53 Reviewed-on: https://gerrit.libreoffice.org/4582 Reviewed-by: Fridrich Strba <fridr...@documentfoundation.org> Tested-by: Fridrich Strba <fridr...@documentfoundation.org> diff --git a/connectivity/Library_postgresql-sdbc-impl.mk b/connectivity/Library_postgresql-sdbc-impl.mk index 6cc9f39..bdb96c5 100644 --- a/connectivity/Library_postgresql-sdbc-impl.mk +++ b/connectivity/Library_postgresql-sdbc-impl.mk @@ -20,6 +20,7 @@ $(eval $(call gb_Library_use_sdk_api,postgresql-sdbc-impl)) $(eval $(call gb_Library_use_libraries,postgresql-sdbc-impl,\ cppu \ cppuhelper \ + dbtools \ sal \ salhelper \ $(gb_UWINAPI) \ diff --git a/connectivity/source/drivers/postgresql/pq_baseresultset.cxx b/connectivity/source/drivers/postgresql/pq_baseresultset.cxx index 1abe9de..1747909 100644 --- a/connectivity/source/drivers/postgresql/pq_baseresultset.cxx +++ b/connectivity/source/drivers/postgresql/pq_baseresultset.cxx @@ -49,6 +49,8 @@ #include <com/sun/star/lang/DisposedException.hpp> +#include <connectivity/dbconversion.hxx> + using osl::Mutex; using osl::MutexGuard; @@ -83,6 +85,8 @@ using com::sun::star::sdbc::XResultSetMetaDataSupplier; using com::sun::star::beans::Property; +using namespace dbtools; + namespace pq_sdbc_driver { static ::cppu::IPropertyArrayHelper & getResultSetPropertyArrayHelper() @@ -540,19 +544,19 @@ Sequence< sal_Int8 > BaseResultSet::getBytes( sal_Int32 columnIndex ) ::com::sun::star::util::Date BaseResultSet::getDate( sal_Int32 columnIndex ) throw (SQLException, RuntimeException) { - return string2Date( getString( columnIndex ) ); + return DBTypeConversion::toDate( getString( columnIndex ) ); } ::com::sun::star::util::Time BaseResultSet::getTime( sal_Int32 columnIndex ) throw (SQLException, RuntimeException) { - return string2Time( getString( columnIndex ) ); + return DBTypeConversion::toTime( getString( columnIndex ) ); } ::com::sun::star::util::DateTime BaseResultSet::getTimestamp( sal_Int32 columnIndex ) throw (SQLException, RuntimeException) { - return string2DateTime( getString( columnIndex ) ); + return DBTypeConversion::toDateTime( getString( columnIndex ) ); } // LEM TODO: these look like they are missing an actual implementation diff --git a/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx b/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx index e6dec90..fb82b99 100644 --- a/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx +++ b/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx @@ -54,6 +54,8 @@ #include <string.h> +#include <connectivity/dbconversion.hxx> + using osl::Mutex; using osl::MutexGuard; @@ -89,6 +91,8 @@ using com::sun::star::beans::XPropertySet; using com::sun::star::beans::XMultiPropertySet; using com::sun::star::beans::XFastPropertySet; +using namespace dbtools; + namespace pq_sdbc_driver { static ::cppu::IPropertyArrayHelper & getPreparedStatementPropertyArrayHelper() @@ -597,20 +601,20 @@ void PreparedStatement::setBytes( void PreparedStatement::setDate( sal_Int32 parameterIndex, const ::com::sun::star::util::Date& x ) throw (SQLException, RuntimeException) { - setString( parameterIndex, date2String( x ) ); + setString( parameterIndex, DBTypeConversion::toDateString( x ) ); } void PreparedStatement::setTime( sal_Int32 parameterIndex, const ::com::sun::star::util::Time& x ) throw (SQLException, RuntimeException) { - setString( parameterIndex, time2String( x ) ); + setString( parameterIndex, DBTypeConversion::toTimeString( x ) ); } void PreparedStatement::setTimestamp( sal_Int32 parameterIndex, const ::com::sun::star::util::DateTime& x ) throw (SQLException, RuntimeException) { - setString( parameterIndex, dateTime2String( x ) ); + setString( parameterIndex, DBTypeConversion::toDateTimeString( x ) ); } void PreparedStatement::setBinaryStream( diff --git a/connectivity/source/drivers/postgresql/pq_tools.cxx b/connectivity/source/drivers/postgresql/pq_tools.cxx index f4125a1..f8cfbef 100644 --- a/connectivity/source/drivers/postgresql/pq_tools.cxx +++ b/connectivity/source/drivers/postgresql/pq_tools.cxx @@ -54,7 +54,6 @@ #include <libpq-fe.h> #include <string.h> - using com::sun::star::beans::XPropertySet; using com::sun::star::lang::XComponent; @@ -84,110 +83,6 @@ using com::sun::star::container::XEnumerationAccess; namespace pq_sdbc_driver { -OUString date2String( const com::sun::star::util::Date & x ) -{ - // TODO FIXME: replace by DBTypeConversion::toDateString - char buffer[64]; - sprintf( buffer, "%d-%02d-%02d", x.Year, x.Month, x.Day ); - return OUString::createFromAscii( buffer ); -} - -com::sun::star::util::Date string2Date( const OUString &date ) -{ - // TODO FIXME: replace by DBTypeConversion::toDate (if it parses the same format) - // Format: Year-Month-Day - com::sun::star::util::Date ret; - - ret.Year = (sal_Int32) rtl_ustr_toInt32( date.pData->buffer, 10 ); - - int index = date.indexOf( '-' ); - if( index >= 0 ) - { - ret.Month = (sal_Int32)rtl_ustr_toInt32( &(date.pData->buffer[ index+1]), 10 ); - int start = index; - index = date.indexOf( '-', start+1 ); - if( index >= 0 ) - { - ret.Day = (sal_Int32)rtl_ustr_toInt32( &date.pData->buffer[index+1], 10 ); - } - } - return ret; -} - -OUString time2String( const com::sun::star::util::Time & x ) -{ - // TODO FIXME: replace by DBTypeConversion::toTimeString - const size_t buflen = 19; - char buffer[buflen]; - snprintf( buffer, buflen, "%02d:%02d:%02d.%09" SAL_PRIuUINT32, x.Hours, x.Minutes, x.Seconds, x.NanoSeconds ); - return OUString::createFromAscii( buffer ); -} - - -com::sun::star::util::Time string2Time( const OUString & time ) -{ - // TODO FIXME: replace by DBTypeConversion::toTime - com::sun::star::util::Time ret; - - sal_Unicode temp[4]; - - temp[0] = time[0]; - temp[1] = time[1]; - temp[2] = 0; - ret.Hours = (sal_Int32)rtl_ustr_toInt32( temp , 10 ); - - temp[0] = time[3]; - temp[1] = time[4]; - ret.Minutes = (sal_Int32)rtl_ustr_toInt32( temp , 10 ); - - temp[0] = time[6]; - temp[1] = time[7]; - ret.Seconds = (sal_Int32)rtl_ustr_toInt32( temp , 10 ); - - if( time.getLength() >9 ) - { - // FIXME does not take into account shorter precision - ret.NanoSeconds = (sal_Int32)rtl_ustr_toInt32( &time.getStr()[9] , 10 ); - } - return ret; - -} - - - -OUString dateTime2String( const com::sun::star::util::DateTime & x ) -{ - // TODO FIXME: replace by DBTypeConversion::toDateTimeString - char buffer[128]; - sprintf( buffer, "%d-%02d-%02d %02d:%02d:%02d.%09" SAL_PRIuUINT32, - x.Year, x.Month, x.Day, - x.Hours, x.Minutes, x.Seconds, x.NanoSeconds ); - return OUString::createFromAscii( buffer ); - -} - -com::sun::star::util::DateTime string2DateTime( const OUString & dateTime ) -{ - // TODO FIXME: replace by DBTypeConversion::toDateTime (if same format) - int space = dateTime.indexOf( ' ' ); - com::sun::star::util::DateTime ret; - - if( space >= 0 ) - { - com::sun::star::util::Date date ( string2Date( OUString( dateTime.getStr(), space ) ) ); - com::sun::star::util::Time time( string2Time( OUString( dateTime.getStr() + space +1 ) ) ); - ret.Day = date.Day; - ret.Month = date.Month; - ret.Year = date.Year; - - ret.Hours = time.Hours; - ret.Minutes = time.Minutes; - ret.Seconds = time.Seconds; - ret.NanoSeconds = time.NanoSeconds; - } - return ret; -} - OUString concatQualified( const OUString & a, const OUString &b) { OUStringBuffer buf( a.getLength() + 2 + b.getLength() ); diff --git a/connectivity/source/drivers/postgresql/pq_tools.hxx b/connectivity/source/drivers/postgresql/pq_tools.hxx index 866ca08..b407693 100644 --- a/connectivity/source/drivers/postgresql/pq_tools.hxx +++ b/connectivity/source/drivers/postgresql/pq_tools.hxx @@ -51,15 +51,6 @@ namespace pq_sdbc_driver { bool isWhitespace( sal_Unicode c ); -OUString date2String( const com::sun::star::util::Date & date ); -com::sun::star::util::Date string2Date( const OUString & str ); - -OUString time2String( const com::sun::star::util::Time & time ); -com::sun::star::util::Time string2Time( const OUString & str ); - -OUString dateTime2String( const com::sun::star::util::DateTime & dateTime ); -com::sun::star::util::DateTime string2DateTime( const OUString & dateTime ); - OUString concatQualified( const OUString & a, const OUString &b); OString OUStringToOString( OUString str, ConnectionSettings *settings); diff --git a/connectivity/source/drivers/postgresql/pq_updateableresultset.cxx b/connectivity/source/drivers/postgresql/pq_updateableresultset.cxx index e0a363d..ec000a5 100644 --- a/connectivity/source/drivers/postgresql/pq_updateableresultset.cxx +++ b/connectivity/source/drivers/postgresql/pq_updateableresultset.cxx @@ -49,6 +49,8 @@ #include <string.h> +#include <connectivity/dbconversion.hxx> + using osl::MutexGuard; @@ -75,6 +77,8 @@ using com::sun::star::beans::XFastPropertySet; using com::sun::star::beans::XPropertySet; using com::sun::star::beans::XMultiPropertySet; +using namespace dbtools; + namespace pq_sdbc_driver { @@ -513,17 +517,17 @@ void UpdateableResultSet::updateBytes( sal_Int32 columnIndex, const ::com::sun:: void UpdateableResultSet::updateDate( sal_Int32 columnIndex, const ::com::sun::star::util::Date& x ) throw (SQLException, RuntimeException) { - updateString( columnIndex, date2String( x ) ); + updateString( columnIndex, DBTypeConversion::toDateString( x ) ); } void UpdateableResultSet::updateTime( sal_Int32 columnIndex, const ::com::sun::star::util::Time& x ) throw (SQLException, RuntimeException) { - updateString( columnIndex, time2String( x ) ); + updateString( columnIndex, DBTypeConversion::toTimeString( x ) ); } void UpdateableResultSet::updateTimestamp( sal_Int32 columnIndex, const ::com::sun::star::util::DateTime& x ) throw (SQLException, RuntimeException) { - updateString( columnIndex, dateTime2String( x ) ); + updateString( columnIndex, DBTypeConversion::toDateTimeString( x ) ); } void UpdateableResultSet::updateBinaryStream( sal_Int32 /* columnIndex */, const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& /* x */, sal_Int32 /* length */ ) throw (SQLException, RuntimeException) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits