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
34 // -----------------------------------------------------------------------------
35 void throwFeatureNotImplementedException( const sal_Char
* _pAsciiFeatureName
, const Reference
< XInterface
>& _rxContext
, const Any
* _pNextException
)
38 const OUString sMessage
= OUString::createFromAscii( _pAsciiFeatureName
) + OUString( ": feature not implemented." );
44 _pNextException
? *_pNextException
: Any()
49 void throwInvalidArgumentException( const sal_Char
* _pAsciiFeatureName
, const Reference
< XInterface
>& _rxContext
, const Any
* _pNextException
)
52 const OUString sMessage
= OUString::createFromAscii( _pAsciiFeatureName
) + OUString( ": invalid arguments." );
58 _pNextException
? *_pNextException
: Any()
62 void translateAndThrow(const ::sql::SQLException
& _error
, const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _context
, const rtl_TextEncoding encoding
)
65 convert(_error
.what(), encoding
),
67 convert(_error
.getSQLState(), encoding
),
68 _error
.getErrorCode(),
74 OUString
getStringFromAny(const Any
& _rAny
)
77 OSL_VERIFY( _rAny
>>= nReturn
);
82 int mysqlToOOOType(int cppConnType
)
85 switch (cppConnType
) {
86 case sql::DataType::BIT
:
87 return com::sun::star::sdbc::DataType::VARCHAR
;
89 case sql::DataType::TINYINT
:
90 return com::sun::star::sdbc::DataType::TINYINT
;
92 case sql::DataType::SMALLINT
:
93 return com::sun::star::sdbc::DataType::SMALLINT
;
95 case sql::DataType::INTEGER
:
96 return com::sun::star::sdbc::DataType::INTEGER
;
98 case sql::DataType::BIGINT
:
99 return com::sun::star::sdbc::DataType::BIGINT
;
101 case sql::DataType::REAL
:
102 return com::sun::star::sdbc::DataType::REAL
;
104 case sql::DataType::DOUBLE
:
105 return com::sun::star::sdbc::DataType::DOUBLE
;
107 case sql::DataType::DECIMAL
:
108 return com::sun::star::sdbc::DataType::DECIMAL
;
110 case sql::DataType::CHAR
:
111 return com::sun::star::sdbc::DataType::CHAR
;
113 case sql::DataType::BINARY
:
114 return com::sun::star::sdbc::DataType::BINARY
;
116 case sql::DataType::ENUM
:
117 case sql::DataType::SET
:
118 case sql::DataType::VARCHAR
:
119 return com::sun::star::sdbc::DataType::VARCHAR
;
121 case sql::DataType::VARBINARY
:
122 return com::sun::star::sdbc::DataType::VARBINARY
;
124 case sql::DataType::LONGVARCHAR
:
125 return com::sun::star::sdbc::DataType::LONGVARCHAR
;
127 case sql::DataType::LONGVARBINARY
:
128 return com::sun::star::sdbc::DataType::LONGVARBINARY
;
130 case sql::DataType::TIMESTAMP
:
131 return com::sun::star::sdbc::DataType::TIMESTAMP
;
133 case sql::DataType::DATE
:
134 return com::sun::star::sdbc::DataType::DATE
;
136 case sql::DataType::TIME
:
137 return com::sun::star::sdbc::DataType::TIME
;
139 case sql::DataType::GEOMETRY
:
140 return com::sun::star::sdbc::DataType::VARCHAR
;
142 case sql::DataType::SQLNULL
:
143 return com::sun::star::sdbc::DataType::SQLNULL
;
145 case sql::DataType::UNKNOWN
:
146 return com::sun::star::sdbc::DataType::VARCHAR
;
149 OSL_FAIL( "mysqlToOOOType: unhandled case, falling back to VARCHAR" );
150 return com::sun::star::sdbc::DataType::VARCHAR
;
154 OUString
convert(const ::std::string
& _string
, const rtl_TextEncoding encoding
)
156 return OUString( _string
.c_str(), _string
.size(), encoding
);
159 ::std::string
convert(const OUString
& _string
, const rtl_TextEncoding encoding
)
161 return ::std::string( OUStringToOString( _string
, encoding
).getStr() );
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */