1*079eb577SAndrew Rist /**************************************************************
2*079eb577SAndrew Rist *
3*079eb577SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*079eb577SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*079eb577SAndrew Rist * distributed with this work for additional information
6*079eb577SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*079eb577SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*079eb577SAndrew Rist * "License"); you may not use this file except in compliance
9*079eb577SAndrew Rist * with the License. You may obtain a copy of the License at
10*079eb577SAndrew Rist *
11*079eb577SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*079eb577SAndrew Rist *
13*079eb577SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*079eb577SAndrew Rist * software distributed under the License is distributed on an
15*079eb577SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*079eb577SAndrew Rist * KIND, either express or implied. See the License for the
17*079eb577SAndrew Rist * specific language governing permissions and limitations
18*079eb577SAndrew Rist * under the License.
19*079eb577SAndrew Rist *
20*079eb577SAndrew Rist *************************************************************/
21cdf0e10cSrcweir #include "mysqlc_general.hxx"
22cdf0e10cSrcweir #include "mysqlc_resultsetmetadata.hxx"
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include <cppconn/exception.h>
25cdf0e10cSrcweir #include <cppconn/datatype.h>
26cdf0e10cSrcweir
27cdf0e10cSrcweir using com::sun::star::sdbc::SQLException;
28cdf0e10cSrcweir
29cdf0e10cSrcweir using com::sun::star::uno::UNO_QUERY;
30cdf0e10cSrcweir using com::sun::star::uno::Reference;
31cdf0e10cSrcweir using com::sun::star::uno::XInterface;
32cdf0e10cSrcweir using com::sun::star::uno::Any;
33cdf0e10cSrcweir using ::rtl::OUString;
34cdf0e10cSrcweir
35cdf0e10cSrcweir namespace mysqlc_sdbc_driver
36cdf0e10cSrcweir {
37cdf0e10cSrcweir // -----------------------------------------------------------------------------
throwFeatureNotImplementedException(const sal_Char * _pAsciiFeatureName,const Reference<XInterface> & _rxContext,const Any * _pNextException)38cdf0e10cSrcweir void throwFeatureNotImplementedException( const sal_Char* _pAsciiFeatureName, const Reference< XInterface >& _rxContext, const Any* _pNextException )
39cdf0e10cSrcweir throw (SQLException)
40cdf0e10cSrcweir {
41cdf0e10cSrcweir const ::rtl::OUString sMessage = ::rtl::OUString::createFromAscii( _pAsciiFeatureName ) + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ": feature not implemented." ) );
42cdf0e10cSrcweir throw SQLException(
43cdf0e10cSrcweir sMessage,
44cdf0e10cSrcweir _rxContext,
45cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HYC00")),
46cdf0e10cSrcweir 0,
47cdf0e10cSrcweir _pNextException ? *_pNextException : Any()
48cdf0e10cSrcweir );
49cdf0e10cSrcweir }
50cdf0e10cSrcweir
51cdf0e10cSrcweir
throwInvalidArgumentException(const sal_Char * _pAsciiFeatureName,const Reference<XInterface> & _rxContext,const Any * _pNextException)52cdf0e10cSrcweir void throwInvalidArgumentException( const sal_Char* _pAsciiFeatureName, const Reference< XInterface >& _rxContext, const Any* _pNextException )
53cdf0e10cSrcweir throw (SQLException)
54cdf0e10cSrcweir {
55cdf0e10cSrcweir const ::rtl::OUString sMessage = ::rtl::OUString::createFromAscii( _pAsciiFeatureName ) + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ": invalid arguments." ) );
56cdf0e10cSrcweir throw SQLException(
57cdf0e10cSrcweir sMessage,
58cdf0e10cSrcweir _rxContext,
59cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HYC00")),
60cdf0e10cSrcweir 0,
61cdf0e10cSrcweir _pNextException ? *_pNextException : Any()
62cdf0e10cSrcweir );
63cdf0e10cSrcweir }
64cdf0e10cSrcweir
translateAndThrow(const::sql::SQLException & _error,const::com::sun::star::uno::Reference<::com::sun::star::uno::XInterface> & _context,const rtl_TextEncoding encoding)65cdf0e10cSrcweir void translateAndThrow(const ::sql::SQLException& _error, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _context, const rtl_TextEncoding encoding)
66cdf0e10cSrcweir {
67cdf0e10cSrcweir throw SQLException(
68cdf0e10cSrcweir convert(_error.what(), encoding),
69cdf0e10cSrcweir _context,
70cdf0e10cSrcweir convert(_error.getSQLState(), encoding),
71cdf0e10cSrcweir _error.getErrorCode(),
72cdf0e10cSrcweir Any()
73cdf0e10cSrcweir );
74cdf0e10cSrcweir }
75cdf0e10cSrcweir
76cdf0e10cSrcweir
getStringFromAny(const Any & _rAny)77cdf0e10cSrcweir OUString getStringFromAny(const Any& _rAny)
78cdf0e10cSrcweir {
79cdf0e10cSrcweir OUString nReturn;
80cdf0e10cSrcweir OSL_VERIFY( _rAny >>= nReturn );
81cdf0e10cSrcweir return nReturn;
82cdf0e10cSrcweir }
83cdf0e10cSrcweir
84cdf0e10cSrcweir
mysqlToOOOType(int cppConnType)85cdf0e10cSrcweir int mysqlToOOOType(int cppConnType)
86cdf0e10cSrcweir throw ()
87cdf0e10cSrcweir {
88cdf0e10cSrcweir switch (cppConnType) {
89cdf0e10cSrcweir case sql::DataType::BIT:
90cdf0e10cSrcweir return com::sun::star::sdbc::DataType::VARCHAR;
91cdf0e10cSrcweir
92cdf0e10cSrcweir case sql::DataType::TINYINT:
93cdf0e10cSrcweir return com::sun::star::sdbc::DataType::TINYINT;
94cdf0e10cSrcweir
95cdf0e10cSrcweir case sql::DataType::SMALLINT:
96cdf0e10cSrcweir return com::sun::star::sdbc::DataType::SMALLINT;
97cdf0e10cSrcweir
98cdf0e10cSrcweir case sql::DataType::INTEGER:
99cdf0e10cSrcweir return com::sun::star::sdbc::DataType::INTEGER;
100cdf0e10cSrcweir
101cdf0e10cSrcweir case sql::DataType::BIGINT:
102cdf0e10cSrcweir return com::sun::star::sdbc::DataType::BIGINT;
103cdf0e10cSrcweir
104cdf0e10cSrcweir case sql::DataType::REAL:
105cdf0e10cSrcweir return com::sun::star::sdbc::DataType::REAL;
106cdf0e10cSrcweir
107cdf0e10cSrcweir case sql::DataType::DOUBLE:
108cdf0e10cSrcweir return com::sun::star::sdbc::DataType::DOUBLE;
109cdf0e10cSrcweir
110cdf0e10cSrcweir case sql::DataType::DECIMAL:
111cdf0e10cSrcweir return com::sun::star::sdbc::DataType::DECIMAL;
112cdf0e10cSrcweir
113cdf0e10cSrcweir case sql::DataType::CHAR:
114cdf0e10cSrcweir return com::sun::star::sdbc::DataType::CHAR;
115cdf0e10cSrcweir
116cdf0e10cSrcweir case sql::DataType::BINARY:
117cdf0e10cSrcweir return com::sun::star::sdbc::DataType::BINARY;
118cdf0e10cSrcweir
119cdf0e10cSrcweir case sql::DataType::ENUM:
120cdf0e10cSrcweir case sql::DataType::SET:
121cdf0e10cSrcweir case sql::DataType::VARCHAR:
122cdf0e10cSrcweir return com::sun::star::sdbc::DataType::VARCHAR;
123cdf0e10cSrcweir
124cdf0e10cSrcweir case sql::DataType::VARBINARY:
125cdf0e10cSrcweir return com::sun::star::sdbc::DataType::VARBINARY;
126cdf0e10cSrcweir
127cdf0e10cSrcweir case sql::DataType::LONGVARCHAR:
128cdf0e10cSrcweir return com::sun::star::sdbc::DataType::LONGVARCHAR;
129cdf0e10cSrcweir
130cdf0e10cSrcweir case sql::DataType::LONGVARBINARY:
131cdf0e10cSrcweir return com::sun::star::sdbc::DataType::LONGVARBINARY;
132cdf0e10cSrcweir
133cdf0e10cSrcweir case sql::DataType::TIMESTAMP:
134cdf0e10cSrcweir return com::sun::star::sdbc::DataType::TIMESTAMP;
135cdf0e10cSrcweir
136cdf0e10cSrcweir case sql::DataType::DATE:
137cdf0e10cSrcweir return com::sun::star::sdbc::DataType::DATE;
138cdf0e10cSrcweir
139cdf0e10cSrcweir case sql::DataType::TIME:
140cdf0e10cSrcweir return com::sun::star::sdbc::DataType::TIME;
141cdf0e10cSrcweir
142cdf0e10cSrcweir case sql::DataType::GEOMETRY:
143cdf0e10cSrcweir return com::sun::star::sdbc::DataType::VARCHAR;
144cdf0e10cSrcweir
145cdf0e10cSrcweir case sql::DataType::SQLNULL:
146cdf0e10cSrcweir return com::sun::star::sdbc::DataType::SQLNULL;
147cdf0e10cSrcweir
148cdf0e10cSrcweir case sql::DataType::UNKNOWN:
149cdf0e10cSrcweir return com::sun::star::sdbc::DataType::VARCHAR;
150cdf0e10cSrcweir }
151cdf0e10cSrcweir
152cdf0e10cSrcweir OSL_ENSURE( false, "mysqlToOOOType: unhandled case, falling back to VARCHAR" );
153cdf0e10cSrcweir return com::sun::star::sdbc::DataType::VARCHAR;
154cdf0e10cSrcweir }
155cdf0e10cSrcweir
156cdf0e10cSrcweir
convert(const::ext_std::string & _string,const rtl_TextEncoding encoding)157cdf0e10cSrcweir ::rtl::OUString convert(const ::ext_std::string& _string, const rtl_TextEncoding encoding)
158cdf0e10cSrcweir {
159cdf0e10cSrcweir return ::rtl::OUString( _string.c_str(), _string.size(), encoding );
160cdf0e10cSrcweir }
161cdf0e10cSrcweir
convert(const::rtl::OUString & _string,const rtl_TextEncoding encoding)162cdf0e10cSrcweir ::ext_std::string convert(const ::rtl::OUString& _string, const rtl_TextEncoding encoding)
163cdf0e10cSrcweir {
164cdf0e10cSrcweir return ::ext_std::string( ::rtl::OUStringToOString( _string, encoding ).getStr() );
165cdf0e10cSrcweir }
166cdf0e10cSrcweir
167cdf0e10cSrcweir
168cdf0e10cSrcweir } /* namespace */
169