bump product version to 7.2.5.1
[LibreOffice.git] / connectivity / source / drivers / mysqlc / mysqlc_general.hxx
blob2a78c76288793a236efc54f6060ab5b1c99afe9d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #pragma once
22 #include <config_lgpl.h>
24 #include <com/sun/star/uno/XInterface.hpp>
25 #include <com/sun/star/sdbc/SQLException.hpp>
27 #include <osl/diagnose.h>
28 #include <mysql.h>
30 #if defined __GNUC__
31 #pragma GCC diagnostic push
32 #pragma GCC diagnostic ignored "-Wdeprecated"
33 #endif
35 #if defined __GNUC__
36 #pragma GCC diagnostic pop
37 #endif
39 namespace mysqlc_sdbc_driver
41 template <typename T>
42 void resetSqlVar(void** target, T* pValue, enum_field_types type, sal_Int32 nSize = 0)
44 if (*target)
46 free(*target);
47 *target = nullptr;
49 constexpr auto nUnitSize = sizeof(T);
50 switch (type)
52 case MYSQL_TYPE_INT24:
53 case MYSQL_TYPE_YEAR:
54 case MYSQL_TYPE_NEWDATE:
55 case MYSQL_TYPE_BIT:
56 case MYSQL_TYPE_GEOMETRY:
57 case MYSQL_TYPE_LONG:
58 case MYSQL_TYPE_SHORT:
59 case MYSQL_TYPE_TINY:
60 case MYSQL_TYPE_LONGLONG:
61 case MYSQL_TYPE_FLOAT:
62 case MYSQL_TYPE_DOUBLE:
63 case MYSQL_TYPE_TIME:
64 case MYSQL_TYPE_DATE:
65 case MYSQL_TYPE_DATETIME:
66 case MYSQL_TYPE_TIMESTAMP:
67 *target = malloc(nUnitSize);
68 memcpy(*target, pValue, nUnitSize);
69 break;
70 case MYSQL_TYPE_STRING:
71 case MYSQL_TYPE_BLOB:
72 case MYSQL_TYPE_DECIMAL:
73 case MYSQL_TYPE_VARCHAR:
74 case MYSQL_TYPE_NEWDECIMAL:
75 case MYSQL_TYPE_ENUM:
76 case MYSQL_TYPE_SET:
77 case MYSQL_TYPE_VAR_STRING:
78 case MYSQL_TYPE_TINY_BLOB:
79 case MYSQL_TYPE_MEDIUM_BLOB:
80 case MYSQL_TYPE_LONG_BLOB:
81 *target = malloc(nUnitSize * nSize);
82 memcpy(*target, pValue, nUnitSize * nSize);
83 break;
84 case MYSQL_TYPE_NULL:
85 // nothing I guess
86 break;
87 default:
88 OSL_FAIL("resetSqlVar: unknown enum_field_type");
92 void allocateSqlVar(void** mem, enum_field_types eType, unsigned nSize = 0);
94 void throwFeatureNotImplementedException(
95 const char* _pAsciiFeatureName, const css::uno::Reference<css::uno::XInterface>& _rxContext);
97 void throwInvalidArgumentException(const char* _pAsciiFeatureName,
98 const css::uno::Reference<css::uno::XInterface>& _rxContext);
100 void throwSQLExceptionWithMsg(const char* msg, const char* SQLSTATE, unsigned int errorNum,
101 const css::uno::Reference<css::uno::XInterface>& _context,
102 const rtl_TextEncoding encoding);
104 void throwSQLExceptionWithMsg(const OUString& msg, const char* SQLSTATE, unsigned int errorNum,
105 const css::uno::Reference<css::uno::XInterface>& _context);
107 sal_Int32 mysqlToOOOType(int eType, int charsetnr) noexcept;
109 OUString mysqlTypeToStr(unsigned mysql_type, unsigned mysql_flags);
111 sal_Int32 mysqlStrToOOOType(const OUString& sType);
113 OUString convert(const ::std::string& _string, const rtl_TextEncoding encoding);
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */