/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtSql module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qsql_mysql_p.h"
#include <qcoreapplication.h>
#include <qvariant.h>
#include <qdatetime.h>
#include <qsqlerror.h>
#include <qsqlfield.h>
#include <qsqlindex.h>
#include <qsqlquery.h>
#include <qsqlrecord.h>
#include <qstringlist.h>
#if QT_CONFIG(textcodec)
#include <qtextcodec.h>
#endif
#include <qvector.h>
#include <qfile.h>
#include <qdebug.h>
#include <QtSql/private/qsqldriver_p.h>
#include <QtSql/private/qsqlresult_p.h>
#ifdef Q_OS_WIN32
// comment the next line out if you want to use MySQL/embedded on Win32 systems.
// note that it will crash if you don't statically link to the mysql/e library!
# define Q_NO_MYSQL_EMBEDDED
#endif
Q_DECLARE_METATYPE(MYSQL_RES*)
Q_DECLARE_METATYPE(MYSQL*)
#if MYSQL_VERSION_ID >= 40108
Q_DECLARE_METATYPE(MYSQL_STMT*)
#endif
#if MYSQL_VERSION_ID >= 40100
# define Q_CLIENT_MULTI_STATEMENTS CLIENT_MULTI_STATEMENTS
#else
# define Q_CLIENT_MULTI_STATEMENTS 0
#endif
// MySQL above version 8 removed my_bool typedef while MariaDB kept it,
// by redefining it we can regain source compatibility.
using my_bool = decltype(mysql_stmt_bind_result(nullptr, nullptr));
QT_BEGIN_NAMESPACE
class QMYSQLDriverPrivate : public QSqlDriverPrivate
{
Q_DECLARE_PUBLIC(QMYSQLDriver)
public:
QMYSQLDriverPrivate() : QSqlDriverPrivate(), mysql(0),
#if QT_CONFIG(textcodec)
tc(QTextCodec::codecForLocale()),
#else
tc(0),
#endif
preparedQuerysEnabled(false) { dbmsType = QSqlDriver::MySqlServer; }
MYSQL *mysql;
QTextCodec *tc;
bool preparedQuerysEnabled;
};
static inline QString toUnicode(QTextCodec *tc, const char *str)
{
#if !QT_CONFIG(textcodec)
Q_UNUSED(tc);
return QString::fromLatin1(str);
#else
return tc->toUnicode(str);
#endif
}
static inline QString toUnicode(QTextCodec *tc, const char *str, int length)
{
#if !QT_CONFIG(textcodec)
Q_UNUSED(tc);
return QString::fromLatin1(str, length);
#else
return tc->toUnicode(str, length);
#endif
}
static inline QByteArray fromUnicode(QTextCodec *tc, const QString &str)
{
#if !QT_CONFIG(textcodec)
Q_UNUSED(tc);
return str.toLatin1();
#else
return tc->fromUnicode(str);
#endif
}
static inline QVariant qDateFromString(const QString &val)
{
#if !QT_CONFIG(datestring)
Q_UNUSED(val);
return QVariant(val);
#else
if (val.isEmpty())
return QVariant(QDate());
return QVariant(QDate::fromString(val, Qt::ISODate));
#endif
}
static inline QVariant qTimeFromString(const QString &val)
{
#if !QT_CONFIG(datestring)
Q_UNUSED(val);
return QVariant(val);
#else
if (val.isEmpty())
return QVariant(QTime());
return QVariant(QTime::fromString(val, Qt::ISODate));
#endif
}
static inline QVariant qDateTimeFromString(QString &val)
{
#if !QT_CONFIG(datestring)
Q_UNUSED(val);
return QVariant(val);
#else
if (val.isEmpty())
return QVariant(QDateTime());
if (val.length() == 14)
// TIMESTAMPS have the format yyyyMMddhhmmss
val.insert(4, QLatin1Char('-')).insert(7, QLatin1Char('-')).insert(10,
QLatin1Char('T')).insert(13, QLatin1Char(':')).insert(16, QLatin1Char(':'));
return QVariant(QDateTime::fromString(val, Qt::ISODate));
#endif
}
class QMYSQLResultPrivate;
class QMYSQLResult : public QSqlResult
{
Q_DECLARE_PRIVATE(QMYSQLResult)
friend class QMYSQLDriver;
public:
explicit QMYSQLResult(const QMYSQLDriver *db);
~QMYSQLResult();
QVariant handle() const override;
protected:
void cleanup();
bool fetch(int i) override;
bool fetchNext() override;
bool fetchLast() override;
bool fetchFirst() override;
QVariant data(int field) override;
bool isNull(int field) override;
bool reset (const QString& query) override;
int size() override;
int numRowsAffected() override;
QVariant lastInsertId() const override;
QSqlRecord record() const override;
void virtual_hook(int id, void *data) override;
bool nextResult() override;
void detachFromResultSet() override;
#if MYSQL_VERSION_ID >= 40108
bool prepare(const QString &stmt) override;
bool exec() override;
#endif
};
class QMYSQLResultPrivate: public QSqlResultPrivate
{
Q_DECLARE_PUBLIC(QMYSQLResult)
public:
Q_DECLARE_SQLDRIVER_PRIVATE(QMYSQLDriver)
QMYSQLResultPrivate(QMYSQLResult *q, const QMYSQLDriver *drv)
: QSqlResultPrivate(q, drv),
result(0),
rowsAffected(0),
hasBlobs(false)
#if MYSQL_VERSION_ID >= 40108
, stmt(0), meta(0), inBinds(0), outBinds(0)
#endif
, preparedQuery(false)
{ }
MYSQL_RES *result;
MYSQL_ROW row;
int rowsAffected;
bool bindInValues();
void bindBlobs();
bool hasBlobs;
struct QMyField
{
QMyField()
: outField(0), nullIndicator(false), bufLength(0ul),
myField(0), type(QVariant::Invalid)
{}
char *outField;
my_bool nullIndicator;
ulong bufLength;
MYSQL_FIELD *myField;
QVariant::Type type;
};
QVector<QMyField> fields;
#if MYSQL_VERSION_ID >= 40108
MYSQL_STMT* stmt;
MYSQL_RES* meta;
MYSQL_BIND *inBinds;
MYSQL_BIND *outBinds;
#endif
bool preparedQuery;
};
#if QT_CONFIG(textcodec)
static QTextCodec* codec(MYSQL* mysql)
{
#if MYSQL_VERSION_ID >= 32321
QTextCodec* heuristicCodec = QTextCodec::codecForName(mysql_character_set_name(mysql));
if (heuristicCodec)
return heuristicCodec;
#endif
return QTextCodec::codecForLocale();
}
#endif // textcodec
static QSqlError qMakeError(const QString& err, QSqlError::ErrorType type,
const QMYSQLDriverPrivate* p)
{
const char *cerr = p->mysql ? mysql_error(p->mysql) : 0;
return QSqlError(QLatin1String("QMYSQL: ") + err,
p->tc ? toUnicode(p->tc, cerr) : QString::fromLatin1(cerr),
type, QString::number(mysql_errno(p->mysql)));
}
static QVariant::Type qDecodeMYSQLType(int mysqltype, uint flags)
{
QVariant::Type type;
switch (mysqltype) {
case
没有合适的资源?快使用搜索试试~ 我知道了~
ubuntu20.04下编译mysql驱动项目源码
共9个文件
cpp:2个
user:1个
so:1个
需积分: 1 0 下载量 140 浏览量
2024-05-21
16:12:11
上传
评论
收藏 56KB ZIP 举报
温馨提示
ubuntu20.04下编译mysql驱动项目源码,编译项目驱动后拷贝到对应位置 scp libqsqlmysql.so /home/pc/Qt5.14.2/Tools/QtCreator/lib/Qt/plugins/sqldrivers scp libqsqlmysql.so /home/pc/Qt5.14.2/5.14.2/gcc_64/plugins/sqldrivers sudo scp libqsqlmysql.so /usr/lib/x86_64-linux-gnu
资源推荐
资源详情
资源评论
收起资源包目录
ubuntu2004+mysql.zip (9个子文件)
ubuntu2004+mysql
libqsqlmysql.so 110KB
mysql
mysql.pro.user.58aed08 22KB
README 204B
qsql_mysql.cpp 50KB
mysql.pro.user 22KB
main.cpp 3KB
mysql.pro 350B
mysql.json 40B
qsql_mysql_p.h 4KB
共 9 条
- 1
资源评论
疾风铸境
- 粉丝: 630
- 资源: 79
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- MSFRosslerAll (2).for
- vs2022安装包在线安装包
- Microsoft C++ 生成工具
- 74LS190实现10以内、100以内十进制加/减计数器-由multisim软件电路仿真设计
- 毕业项目:网上图书订阅管理系统的设计与开发(ASP.NET技术+程序源代码+毕业文档)
- zjk-1.ipynb
- Delphi 12 控件之EhLib.v10.2.42 for Delphi 5-12.src.rar
- cloudreve3.8.3的docker镜像
- RB108A-SOT23-5封装 单节锂电池保护IC 深圳市可芯电子有限公司.pdf
- Apache Maven的安装与配置.pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功