22#include <rtl/ustring.hxx>
25#include <com/sun/star/sdbc/DataType.hpp>
27using com::sun::star::sdbc::SQLException;
29using com::sun::star::uno::Any;
31using com::sun::star::uno::XInterface;
43 case MYSQL_TYPE_INT24:
44 *mem = malloc(
sizeof(sal_Int32));
46 case MYSQL_TYPE_SHORT:
48 *mem = malloc(
sizeof(sal_Int16));
54 case MYSQL_TYPE_LONGLONG:
55 *mem = malloc(
sizeof(sal_Int64));
57 case MYSQL_TYPE_FLOAT:
58 *mem = malloc(
sizeof(
float));
60 case MYSQL_TYPE_DOUBLE:
61 *mem = malloc(
sizeof(
double));
65 case MYSQL_TYPE_DATETIME:
66 case MYSQL_TYPE_TIMESTAMP:
67 case MYSQL_TYPE_NEWDATE:
70 case MYSQL_TYPE_GEOMETRY:
71 *mem = malloc(
sizeof(MYSQL_TIME));
73 case MYSQL_TYPE_STRING:
74 case MYSQL_TYPE_VAR_STRING:
75 case MYSQL_TYPE_VARCHAR:
76 case MYSQL_TYPE_DECIMAL:
77 case MYSQL_TYPE_NEWDECIMAL:
78 *mem = malloc(
sizeof(
char) * nSize);
82 case MYSQL_TYPE_TINY_BLOB:
83 case MYSQL_TYPE_MEDIUM_BLOB:
84 case MYSQL_TYPE_LONG_BLOB:
88 SAL_WARN(
"connectivity.mysqlc",
"unknown enum_field_type");
93 const css::uno::Reference<XInterface>& _rxContext)
96 = OUString::createFromAscii(_pAsciiFeatureName) +
": feature not implemented.";
97 throw SQLException(
sMessage, _rxContext,
"HYC00", 0,
Any());
101 const css::uno::Reference<XInterface>& _rxContext)
104 = OUString::createFromAscii(_pAsciiFeatureName) +
": invalid arguments.";
105 throw SQLException(
sMessage, _rxContext,
"HYC00", 0,
Any());
109 const css::uno::Reference<css::uno::XInterface>& _context,
110 const rtl_TextEncoding encoding)
112 OString errorMsg{ msg };
117 const css::uno::Reference<css::uno::XInterface>& _context)
119 throw SQLException(msg, _context, OStringToOUString(SQLSTATE, RTL_TEXTENCODING_ASCII_US),
129 return css::sdbc::DataType::BIT;
131 case MYSQL_TYPE_TINY:
132 return css::sdbc::DataType::TINYINT;
134 case MYSQL_TYPE_SHORT:
135 case MYSQL_TYPE_YEAR:
136 return css::sdbc::DataType::SMALLINT;
138 case MYSQL_TYPE_INT24:
139 case MYSQL_TYPE_LONG:
140 return css::sdbc::DataType::INTEGER;
142 case MYSQL_TYPE_LONGLONG:
143 return css::sdbc::DataType::BIGINT;
145 case MYSQL_TYPE_FLOAT:
146 return css::sdbc::DataType::REAL;
148 case MYSQL_TYPE_DOUBLE:
149 return css::sdbc::DataType::DOUBLE;
151 case MYSQL_TYPE_DECIMAL:
152 case MYSQL_TYPE_NEWDECIMAL:
153 return css::sdbc::DataType::DECIMAL;
155 case MYSQL_TYPE_STRING:
157 return css::sdbc::DataType::BINARY;
158 return css::sdbc::DataType::CHAR;
160 case MYSQL_TYPE_ENUM:
162 case MYSQL_TYPE_VAR_STRING:
164 return css::sdbc::DataType::VARBINARY;
165 return css::sdbc::DataType::VARCHAR;
167 case MYSQL_TYPE_BLOB:
168 case MYSQL_TYPE_TINY_BLOB:
169 case MYSQL_TYPE_MEDIUM_BLOB:
170 case MYSQL_TYPE_LONG_BLOB:
172 return css::sdbc::DataType::LONGVARBINARY;
173 return css::sdbc::DataType::LONGVARCHAR;
175 case MYSQL_TYPE_TIMESTAMP:
176 case MYSQL_TYPE_DATETIME:
177 return css::sdbc::DataType::TIMESTAMP;
179 case MYSQL_TYPE_DATE:
180 return css::sdbc::DataType::DATE;
182 case MYSQL_TYPE_TIME:
183 return css::sdbc::DataType::TIME;
185 case MYSQL_TYPE_GEOMETRY:
186 return css::sdbc::DataType::VARCHAR;
188 case MYSQL_TYPE_NULL:
189 return css::sdbc::DataType::SQLNULL;
192 OSL_FAIL(
"mysqlToOOOType: unhandled case, falling back to VARCHAR");
193 return css::sdbc::DataType::VARCHAR;
201 return css::sdbc::DataType::TINYINT;
204 return css::sdbc::DataType::SMALLINT;
207 return css::sdbc::DataType::INTEGER;
210 return css::sdbc::DataType::VARCHAR;
212 return css::sdbc::DataType::BIGINT;
217 return css::sdbc::DataType::BLOB;
219 return css::sdbc::DataType::VARBINARY;
221 return css::sdbc::DataType::CHAR;
223 return css::sdbc::DataType::VARCHAR;
225 return css::sdbc::DataType::LONGVARCHAR;
228 return css::sdbc::DataType::CLOB;
230 return css::sdbc::DataType::BINARY;
232 return css::sdbc::DataType::TIME;
234 return css::sdbc::DataType::DATE;
237 return css::sdbc::DataType::TIMESTAMP;
239 return css::sdbc::DataType::DECIMAL;
241 return css::sdbc::DataType::REAL;
243 return css::sdbc::DataType::DOUBLE;
245 return css::sdbc::DataType::BIT;
248 return css::sdbc::DataType::BOOLEAN;
249 OSL_FAIL(
"Unknown type name from string, failing back to varchar.");
250 return css::sdbc::DataType::VARCHAR;
255 bool isUnsigned = (flags & UNSIGNED_FLAG) != 0;
256 bool isZerofill = (flags & ZEROFILL_FLAG) != 0;
260 return OUString{
"BIT" };
261 case MYSQL_TYPE_DECIMAL:
262 case MYSQL_TYPE_NEWDECIMAL:
263 return isUnsigned ? (isZerofill ? OUString{
"DECIMAL UNSIGNED ZEROFILL" }
264 : OUString{
"DECIMAL UNSIGNED" })
265 : OUString{
"DECIMAL" };
266 case MYSQL_TYPE_TINY:
267 return isUnsigned ? (isZerofill ? OUString{
"TINYINT UNSIGNED ZEROFILL" }
268 : OUString{
"TINYINT UNSIGNED" })
269 : OUString{
"TINYINT" };
270 case MYSQL_TYPE_SHORT:
271 return isUnsigned ? (isZerofill ? OUString{
"SMALLINT UNSIGNED ZEROFILL" }
272 : OUString{
"SMALLINT UNSIGNED" })
273 : OUString{
"SMALLINT" };
274 case MYSQL_TYPE_LONG:
275 return isUnsigned ? (isZerofill ? OUString{
"INT UNSIGNED ZEROFILL" }
276 : OUString{
"INT UNSIGNED" })
278 case MYSQL_TYPE_FLOAT:
279 return isUnsigned ? (isZerofill ? OUString{
"FLOAT UNSIGNED ZEROFILL" }
280 : OUString{
"FLOAT UNSIGNED" })
281 : OUString{
"FLOAT" };
282 case MYSQL_TYPE_DOUBLE:
283 return isUnsigned ? (isZerofill ? OUString{
"DOUBLE UNSIGNED ZEROFILL" }
284 : OUString{
"DOUBLE UNSIGNED" })
285 : OUString{
"DOUBLE" };
286 case MYSQL_TYPE_NULL:
287 return OUString{
"NULL" };
288 case MYSQL_TYPE_TIMESTAMP:
289 return OUString{
"TIMESTAMP" };
290 case MYSQL_TYPE_LONGLONG:
291 return isUnsigned ? (isZerofill ? OUString{
"BIGINT UNSIGNED ZEROFILL" }
292 : OUString{
"BIGINT UNSIGNED" })
293 : OUString{
"BIGINT" };
294 case MYSQL_TYPE_INT24:
295 return isUnsigned ? (isZerofill ? OUString{
"MEDIUMINT UNSIGNED ZEROFILL" }
296 : OUString{
"MEDIUMINT UNSIGNED" })
297 : OUString{
"MEDIUMINT" };
298 case MYSQL_TYPE_DATE:
299 return OUString{
"DATE" };
300 case MYSQL_TYPE_TIME:
301 return OUString{
"TIME" };
302 case MYSQL_TYPE_DATETIME:
303 return OUString{
"DATETIME" };
304 case MYSQL_TYPE_TINY_BLOB:
306 return OUString{
"TINYBLOB" };
308 case MYSQL_TYPE_MEDIUM_BLOB:
310 return OUString{
"MEDIUMBLOB" };
312 case MYSQL_TYPE_LONG_BLOB:
314 return OUString{
"LONGBLOB" };
316 case MYSQL_TYPE_BLOB:
318 return OUString{
"BLOB" };
320 case MYSQL_TYPE_VARCHAR:
321 case MYSQL_TYPE_VAR_STRING:
322 if (flags & ENUM_FLAG)
324 return OUString{
"ENUM" };
326 if (flags & SET_FLAG)
328 return OUString{
"SET" };
330 return OUString{
"VARCHAR" };
331 case MYSQL_TYPE_STRING:
332 if (flags & ENUM_FLAG)
334 return OUString{
"ENUM" };
336 if (flags & SET_FLAG)
338 return OUString{
"SET" };
340 return OUString{
"CHAR" };
341 case MYSQL_TYPE_YEAR:
342 return OUString{
"YEAR" };
343 case MYSQL_TYPE_GEOMETRY:
344 return OUString{
"GEOMETRY" };
346 return OUString{
"UNKNOWN" };
350OUString
convert(const ::std::string& _string,
const rtl_TextEncoding encoding)
352 return OUString(_string.c_str(), _string.size(), encoding);
#define SAL_WARN(area, stream)
OUString convert(const ::std::string &_string, const rtl_TextEncoding encoding)
sal_Int32 mysqlStrToOOOType(std::u16string_view sType)
void throwInvalidArgumentException(const char *_pAsciiFeatureName, const css::uno::Reference< XInterface > &_rxContext)
void allocateSqlVar(void **mem, enum_field_types eType, unsigned nSize)
sal_Int32 mysqlToOOOType(int eType, int charsetnr) noexcept
void throwSQLExceptionWithMsg(const char *msg, const char *SQLSTATE, unsigned int errorNum, const css::uno::Reference< css::uno::XInterface > &_context, const rtl_TextEncoding encoding)
OUString mysqlTypeToStr(unsigned type, unsigned flags)
void throwFeatureNotImplementedException(const char *_pAsciiFeatureName, const css::uno::Reference< XInterface > &_rxContext)
bool equalsIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2)