Bump version to 6.4-15
[LibreOffice.git] / include / connectivity / dbconversion.hxx
blob5991682f7dfe87ba139149359bbd3374d89ea5d7
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
30 namespace sun
32 namespace star
34 namespace lang
36 struct Locale;
38 namespace sdb
40 class XColumn;
41 class XColumnUpdate;
43 namespace beans
45 class XPropertySet;
47 namespace util
49 class XNumberFormatter;
50 class XNumberFormatsSupplier;
51 struct Time;
52 struct DateTime;
54 namespace script
56 class XTypeConverter;
62 namespace dbtools
64 namespace DBTypeConversion
66 OOO_DLLPUBLIC_DBTOOLS css::util::Date const & getStandardDate();
67 /// @throws css::lang::IllegalArgumentException
68 OOO_DLLPUBLIC_DBTOOLS void setValue(const css::uno::Reference< css::sdb::XColumnUpdate>& xVariant,
69 const css::uno::Reference< css::util::XNumberFormatter>& xFormatter,
70 const css::util::Date& rNullDate,
71 const OUString& rString,
72 sal_Int32 nKey,
73 sal_Int16 nFieldType,
74 sal_Int16 nKeyType);
76 /// @throws css::lang::IllegalArgumentException
77 OOO_DLLPUBLIC_DBTOOLS void setValue(const css::uno::Reference< css::sdb::XColumnUpdate>& xVariant,
78 const css::util::Date& rNullDate,
79 const double& rValue,
80 sal_Int16 nKeyType);
82 OOO_DLLPUBLIC_DBTOOLS double getValue( const css::uno::Reference< css::sdb::XColumn>& xVariant, const css::util::Date& rNullDate );
84 // get the columnvalue as string with a default format given by the column or a default format
85 // for the type
86 OOO_DLLPUBLIC_DBTOOLS OUString getFormattedValue(
87 const css::uno::Reference< css::beans::XPropertySet>& _xColumn,
88 const css::uno::Reference< css::util::XNumberFormatter>& xFormatter,
89 const css::lang::Locale& _rLocale,
90 const css::util::Date& rNullDate);
92 OOO_DLLPUBLIC_DBTOOLS OUString getFormattedValue(
93 const css::uno::Reference< css::sdb::XColumn>& _xColumn,
94 const css::uno::Reference< css::util::XNumberFormatter>& xFormatter,
95 const css::util::Date& rNullDate,
96 sal_Int32 nKey,
97 sal_Int16 nKeyType);
99 OOO_DLLPUBLIC_DBTOOLS css::util::Date toDate(double dVal, const css::util::Date& _rNullDate = getStandardDate());
100 OOO_DLLPUBLIC_DBTOOLS css::util::Date toDate(const OUString& _sSQLDate);
101 OOO_DLLPUBLIC_DBTOOLS css::util::Time toTime(double dVal, short nDigits = 9);
102 OOO_DLLPUBLIC_DBTOOLS css::util::Time toTime(const OUString& _sSQLDate);
103 OOO_DLLPUBLIC_DBTOOLS css::util::DateTime toDateTime(double dVal, const css::util::Date& _rNullDate = getStandardDate());
104 OOO_DLLPUBLIC_DBTOOLS css::util::DateTime toDateTime(const OUString& _sSQLDate);
106 OOO_DLLPUBLIC_DBTOOLS sal_Int64 getNsFromTime(const css::util::Time& rVal);
108 OOO_DLLPUBLIC_DBTOOLS sal_Int32 toDays(const css::util::Date& _rVal, const css::util::Date& _rNullDate = getStandardDate());
110 OOO_DLLPUBLIC_DBTOOLS double toDouble(const css::util::Date& rVal, const css::util::Date& _rNullDate = getStandardDate());
111 OOO_DLLPUBLIC_DBTOOLS double toDouble(const css::util::Time& rVal);
112 OOO_DLLPUBLIC_DBTOOLS double toDouble(const css::util::DateTime& rVal, const css::util::Date& _rNullDate = getStandardDate());
114 OOO_DLLPUBLIC_DBTOOLS css::util::Date toDate(sal_Int32 _nVal);
115 OOO_DLLPUBLIC_DBTOOLS css::util::Time toTime(sal_Int64 _nVal);
117 /** convert a double which is a date value relative to the standard db null date into a date value relative
118 to a given fixed date.
120 inline double toNullDate(const css::util::Date& _rNullDate, double _rVal) { return _rVal - toDays(_rNullDate); }
122 // return the date from the numberformatsupplier or the STANDARD_DATE (1900,1,1)
123 OOO_DLLPUBLIC_DBTOOLS css::util::Date getNULLDate(const css::uno::Reference< css::util::XNumberFormatsSupplier > &xSupplier);
125 // return the date in the format %04d-%02d-%02d
126 OOO_DLLPUBLIC_DBTOOLS OUString toDateString(const css::util::Date& rDate);
127 // return the time in the format %02d:%02d:%02d
128 OOO_DLLPUBLIC_DBTOOLS OUString toTimeStringS(const css::util::Time& rTime);
129 // return the time in the format %02d:%02d:%02d.%09d
130 OOO_DLLPUBLIC_DBTOOLS OUString toTimeString(const css::util::Time& rTime);
131 // return the DateTime in the format %04d-%02d-%02d %02d:%02d:%02d.%09d
132 OOO_DLLPUBLIC_DBTOOLS OUString toDateTimeString(const css::util::DateTime& _rDateTime);
133 // return the any in an sql standard format
134 OOO_DLLPUBLIC_DBTOOLS OUString toSQLString(sal_Int32 eType, const css::uno::Any& _rVal,
135 const css::uno::Reference< css::script::XTypeConverter >& _rxTypeConverter);
137 /** converts a Unicode string into a 8-bit string, using the given encoding
139 @param _rSource
140 the source string to convert
141 @param _rDest
142 the destination string
143 @param _eEncoding
144 the encoding to use for the conversion
146 @throws css::sdbc::SQLException
147 if the given string contains characters which are not convertible using the given encoding
148 The SQLState of the exception will be set to 22018 ("Invalid character value for cast specification")
150 @return
151 the length of the converted string
153 OOO_DLLPUBLIC_DBTOOLS sal_Int32 convertUnicodeString(
154 const OUString& _rSource,
155 OString& _rDest,
156 rtl_TextEncoding _eEncoding
159 /** converts a Unicode string into a 8-bit string, using the given encoding
161 @param _rSource
162 the source string to convert
164 @param _rDest
165 the destination string
167 @param _nMaxLen
168 the maximum length of the destination string
170 @param _eEncoding
171 the encoding to use for the conversion
173 @throws css::sdbc::SQLException
174 if convertUnicodeString, which is called internally, throws such an exception
176 @throws css::sdbc::SQLException
177 if the conversion results in a string which is longer than _nMaxLen
179 @return
180 the length of the converted string
182 OOO_DLLPUBLIC_DBTOOLS sal_Int32 convertUnicodeStringToLength(
183 const OUString& _rSource,
184 OString& _rDest,
185 sal_Int32 _nMaxLen,
186 rtl_TextEncoding _eEncoding
190 } // namespace dbtools
192 #endif // INCLUDED_CONNECTIVITY_DBCONVERSION_HXX
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */