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 .
19 #include "mysqlc_general.hxx"
20 #include "mysqlc_resultsetmetadata.hxx"
22 #include <cppconn/exception.h>
23 #include <cppconn/datatype.h>
25 using com::sun::star::sdbc::SQLException
;
27 using com::sun::star::uno::UNO_QUERY
;
28 using com::sun::star::uno::Reference
;
29 using com::sun::star::uno::XInterface
;
30 using com::sun::star::uno::Any
;
32 namespace mysqlc_sdbc_driver
35 void throwFeatureNotImplementedException( const sal_Char
* _pAsciiFeatureName
, const Reference
< XInterface
>& _rxContext
, const Any
* _pNextException
)
38 const rtl::OUString sMessage
= rtl::OUString::createFromAscii( _pAsciiFeatureName
) + ": feature not implemented.";
42 rtl::OUString("HYC00"),
44 _pNextException
? *_pNextException
: Any()
48 void throwInvalidArgumentException( const sal_Char
* _pAsciiFeatureName
, const Reference
< XInterface
>& _rxContext
, const Any
* _pNextException
)
51 const rtl::OUString sMessage
= rtl::OUString::createFromAscii( _pAsciiFeatureName
) + ": invalid arguments.";
55 rtl::OUString("HYC00"),
57 _pNextException
? *_pNextException
: Any()
61 void translateAndThrow(const ::sql::SQLException
& _error
, const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _context
, const rtl_TextEncoding encoding
)
64 convert(_error
.what(), encoding
),
66 convert(_error
.getSQLState(), encoding
),
67 _error
.getErrorCode(),
72 rtl::OUString
getStringFromAny(const Any
& _rAny
)
74 rtl::OUString nReturn
;
75 OSL_VERIFY( _rAny
>>= nReturn
);
79 int mysqlToOOOType(int cppConnType
)
82 switch (cppConnType
) {
83 case sql::DataType::BIT
:
84 return com::sun::star::sdbc::DataType::VARCHAR
;
86 case sql::DataType::TINYINT
:
87 return com::sun::star::sdbc::DataType::TINYINT
;
89 case sql::DataType::SMALLINT
:
90 return com::sun::star::sdbc::DataType::SMALLINT
;
92 case sql::DataType::INTEGER
:
93 return com::sun::star::sdbc::DataType::INTEGER
;
95 case sql::DataType::BIGINT
:
96 return com::sun::star::sdbc::DataType::BIGINT
;
98 case sql::DataType::REAL
:
99 return com::sun::star::sdbc::DataType::REAL
;
101 case sql::DataType::DOUBLE
:
102 return com::sun::star::sdbc::DataType::DOUBLE
;
104 case sql::DataType::DECIMAL
:
105 return com::sun::star::sdbc::DataType::DECIMAL
;
107 case sql::DataType::CHAR
:
108 return com::sun::star::sdbc::DataType::CHAR
;
110 case sql::DataType::BINARY
:
111 return com::sun::star::sdbc::DataType::BINARY
;
113 case sql::DataType::ENUM
:
114 case sql::DataType::SET
:
115 case sql::DataType::VARCHAR
:
116 return com::sun::star::sdbc::DataType::VARCHAR
;
118 case sql::DataType::VARBINARY
:
119 return com::sun::star::sdbc::DataType::VARBINARY
;
121 case sql::DataType::LONGVARCHAR
:
122 return com::sun::star::sdbc::DataType::LONGVARCHAR
;
124 case sql::DataType::LONGVARBINARY
:
125 return com::sun::star::sdbc::DataType::LONGVARBINARY
;
127 case sql::DataType::TIMESTAMP
:
128 return com::sun::star::sdbc::DataType::TIMESTAMP
;
130 case sql::DataType::DATE
:
131 return com::sun::star::sdbc::DataType::DATE
;
133 case sql::DataType::TIME
:
134 return com::sun::star::sdbc::DataType::TIME
;
136 case sql::DataType::GEOMETRY
:
137 return com::sun::star::sdbc::DataType::VARCHAR
;
139 case sql::DataType::SQLNULL
:
140 return com::sun::star::sdbc::DataType::SQLNULL
;
142 case sql::DataType::UNKNOWN
:
143 return com::sun::star::sdbc::DataType::VARCHAR
;
146 OSL_FAIL( "mysqlToOOOType: unhandled case, falling back to VARCHAR" );
147 return com::sun::star::sdbc::DataType::VARCHAR
;
150 rtl::OUString
convert(const ::std::string
& _string
, const rtl_TextEncoding encoding
)
152 return rtl::OUString( _string
.c_str(), _string
.size(), encoding
);
155 ::std::string
convert(const rtl::OUString
& _string
, const rtl_TextEncoding encoding
)
157 return ::std::string( rtl::OUStringToOString( _string
, encoding
).getStr() );
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */