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/lang/IllegalArgumentException.hpp>
24 #include <com/sun/star/util/Date.hpp>
25 #include <com/sun/star/uno/Reference.hxx>
26 #include <connectivity/dbtoolsdllapi.hxx>
53 class XNumberFormatter
;
54 class XNumberFormatsSupplier
;
68 namespace DBTypeConversion
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
,
77 sal_Int16 nKeyType
) throw(::com::sun::star::lang::IllegalArgumentException
);
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
,
82 sal_Int16 nKeyType
) throw(::com::sun::star::lang::IllegalArgumentException
);
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
);
86 // get the columnvalue as string with a default format given by the column or a default format
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
);
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
,
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
);
108 OOO_DLLPUBLIC_DBTOOLS sal_Int64
getNsFromTime(const ::com::sun::star::util::Time
& rVal
);
110 OOO_DLLPUBLIC_DBTOOLS sal_Int32
toDays(const ::com::sun::star::util::Date
& _rVal
, const ::com::sun::star::util::Date
& _rNullDate
= getStandardDate());
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());
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
);
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.
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.
126 inline double toNullDate(const ::com::sun::star::util::Date
& _rNullDate
, double _rVal
) { return _rVal
- toDays(_rNullDate
); }
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
);
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
);
143 /** converts a Unicode string into a 8-bit string, using the given encoding
146 the source string to convert
148 the destination string
150 the encoding to use for the conversion
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")
157 the length of the converted string
159 OOO_DLLPUBLIC_DBTOOLS sal_Int32
convertUnicodeString(
160 const OUString
& _rSource
,
162 rtl_TextEncoding _eEncoding
165 /** converts a Unicode string into a 8-bit string, using the given encoding
168 the source string to convert
171 the destination string
174 the maximum length of the destination string
177 the encoding to use for the conversion
179 @throws com::sun::star::sdbc::SQLException
180 if convertUnicodeString, which is called internally, throws such an exception
182 @throws com::sun::star::sdbc::SQLException
183 if the conversion results in a string which is longer than _nMaxLen
186 the length of the converted string
188 OOO_DLLPUBLIC_DBTOOLS sal_Int32
convertUnicodeStringToLength(
189 const OUString
& _rSource
,
192 rtl_TextEncoding _eEncoding
196 } // namespace dbtools
198 #endif // INCLUDED_CONNECTIVITY_DBCONVERSION_HXX
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */