>
< div> But when I compile to the last step, the error message’sqlite3_key’ was not declared in this scope appears. I don’t know why, but this error only appears. The sqlite3.h file has also been introduced. Why is it still wrong? Today I calm down and read the sqlite3_key function of the sqlite3.h file, and found that there is a sentence on it
Recently, due to work reasons, I need to use the sqlite database. The sqlite database is small and easy to use, which feels pretty good. But there is a shortcoming that the database is not encrypted, but the good thing is that sqlite reserves an encrypted interface, we can call it directly. I also refer to the information on the Internet to encrypt the database:
The SQLite database has no encryption function by default, which is inconvenient for some occasions that need to keep the project files confidential. This article takes QT4.4.3 as an example.
>
Modify the sql module in the qt source code and add an encryption function to the qt integrated sqlite database.
1. Compile the files in the /wxsqlite3_prj/sqlite3 directory to generate sqlite3.lib< /p>
2 Copy sqlite3.h and sqlite3.lib generated in the previous step to the directory?:\Qt\4.4.3\src\plugins\sqldrivers\sqlite.
3 ?:\Qt\4.4.3\src\plugins\sqldrivers\sqlite The sqlite.pro file in the directory is modified to:
TARGET = qsqlite
# Do not use the built-in qt sqilte source code file, but use an externally generated library
win32:LIBS += sqlite3.lib
#
HEADERS = ../../. ./sql/drivers/sqlite/qsql_sqlite.h
SOURCES = smain.cpp \
../../../sql/drivers/sqlite/qsql_sqlite.cpp< /p>
!system-sqlite:!contains( LIBS, .*sqlite.*) {
CONFIG(release, debug|release):DEFINES *= NDEBUG
DEFINES += SQLITE_CORE SQLITE_OMIT_LOAD_EXTENSION SQLITE_OMIT_COMPLETE
# INCLUDEPATH += ../../../3rdparty/sqlite
# SOURCES += ../../../3rdparty /sqlite/sqlite3.c
} else {
LIBS *= $$QT_LFLAGS_SQLITE
QMAKE_CXXFLAGS *= $$QT_CFLAGS_SQLITE
}
include(../qsqldrive rbase.pri)
4 Modify?: The file qsql_sqlite.cpp in the \Qt\4.4.3\src\sql\drivers\sqlite directory
The function to be modified bool QSQLiteDriver: :open(), modify the function body to:
bool QSQLiteDriver::open(const QString & db, const QString &, const QString &, const QString &, int, const QString &conOpts)
{
if (isOpen())
close();
if (db.isEmpty())
return false;
if (sqlite3_open16(db.constData(), &d->access) == SQLITE_OK) {
sqlite3_busy_timeout(d->access, qGetSqliteTimeout(conOpts));
setOpen(true);
setOpenError(false);
//Add encryption function “Trucc” is the encryption key, 5 is the key length< /p>
sqlite3_key( d->access, “Trucc”, 5);
return true;
} else {
setLastError(qMakeError (d->access, tr(“Error opening database”),
QSqlError::ConnectionError));
setOpenError(true);
return false ;
}
}
5 Compile?:\Qt\4.4.3\src\plugins\sqldrivers\sqlite The project under the directory?: \Qt\4.4.3\plugins\sqldrivers generates sqlite with encryption function
corresponding library files.
Excerpt from: http://apps.hi.baidu.com/share /detail/21604459
Can be When I compile to the last step, the error message’sqlite3_key’ was not declared in this scope appeared. I don’t know why, but this error only appears. The sqlite3.h file has also been introduced, but why is it still wrong? Woolen cloth? I calm down today and read the sqlite3_key function of the sqlite3.h file, and found that there is a sentence on it
#ifdef SQLITE_HAS_CODEC
I suddenly thought about what this sentence means Isn’t it that the sqlite3_key function can only be used if SQLITE_HAS_CODEC is defined. In this case, we only need to define it in the document that raised the error. In this way, I will appear in the header of the qsql_sqlite.cpp file where the sqlite3_key function cannot be found, add:
#if defined SQLITE_HAS_CODEC
Add at the end of the file:
#endif
Re-compile, and compile passes.
It seems that if you encounter problems, you still have to stop. Slowly and carefully analyze, I believe that the problem can always be solved.
WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 888 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC