Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_CONNECTIVITY_DBCONVERSION_HXX
21 : #define INCLUDED_CONNECTIVITY_DBCONVERSION_HXX
22 :
23 : #include <com/sun/star/lang/IllegalArgumentException.hpp>
24 : #include <com/sun/star/util/Date.hpp>
25 : #include <com/sun/star/uno/Reference.hxx>
26 : #include <connectivity/dbtoolsdllapi.hxx>
27 :
28 : namespace com
29 : {
30 : namespace sun
31 : {
32 : namespace star
33 : {
34 : namespace lang
35 : {
36 : struct Locale;
37 : }
38 : namespace sdb
39 : {
40 : class XColumn;
41 : class XColumnUpdate;
42 : }
43 : namespace sdbc
44 : {
45 : class SQLException;
46 : }
47 : namespace beans
48 : {
49 : class XPropertySet;
50 : }
51 : namespace util
52 : {
53 : class XNumberFormatter;
54 : class XNumberFormatsSupplier;
55 : struct Time;
56 : struct DateTime;
57 : }
58 : namespace script
59 : {
60 : class XTypeConverter;
61 : }
62 : }
63 : }
64 : }
65 :
66 : namespace dbtools
67 : {
68 : namespace DBTypeConversion
69 : {
70 : OOO_DLLPUBLIC_DBTOOLS ::com::sun::star::util::Date getStandardDate();
71 : OOO_DLLPUBLIC_DBTOOLS void setValue(const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XColumnUpdate>& xVariant,
72 : const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter>& xFormatter,
73 : const ::com::sun::star::util::Date& rNullDate,
74 : const OUString& rString,
75 : sal_Int32 nKey,
76 : sal_Int16 nFieldType,
77 : sal_Int16 nKeyType) throw(::com::sun::star::lang::IllegalArgumentException);
78 :
79 : OOO_DLLPUBLIC_DBTOOLS void setValue(const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XColumnUpdate>& xVariant,
80 : const ::com::sun::star::util::Date& rNullDate,
81 : const double& rValue,
82 : sal_Int16 nKeyType) throw(::com::sun::star::lang::IllegalArgumentException);
83 :
84 : OOO_DLLPUBLIC_DBTOOLS double getValue( const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XColumn>& xVariant, const ::com::sun::star::util::Date& rNullDate );
85 :
86 : // get the columnvalue as string with a default format given by the column or a default format
87 : // for the type
88 : OOO_DLLPUBLIC_DBTOOLS OUString getFormattedValue(
89 : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xColumn,
90 : const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter>& xFormatter,
91 : const ::com::sun::star::lang::Locale& _rLocale,
92 : const ::com::sun::star::util::Date& rNullDate);
93 :
94 : OOO_DLLPUBLIC_DBTOOLS OUString getFormattedValue(
95 : const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XColumn>& _xColumn,
96 : const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter>& xFormatter,
97 : const ::com::sun::star::util::Date& rNullDate,
98 : sal_Int32 nKey,
99 : sal_Int16 nKeyType);
100 :
101 : OOO_DLLPUBLIC_DBTOOLS ::com::sun::star::util::Date toDate(double dVal, const ::com::sun::star::util::Date& _rNullDate = getStandardDate());
102 : OOO_DLLPUBLIC_DBTOOLS ::com::sun::star::util::Date toDate(const OUString& _sSQLDate);
103 : OOO_DLLPUBLIC_DBTOOLS ::com::sun::star::util::Time toTime(double dVal, short nDigits = 9);
104 : OOO_DLLPUBLIC_DBTOOLS ::com::sun::star::util::Time toTime(const OUString& _sSQLDate);
105 : OOO_DLLPUBLIC_DBTOOLS ::com::sun::star::util::DateTime toDateTime(double dVal, const ::com::sun::star::util::Date& _rNullDate = getStandardDate());
106 : OOO_DLLPUBLIC_DBTOOLS ::com::sun::star::util::DateTime toDateTime(const OUString& _sSQLDate);
107 :
108 : OOO_DLLPUBLIC_DBTOOLS sal_Int64 getNsFromTime(const ::com::sun::star::util::Time& rVal);
109 :
110 : OOO_DLLPUBLIC_DBTOOLS sal_Int32 toDays(const ::com::sun::star::util::Date& _rVal, const ::com::sun::star::util::Date& _rNullDate = getStandardDate());
111 :
112 : OOO_DLLPUBLIC_DBTOOLS double toDouble(const ::com::sun::star::util::Date& rVal, const ::com::sun::star::util::Date& _rNullDate = getStandardDate());
113 : OOO_DLLPUBLIC_DBTOOLS double toDouble(const ::com::sun::star::util::Time& rVal);
114 : OOO_DLLPUBLIC_DBTOOLS double toDouble(const ::com::sun::star::util::DateTime& rVal, const ::com::sun::star::util::Date& _rNullDate = getStandardDate());
115 :
116 : OOO_DLLPUBLIC_DBTOOLS ::com::sun::star::util::Date toDate(sal_Int32 _nVal);
117 : OOO_DLLPUBLIC_DBTOOLS ::com::sun::star::util::Time toTime(sal_Int64 _nVal);
118 :
119 : /** convert a double which is a date value relative to a given fixed date into a date value relative
120 : to the standard db null date.
121 : */
122 : inline double toStandardDbDate(const ::com::sun::star::util::Date& _rNullDate, double _rVal) { return _rVal + toDays(_rNullDate); }
123 : /** convert a double which is a date value relative to the standard db null date into a date value relative
124 : to a given fixed date.
125 : */
126 0 : inline double toNullDate(const ::com::sun::star::util::Date& _rNullDate, double _rVal) { return _rVal - toDays(_rNullDate); }
127 :
128 : // return the date from the numberformatsupplier or the STANDARD_DATE (1900,1,1)
129 : OOO_DLLPUBLIC_DBTOOLS ::com::sun::star::util::Date getNULLDate(const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier > &xSupplier);
130 :
131 : // return the date in the format %04d-%02d-%02d
132 : OOO_DLLPUBLIC_DBTOOLS OUString toDateString(const ::com::sun::star::util::Date& rDate);
133 : // return the time in the format %02d:%02d:%02d
134 : OOO_DLLPUBLIC_DBTOOLS OUString toTimeStringS(const ::com::sun::star::util::Time& rTime);
135 : // return the time in the format %02d:%02d:%02d.%09d
136 : OOO_DLLPUBLIC_DBTOOLS OUString toTimeString(const ::com::sun::star::util::Time& rTime);
137 : // return the DateTime in the format %04d-%02d-%02d %02d:%02d:%02d.%09d
138 : OOO_DLLPUBLIC_DBTOOLS OUString toDateTimeString(const ::com::sun::star::util::DateTime& _rDateTime);
139 : // return the any in an sql standard format
140 : OOO_DLLPUBLIC_DBTOOLS OUString toSQLString(sal_Int32 eType, const ::com::sun::star::uno::Any& _rVal, bool bQuote,
141 : const ::com::sun::star::uno::Reference< ::com::sun::star::script::XTypeConverter >& _rxTypeConverter);
142 :
143 : /** converts a Unicode string into a 8-bit string, using the given encoding
144 :
145 : @param _rSource
146 : the source string to convert
147 : @param _rDest
148 : the destination string
149 : @param _eEncoding
150 : the encoding to use for the conversion
151 :
152 : @throws com::sun::star::sdbc::SQLException
153 : if the given string contains characters which are not convertible using the given encoding
154 : The SQLState of the exception will be set to 22018 ("Invalid character value for cast specification")
155 :
156 : @return
157 : the length of the converted string
158 : */
159 : OOO_DLLPUBLIC_DBTOOLS sal_Int32 convertUnicodeString(
160 : const OUString& _rSource,
161 : OString& _rDest,
162 : rtl_TextEncoding _eEncoding
163 : );
164 :
165 : /** converts a Unicode string into a 8-bit string, using the given encoding
166 :
167 : @param _rSource
168 : the source string to convert
169 :
170 : @param _rDest
171 : the destination string
172 :
173 : @param _nMaxLen
174 : the maximum length of the destination string
175 :
176 : @param _eEncoding
177 : the encoding to use for the conversion
178 :
179 : @throws com::sun::star::sdbc::SQLException
180 : if convertUnicodeString, which is called internally, throws such an exception
181 :
182 : @throws com::sun::star::sdbc::SQLException
183 : if the conversion results in a string which is longer than _nMaxLen
184 :
185 : @return
186 : the length of the converted string
187 : */
188 : OOO_DLLPUBLIC_DBTOOLS sal_Int32 convertUnicodeStringToLength(
189 : const OUString& _rSource,
190 : OString& _rDest,
191 : sal_Int32 _nMaxLen,
192 : rtl_TextEncoding _eEncoding
193 : );
194 : }
195 :
196 : } // namespace dbtools
197 :
198 : #endif // INCLUDED_CONNECTIVITY_DBCONVERSION_HXX
199 :
200 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|