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