Update git submodules
[LibreOffice.git] / include / connectivity / dbconversion.hxx
blobe9471344cea9820bbc505fce59cddb21eb4818d0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
30 namespace lang
32 struct Locale;
34 namespace sdb
36 class XColumn;
37 class XColumnUpdate;
39 namespace beans
41 class XPropertySet;
43 namespace util
45 class XNumberFormatter;
46 class XNumberFormatsSupplier;
47 struct Time;
48 struct DateTime;
50 namespace script
52 class XTypeConverter;
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,
64 sal_Int32 nKey,
65 sal_Int16 nFieldType,
66 sal_Int16 nKeyType);
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,
71 const double& rValue,
72 sal_Int16 nKeyType);
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
77 // for the type
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,
88 sal_Int32 nKey,
89 sal_Int16 nKeyType);
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
131 @param _rSource
132 the source string to convert
133 @param _rDest
134 the destination string
135 @param _eEncoding
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")
142 @return
143 the length of the converted string
145 OOO_DLLPUBLIC_DBTOOLS sal_Int32 convertUnicodeString(
146 const OUString& _rSource,
147 OString& _rDest,
148 rtl_TextEncoding _eEncoding
151 /** converts a Unicode string into a 8-bit string, using the given encoding
153 @param _rSource
154 the source string to convert
156 @param _rDest
157 the destination string
159 @param _nMaxLen
160 the maximum length of the destination string
162 @param _eEncoding
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
171 @return
172 the length of the converted string
174 OOO_DLLPUBLIC_DBTOOLS sal_Int32 convertUnicodeStringToLength(
175 const OUString& _rSource,
176 OString& _rDest,
177 sal_Int32 _nMaxLen,
178 rtl_TextEncoding _eEncoding
181 } // namespace dbtools::DBTypeConversion
183 #endif // INCLUDED_CONNECTIVITY_DBCONVERSION_HXX
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */