dbaccess/source/ui/control/FieldDescControl.cxx | 47 +++++++++++++++++++++++- dbaccess/source/ui/inc/FieldDescControl.hxx | 5 ++ 2 files changed, 50 insertions(+), 2 deletions(-)
New commits: commit e6004bddfc8d7d41f4e17691eaeefd770c608a13 Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Thu Jan 21 20:52:41 2021 +0000 Commit: Christian Lohmaier <lohmaier+libreoff...@googlemail.com> CommitDate: Wed Jan 27 15:43:37 2021 +0100 tdf#138409 numerical ControlFormat strings shouldn't be localized i.e. input fr/de 12,34 should be stored as 12.34 Change-Id: I20c97d2d604998a40e3a15963aa3d8716101e3c4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109750 Tested-by: Jenkins Reviewed-by: Lionel Mamane <lio...@mamane.lu> (cherry picked from commit c10b7b3c2e9743b284b0acb21a7dd219918d51ac) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109798 Reviewed-by: Adolfo Jayme Barrientos <fit...@ubuntu.com> Reviewed-by: Christian Lohmaier <lohmaier+libreoff...@googlemail.com> Tested-by: Christian Lohmaier <lohmaier+libreoff...@googlemail.com> diff --git a/dbaccess/source/ui/control/FieldDescControl.cxx b/dbaccess/source/ui/control/FieldDescControl.cxx index bbd39519ce45..5b925a93f56a 100644 --- a/dbaccess/source/ui/control/FieldDescControl.cxx +++ b/dbaccess/source/ui/control/FieldDescControl.cxx @@ -1107,7 +1107,9 @@ void OFieldDescControl::SaveData( OFieldDescription* pFieldDescr ) OUString sDefault; if (m_xDefault) { - sDefault = m_xDefault->get_text(); + // tdf#138409 take the control default in the UI Locale format, e.g. 12,34 and return a string + // suitable as the database default, e.g. 12.34 + sDefault = CanonicalizeToControlDefault(pFieldDescr, m_xDefault->get_text()); } else if (m_xBoolDefault) { @@ -1338,4 +1340,47 @@ OUString OFieldDescControl::getControlDefault( const OFieldDescription* _pFieldD return sDefault; } +// tdf#138409 intended to be effectively the reverse of getControlDefault to +// turn a user's possibly 12,34 format into 12.34 format for numerical types +OUString OFieldDescControl::CanonicalizeToControlDefault(const OFieldDescription* pFieldDescr, const OUString& rDefault) const +{ + if (rDefault.isEmpty()) + return rDefault; + + bool bIsNumericalType = false; + switch (pFieldDescr->GetType()) + { + case DataType::TINYINT: + case DataType::SMALLINT: + case DataType::INTEGER: + case DataType::BIGINT: + case DataType::FLOAT: + case DataType::REAL: + case DataType::DOUBLE: + case DataType::NUMERIC: + case DataType::DECIMAL: + bIsNumericalType = true; + break; + } + + if (!bIsNumericalType) + return rDefault; + + try + { + sal_uInt32 nFormatKey; + bool bTextFormat = isTextFormat(pFieldDescr, nFormatKey); + if (bTextFormat) + return rDefault; + double nValue = GetFormatter()->convertStringToNumber(nFormatKey, rDefault); + return OUString::number(nValue); + } + catch(const Exception&) + { + } + + return rDefault; +} + + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/ui/inc/FieldDescControl.hxx b/dbaccess/source/ui/inc/FieldDescControl.hxx index c467d4ca5402..8c8e0c819cd0 100644 --- a/dbaccess/source/ui/inc/FieldDescControl.hxx +++ b/dbaccess/source/ui/inc/FieldDescControl.hxx @@ -188,7 +188,10 @@ namespace dbaui virtual css::uno::Reference< css::sdbc::XDatabaseMetaData> getMetaData() = 0; virtual css::uno::Reference< css::sdbc::XConnection> getConnection() = 0; - OUString getControlDefault( const OFieldDescription* _pFieldDescr, bool _bCheck = true) const; + OUString getControlDefault( const OFieldDescription* pFieldDescr, bool _bCheck = true) const; + // tdf#138409 take the control default in the UI Locale format, e.g. 12,34 and return a string + // suitable as the database default, e.g. 12.34 + OUString CanonicalizeToControlDefault(const OFieldDescription* pFieldDescr, const OUString& rUserText) const; void setEditWidth(sal_Int32 _nWidth) { m_nEditWidth = _nWidth; } }; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits