LibreOffice Module connectivity (master) 1
mysqlc_general.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#pragma once
21
22#include <config_lgpl.h>
23
24#include <com/sun/star/uno/XInterface.hpp>
25#include <com/sun/star/sdbc/SQLException.hpp>
26
27#include <osl/diagnose.h>
28#include <mysql.h>
29
30#if defined __GNUC__
31#pragma GCC diagnostic push
32#pragma GCC diagnostic ignored "-Wdeprecated"
33#endif
34
35#if defined __GNUC__
36#pragma GCC diagnostic pop
37#endif
38
39namespace mysqlc_sdbc_driver
40{
41template <typename T>
42void resetSqlVar(void** target, T* pValue, enum_field_types type, sal_Int32 nSize = 0)
43{
44 if (*target)
45 {
46 free(*target);
47 *target = nullptr;
48 }
49 constexpr auto nUnitSize = sizeof(T);
50 switch (type)
51 {
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");
89 }
90}
91
92void allocateSqlVar(void** mem, enum_field_types eType, unsigned nSize = 0);
93
95 const char* _pAsciiFeatureName, const css::uno::Reference<css::uno::XInterface>& _rxContext);
96
97void throwInvalidArgumentException(const char* _pAsciiFeatureName,
98 const css::uno::Reference<css::uno::XInterface>& _rxContext);
99
100void throwSQLExceptionWithMsg(const char* msg, const char* SQLSTATE, unsigned int errorNum,
101 const css::uno::Reference<css::uno::XInterface>& _context,
102 const rtl_TextEncoding encoding);
103
104void throwSQLExceptionWithMsg(const OUString& msg, const char* SQLSTATE, unsigned int errorNum,
105 const css::uno::Reference<css::uno::XInterface>& _context);
106
107sal_Int32 mysqlToOOOType(int eType, int charsetnr) noexcept;
108
109OUString mysqlTypeToStr(unsigned mysql_type, unsigned mysql_flags);
110
111sal_Int32 mysqlStrToOOOType(std::u16string_view sType);
112
113OUString convert(const ::std::string& _string, const rtl_TextEncoding encoding);
114}
115
116/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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)
void resetSqlVar(void **target, T *pValue, enum_field_types type, sal_Int32 nSize=0)
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)
sal_Int32 type
Definition: pq_statics.cxx:60