1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_CONNECTIVITY_DBCONVERSION_HXX
21 #define INCLUDED_CONNECTIVITY_DBCONVERSION_HXX
23 #include <com/sun/star/util/Date.hpp>
24 #include <connectivity/dbtoolsdllapi.hxx>
26 namespace com::sun::star::uno
{ template <typename
> class Reference
; }
28 namespace com::sun::star
45 class XNumberFormatter
;
46 class XNumberFormatsSupplier
;
56 namespace dbtools::DBTypeConversion
58 OOO_DLLPUBLIC_DBTOOLS
css::util::Date
const & getStandardDate();
59 /// @throws css::lang::IllegalArgumentException
60 OOO_DLLPUBLIC_DBTOOLS
void setValue(const css::uno::Reference
< css::sdb::XColumnUpdate
>& xVariant
,
61 const css::uno::Reference
< css::util::XNumberFormatter
>& xFormatter
,
62 const css::util::Date
& rNullDate
,
63 const OUString
& rString
,
68 /// @throws css::lang::IllegalArgumentException
69 OOO_DLLPUBLIC_DBTOOLS
void setValue(const css::uno::Reference
< css::sdb::XColumnUpdate
>& xVariant
,
70 const css::util::Date
& rNullDate
,
74 OOO_DLLPUBLIC_DBTOOLS
double getValue( const css::uno::Reference
< css::sdb::XColumn
>& xVariant
, const css::util::Date
& rNullDate
);
76 // get the columnvalue as string with a default format given by the column or a default format
78 OOO_DLLPUBLIC_DBTOOLS OUString
getFormattedValue(
79 const css::uno::Reference
< css::beans::XPropertySet
>& _xColumn
,
80 const css::uno::Reference
< css::util::XNumberFormatter
>& xFormatter
,
81 const css::lang::Locale
& _rLocale
,
82 const css::util::Date
& rNullDate
);
84 OOO_DLLPUBLIC_DBTOOLS OUString
getFormattedValue(
85 const css::uno::Reference
< css::sdb::XColumn
>& _xColumn
,
86 const css::uno::Reference
< css::util::XNumberFormatter
>& xFormatter
,
87 const css::util::Date
& rNullDate
,
91 OOO_DLLPUBLIC_DBTOOLS
css::util::Date
toDate(double dVal
, const css::util::Date
& _rNullDate
= getStandardDate());
92 OOO_DLLPUBLIC_DBTOOLS
css::util::Date
toDate(std::u16string_view _sSQLDate
);
93 OOO_DLLPUBLIC_DBTOOLS
css::util::Time
toTime(double dVal
, short nDigits
= 9);
94 OOO_DLLPUBLIC_DBTOOLS
css::util::Time
toTime(std::u16string_view _sSQLDate
);
95 OOO_DLLPUBLIC_DBTOOLS
css::util::DateTime
toDateTime(double dVal
, const css::util::Date
& _rNullDate
= getStandardDate());
96 OOO_DLLPUBLIC_DBTOOLS
css::util::DateTime
toDateTime(const OUString
& _sSQLDate
);
98 OOO_DLLPUBLIC_DBTOOLS sal_Int64
getNsFromTime(const css::util::Time
& rVal
);
100 OOO_DLLPUBLIC_DBTOOLS sal_Int32
toDays(const css::util::Date
& _rVal
, const css::util::Date
& _rNullDate
= getStandardDate());
102 OOO_DLLPUBLIC_DBTOOLS
double toDouble(const css::util::Date
& rVal
, const css::util::Date
& _rNullDate
= getStandardDate());
103 OOO_DLLPUBLIC_DBTOOLS
double toDouble(const css::util::Time
& rVal
);
104 OOO_DLLPUBLIC_DBTOOLS
double toDouble(const css::util::DateTime
& rVal
, const css::util::Date
& _rNullDate
= getStandardDate());
106 OOO_DLLPUBLIC_DBTOOLS
css::util::Date
toDate(sal_Int32 _nVal
);
107 OOO_DLLPUBLIC_DBTOOLS
css::util::Time
toTime(sal_Int64 _nVal
);
109 /** convert a double which is a date value relative to the standard db null date into a date value relative
110 to a given fixed date.
112 inline double toNullDate(const css::util::Date
& _rNullDate
, double _rVal
) { return _rVal
- toDays(_rNullDate
); }
114 // return the date from the numberformatsupplier or the STANDARD_DATE (1900,1,1)
115 OOO_DLLPUBLIC_DBTOOLS
css::util::Date
getNULLDate(const css::uno::Reference
< css::util::XNumberFormatsSupplier
> &xSupplier
);
117 // return the date in the format %04d-%02d-%02d
118 OOO_DLLPUBLIC_DBTOOLS OUString
toDateString(const css::util::Date
& rDate
);
119 // return the time in the format %02d:%02d:%02d
120 OOO_DLLPUBLIC_DBTOOLS OUString
toTimeStringS(const css::util::Time
& rTime
);
121 // return the time in the format %02d:%02d:%02d.%09d
122 OOO_DLLPUBLIC_DBTOOLS OUString
toTimeString(const css::util::Time
& rTime
);
123 // return the DateTime in the format %04d-%02d-%02d %02d:%02d:%02d.%09d
124 OOO_DLLPUBLIC_DBTOOLS OUString
toDateTimeString(const css::util::DateTime
& _rDateTime
);
125 // return the any in an sql standard format
126 OOO_DLLPUBLIC_DBTOOLS OUString
toSQLString(sal_Int32 eType
, const css::uno::Any
& _rVal
,
127 const css::uno::Reference
< css::script::XTypeConverter
>& _rxTypeConverter
);
129 /** converts a Unicode string into a 8-bit string, using the given encoding
132 the source string to convert
134 the destination string
136 the encoding to use for the conversion
138 @throws css::sdbc::SQLException
139 if the given string contains characters which are not convertible using the given encoding
140 The SQLState of the exception will be set to 22018 ("Invalid character value for cast specification")
143 the length of the converted string
145 OOO_DLLPUBLIC_DBTOOLS sal_Int32
convertUnicodeString(
146 const OUString
& _rSource
,
148 rtl_TextEncoding _eEncoding
151 /** converts a Unicode string into a 8-bit string, using the given encoding
154 the source string to convert
157 the destination string
160 the maximum length of the destination string
163 the encoding to use for the conversion
165 @throws css::sdbc::SQLException
166 if convertUnicodeString, which is called internally, throws such an exception
168 @throws css::sdbc::SQLException
169 if the conversion results in a string which is longer than _nMaxLen
172 the length of the converted string
174 OOO_DLLPUBLIC_DBTOOLS sal_Int32
convertUnicodeStringToLength(
175 const OUString
& _rSource
,
178 rtl_TextEncoding _eEncoding
181 } // namespace dbtools::DBTypeConversion
183 #endif // INCLUDED_CONNECTIVITY_DBCONVERSION_HXX
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */