#include "qsql_sqliteex_p.h"
#include <qcoreapplication.h>
#include <qdatetime.h>
#include <qvariant.h>
#include <qsqlerror.h>
#include <qsqlfield.h>
#include <qsqlindex.h>
#include <qsqlquery.h>
#include <qstringlist.h>
#include <qvector.h>
#include <qdebug.h>
#ifndef QT_NO_REGULAREXPRESSION
#include <qcache.h>
#include <qregularexpression.h>
#endif
#include <QTimeZone>
#if defined Q_OS_WIN
# include <qt_windows.h>
#else
# include <unistd.h>
#endif
#include "sqlite3.h"
#include <functional>
#include <QtSql/private/qsqlcachedresult_p.h>
#include <QtSql/private/qsqldriver_p.h>
Q_DECLARE_OPAQUE_POINTER(sqlite3*)
Q_DECLARE_METATYPE(sqlite3*)
Q_DECLARE_OPAQUE_POINTER(sqlite3_stmt*)
Q_DECLARE_METATYPE(sqlite3_stmt*)
QT_BEGIN_NAMESPACE
static QString _q_escapeIdentifier(const QString &identifier)
{
QString res = identifier;
if (!identifier.isEmpty() && !identifier.startsWith(QLatin1Char('"')) && !identifier.endsWith(QLatin1Char('"'))) {
res.replace(QLatin1Char('"'), QLatin1String("\"\""));
res.prepend(QLatin1Char('"')).append(QLatin1Char('"'));
res.replace(QLatin1Char('.'), QLatin1String("\".\""));
}
return res;
}
static QVariant::Type qGetColumnType(const QString &tpName)
{
const QString typeName = tpName.toLower();
if (typeName == QLatin1String("integer")
|| typeName == QLatin1String("int"))
return QVariant::Int;
if (typeName == QLatin1String("double")
|| typeName == QLatin1String("float")
|| typeName == QLatin1String("real")
|| typeName.startsWith(QLatin1String("numeric")))
return QVariant::Double;
if (typeName == QLatin1String("blob"))
return QVariant::ByteArray;
if (typeName == QLatin1String("boolean")
|| typeName == QLatin1String("bool"))
return QVariant::Bool;
return QVariant::String;
}
static QSqlError qMakeError(sqlite3 *access, const QString &descr, QSqlError::ErrorType type,
int errorCode = -1)
{
return QSqlError(descr,
QString(reinterpret_cast<const QChar *>(sqlite3_errmsg16(access))),
type, QString::number(errorCode));
}
class QSQLiteExResultPrivate;
class QSQLiteExResult : public QSqlCachedResult
{
Q_DECLARE_PRIVATE(QSQLiteExResult)
friend class QSQLiteExDriver;
public:
explicit QSQLiteExResult(const QSQLiteExDriver* db);
~QSQLiteExResult();
QVariant handle() const Q_DECL_OVERRIDE;
protected:
bool gotoNext(QSqlCachedResult::ValueCache& row, int idx) Q_DECL_OVERRIDE;
bool reset(const QString &query) Q_DECL_OVERRIDE;
bool prepare(const QString &query) Q_DECL_OVERRIDE;
bool exec() Q_DECL_OVERRIDE;
int size() Q_DECL_OVERRIDE;
int numRowsAffected() Q_DECL_OVERRIDE;
QVariant lastInsertId() const Q_DECL_OVERRIDE;
QSqlRecord record() const Q_DECL_OVERRIDE;
void detachFromResultSet() Q_DECL_OVERRIDE;
void virtual_hook(int id, void *data) Q_DECL_OVERRIDE;
};
class QSQLiteExDriverPrivate : public QSqlDriverPrivate
{
Q_DECLARE_PUBLIC(QSQLiteExDriver)
public:
inline QSQLiteExDriverPrivate() : QSqlDriverPrivate(), access(0) { dbmsType = QSqlDriver::SQLite; }
sqlite3 *access;
QList <QSQLiteExResult *> results;
QStringList notificationid;
};
class QSQLiteExResultPrivate: public QSqlCachedResultPrivate
{
Q_DECLARE_PUBLIC(QSQLiteExResult)
public:
Q_DECLARE_SQLDRIVER_PRIVATE(QSQLiteExDriver)
QSQLiteExResultPrivate(QSQLiteExResult *q, const QSQLiteExDriver *drv);
void cleanup();
bool fetchNext(QSqlCachedResult::ValueCache &values, int idx, bool initialFetch);
// initializes the recordInfo and the cache
void initColumns(bool emptyResultset);
void finalize();
sqlite3_stmt *stmt;
bool skippedStatus; // the status of the fetchNext() that's skipped
bool skipRow; // skip the next fetchNext()?
QSqlRecord rInf;
QVector<QVariant> firstRow;
};
QSQLiteExResultPrivate::QSQLiteExResultPrivate(QSQLiteExResult *q, const QSQLiteExDriver *drv)
: QSqlCachedResultPrivate(q, drv),
stmt(0),
skippedStatus(false),
skipRow(false)
{
}
void QSQLiteExResultPrivate::cleanup()
{
Q_Q(QSQLiteExResult);
finalize();
rInf.clear();
skippedStatus = false;
skipRow = false;
q->setAt(QSql::BeforeFirstRow);
q->setActive(false);
q->cleanup();
}
void QSQLiteExResultPrivate::finalize()
{
if (!stmt)
return;
sqlite3_finalize(stmt);
stmt = 0;
}
void QSQLiteExResultPrivate::initColumns(bool emptyResultset)
{
Q_Q(QSQLiteExResult);
int nCols = sqlite3_column_count(stmt);
if (nCols <= 0)
return;
q->init(nCols);
for (int i = 0; i < nCols; ++i) {
QString colName = QString(reinterpret_cast<const QChar *>(
sqlite3_column_name16(stmt, i))
).remove(QLatin1Char('"'));
const QString tableName = QString(reinterpret_cast<const QChar *>(
sqlite3_column_table_name16(stmt, i))
).remove(QLatin1Char('"'));
// must use typeName for resolving the type to match QSqliteDriver::record
QString typeName = QString(reinterpret_cast<const QChar *>(
sqlite3_column_decltype16(stmt, i)));
// sqlite3_column_type is documented to have undefined behavior if the result set is empty
int stp = emptyResultset ? -1 : sqlite3_column_type(stmt, i);
QVariant::Type fieldType;
if (!typeName.isEmpty()) {
fieldType = qGetColumnType(typeName);
} else {
// Get the proper type for the field based on stp value
switch (stp) {
case SQLITE_INTEGER:
fieldType = QVariant::Int;
break;
case SQLITE_FLOAT:
fieldType = QVariant::Double;
break;
case SQLITE_BLOB:
fieldType = QVariant::ByteArray;
break;
case SQLITE_TEXT:
fieldType = QVariant::String;
break;
case SQLITE_NULL:
default:
fieldType = QVariant::Invalid;
break;
}
}
QSqlField fld(colName, fieldType, tableName);
fld.setSqlType(stp);
rInf.append(fld);
}
}
bool QSQLiteExResultPrivate::fetchNext(QSqlCachedResult::ValueCache &values, int idx, bool initialFetch)
{
Q_Q(QSQLiteExResult);
int res;
int i;
if (skipRow) {
// already fetched
Q_ASSERT(!initialFetch);
skipRow = false;
for(int i=0;i<firstRow.count();i++)
values[i]=firstRow[i];
return skippedStatus;
}
skipRow = initialFetch;
if(initialFetch) {
firstRow.clear();
firstRow.resize(sqlite3_column_count(stmt));
}
if (!stmt) {
q->setLastError(QSqlError(QCoreApplication::translate("QSQLiteResult", "Unable to fetch row"),
QCoreApplication::translate("QSQLiteResult", "No query"), QSqlError::ConnectionError));
q->setAt(QSql::AfterLastRow);
return false;
}
res = sqlite3_step(stmt);
switch(res) {
case SQLITE_ROW:
// check to see if should fill out columns
if (rInf.isEmpty())
// must be first call.
initColumns(false);
if (idx < 0 && !initialFetch)
return true;
for (i = 0; i < rInf.count(); ++i) {
switch (sqlite3_column_type(stmt, i)) {
case SQLITE_BLOB:
values[i + idx] = QByteArray(static_cast<const char *>(
sqlite3_column_blob(stmt, i)),
没有合适的资源?快使用搜索试试~ 我知道了~
QT sqlite加密数据库引擎
共217个文件
h:179个
o:9个
cpp:7个
5星 · 超过95%的资源 需积分: 50 98 下载量 42 浏览量
2018-09-26
15:08:38
上传
评论 2
收藏 2.6MB RAR 举报
温馨提示
QT自带的Sqlite引擎是不支持加密的,所以自己实现了能够加密的Sqlite引擎,继承QSqlDriver实现的,与其他数据库一样使用QSqlDatabase进行操作,与QT自带数据库操作保持一致。文件包含项目源码及测试代码。
资源推荐
资源详情
资源评论
收起资源包目录
QT sqlite加密数据库引擎 (217个子文件)
libSQLITEEXD.a 2KB
libSQLITEEX.a 2KB
qsql_sqliteex.cpp 32KB
moc_qsqliteexdriverplugin.cpp 6KB
moc_qsqliteexdriverplugin.cpp 6KB
moc_qsql_sqliteex_p.cpp 4KB
moc_qsql_sqliteex_p.cpp 4KB
main.cpp 1KB
qsqliteexdriverplugin.cpp 505B
Makefile.Debug 41KB
Makefile.Debug 37KB
SQLITEEXD.dll 1.7MB
SQLITEEXD.dll 1.7MB
sqlite3.dll 820KB
SQLITEEX.dll 74KB
SQLITEEX.dll 74KB
TestSqliteEx.exe 618KB
qlocale_data_p.h 941KB
sqlite3.h 363KB
qurltlds_p.h 191KB
qtimezoneprivate_data_p.h 98KB
cp949codetbl_p.h 72KB
qxmlstream_p.h 68KB
qjson_p.h 23KB
qsimd_p.h 19KB
qobject_p.h 19KB
qlocale_p.h 18KB
qtimezoneprivate_p.h 18KB
qvariant_p.h 15KB
qfilesystemmetadata_p.h 14KB
qstatemachine_p.h 14KB
qnumeric_p.h 14KB
qharfbuzz_p.h 13KB
qutfcodec_p.h 13KB
qprocess_p.h 12KB
qdatetimeparser_p.h 11KB
qjni_p.h 11KB
qmetaobjectbuilder_p.h 11KB
qcore_unix_p.h 11KB
qmetatype_p.h 11KB
qsettings_p.h 11KB
qfreelist_p.h 10KB
moc_predefs.h 10KB
moc_predefs.h 10KB
qeventdispatcher_cf_p.h 10KB
qmetaobject_p.h 9KB
qabstractanimation_p.h 9KB
qthread_p.h 9KB
qabstractfileengine_p.h 9KB
qfsfileengine_p.h 8KB
qmetaobject_moc_p.h 8KB
qstringiterator_p.h 8KB
qjpunicode_p.h 8KB
qiodevice_p.h 8KB
qfileinfo_p.h 8KB
qunicodetables_p.h 7KB
qmimeprovider_p.h 7KB
qbytedata_p.h 7KB
qfutureinterface_p.h 7KB
qnoncontiguousbytedevice_p.h 7KB
qfilesystemengine_p.h 7KB
qabstractitemmodel_p.h 7KB
qeventdispatcher_win_p.h 7KB
qsqltablemodel_p.h 6KB
qjnihelpers_p.h 6KB
qsqlquerymodel_p.h 6KB
qfilesystemwatcher_win_p.h 6KB
qtextstream_p.h 6KB
qmimeglobpattern_p.h 6KB
qglobal_p.h 6KB
qcore_mac_p.h 6KB
qcoreapplication_p.h 6KB
qfilesystemwatcher_fsevents_p.h 6KB
qeventdispatcher_unix_p.h 6KB
qdoublescanprint_p.h 6KB
qstringalgorithms_p.h 5KB
qthreadpool_p.h 5KB
qendian_p.h 5KB
qringbuffer_p.h 5KB
qmutex_p.h 5KB
qtemporaryfile_p.h 5KB
qsqlresult_p.h 5KB
qdatetime_p.h 5KB
qsharedmemory_p.h 5KB
qeuckrcodec_p.h 5KB
qsqlnulldriver_p.h 5KB
qwindowspipewriter_p.h 5KB
qppsobjectprivate_p.h 5KB
qloggingregistry_p.h 5KB
qresource_p.h 5KB
qitemselectionmodel_p.h 5KB
qlocale_tools_p.h 5KB
qfactoryloader_p.h 5KB
qeucjpcodec_p.h 5KB
qsjiscodec_p.h 5KB
qjiscodec_p.h 5KB
qppsobject_p.h 5KB
qfilesystementry_p.h 4KB
qmimemagicrule_p.h 4KB
qfunctions_fake_env_p.h 4KB
共 217 条
- 1
- 2
- 3
资源评论
- whatishacker2020-08-20新版本的Sqlite已经没有预留加密接口了。大家要用,要找老版本的sqlite才行。
十一夜飞天
- 粉丝: 3
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- wordpress主题博客网站:大前端D8 博客网站源码下载.rar
- WordPress主题程序响应式美女图片主题:CX-UDY爱美图吧.rar
- WordPress主题多功能新闻资讯自媒体个人博客商城主题模板LensNews v2.2版.rar
- WordPress论坛主题WP模板.rar
- wordpress主题风格时光轴型博客网站源码.rar
- WordPress自适应多功能免费图片主题CX-UDY模板.rar
- 仿北京时间Btime V.1.4.0新闻WordPress主题模板源码.rar
- wordpress女性资讯心怡网模板.rar
- Wordpress自适应轻社交SNS主题LightSNS-1.3正式版.rar
- 基于java的HTTP协议断点续传.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功