c++如何激活sqlite3的用户认证逻辑 [英] How to activate the user authentication logic of sqlite3 in c++
问题描述
我正在尝试在我的 C++ 项目中使用 sqlite3 上的用户身份验证.我已按照 here 中说明的步骤进行操作.我已将 sqlite3userauth.h
添加到 sqlite3.h
的末尾并将 userauth.c
添加到 sqlite3.c的末尾code> 并在我的代码中包含
#include "sqlite3.h"
.但是现在我的代码无法识别任何新函数,例如 sqlite3_user_add
.此外,我尝试使用以下命令编译 shell.c
gcc -o sqlite3Exe shell.c sqlite3.c -DSQLITE_USER_AUTHENTICATION -ldl -lpthread
但我收到此错误:
sqlite3.c:230543:11:致命错误:sqliteInt.h:没有那个文件或目录 # 包含sqliteInt.h";编译终止.
我试图评论该行,但后来又出现了另一个错误:
<块引用>sqlite3.c:230730:3:错误:无法运行的参数太少'sqlite3ExpirePreparedStatements'
sqlite3ExpirePreparedStatements(db);
该行指的是:
sqlite3ExpirePreparedStatements(db);
我没有对主要代码做任何更改,并按照官网提供的提示进行操作,但似乎不起作用.你能指导我完成这个吗?我正在使用 QT 并尝试创建受密码保护的数据库接口.
这是我的代码的一些部分:
project.pro(我以这种方式添加了
sqlite3
和编译器标志):来源 +=
sqlite/sqlite3.c
...标题 +=
sqlite/sqlite3.h
...QMAKE_CXXFLAGS += -DSQLITE_USER_AUTHENTICATION -ldl -lpthread
这是我的 sqlite3.h
文件的一部分(它显示了我在哪里添加了 sqlite3userauth.h
的代码):
<代码>...#ifdef __cplusplus}/* 'extern C"' 的结尾堵塞 */#万一#endif/* _FTS5_H *//******** fts5.h 结束 *********//*** 2014-09-08**** 作者不拥有此源代码的版权.代替** 法律声明,祝福:**** 愿你行善不作恶.** 愿你为自己找到宽恕并宽恕他人.** 愿你自由分享,永不索取.********************************************************************************...
这是我的 sqlite3.c
文件的一部分(这显示了我在哪里添加了 userauth.c
的代码):
<代码>...#if __LINE__!=230511#undef SQLITE_SOURCE_ID#define SQLITE_SOURCE_ID "2020-08-14 13:23:32 fca8dc8b578f215a969cd899336378966156154710873e68b3d9ac5881b0alt2"#万一/* 返回此库的源 ID */SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID;}/**************************** sqlite3.c 结束 ******************************//*** 2014-09-08**** 作者不拥有此源代码的版权.代替** 法律通知,祝福:**** 愿你行善不作恶.** 愿你为自己找到宽恕并宽恕他人.** 愿你自由分享,永不索取.************************************************************************************ 这个文件包含了大部分的实现** 用户认证扩展功能.用户的某些部分-** 身份验证代码包含在 SQLite 核心中(在** src/主源代码树的子目录)但那些部分** 可以合理地分离出来的内容被移动到这个文件中.**...
这是我使用 sqlite3
的 dbmanager.cpp
文件:
extern "C"{#include "sqlite/sqlite3.h";}#include使用命名空间标准;DBmanager::DBmanager(string dbAdd){如果(存在(dbAdd)){cout<<dbAdd<<<<<<<<<<文件已经存在"<<endl;}别的{cout<<dbAdd<<<<<<<<<<文件不存在,将第一次创建<dbAdd=dbAdd;国际RC;rc = sqlite3_open(this->dbAdd.c_str(), &this->db);sqlite3_user_add(db,Admin",Admin",2,1);//这是抛出我在下面提到的异常的行.如果( rc ) {cout<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<;sqlite3_errmsg(this->db)<
更新:
- 我已将
QMAKE_CXXFLAGS += -DSQLITE_USER_AUTHENTICATION -ldl -lpthread
添加到我的.pro
文件中.现在,QtCreator 检测到诸如sqlite3_user_add
之类的函数,但是当我尝试编译我的项目时,它给出了以下错误:
<块引用>
对`sqlite3_user_add'的未定义引用
<块引用>
:-1: 错误: collect2.exe: 错误: ld 返回 1 个退出状态
您在上面附加的错误,这是一个编译错误.尝试添加 mysql 标志,这有助于链接您的客户端库
eg: g++ youSqlCode.cpp -o b lmysqlcppconn
I am trying to utilize user authentication on sqlite3 for my c++ project. I have followed the steps explained in here. I have added sqlite3userauth.h
into the end of sqlite3.h
and userauth.c
into the end of sqlite3.c
and included #include "sqlite3.h"
in my code. But now my code does not recognize any of the new functions such as sqlite3_user_add
. Also, I have tried to compile shell.c
using the following command gcc -o sqlite3Exe shell.c sqlite3.c -DSQLITE_USER_AUTHENTICATION -ldl -lpthread
but I got this error:
sqlite3.c:230543:11: fatal error: sqliteInt.h: No such file or directory # include "sqliteInt.h" compilation terminated.
I tried to comment that line but then I got another error:
sqlite3.c:230730:3: error: too few arguments to function 'sqlite3ExpirePreparedStatements'
sqlite3ExpirePreparedStatements(db);
that line is referring to :
sqlite3ExpirePreparedStatements(db);
I haven't made any changes on the main code and followed the tips given by the official website but it seems like it doesn't work. Can you please guide me through this? I am using QT and trying to create a password-protected database interface.
Here are some parts of my code:
project.pro (I have added
sqlite3
and compiler flags this way) :SOURCES +=
sqlite/sqlite3.c
...HEADERS +=
sqlite/sqlite3.h
...QMAKE_CXXFLAGS += -DSQLITE_USER_AUTHENTICATION -ldl -lpthread
this is part of my sqlite3.h
file (it shows where have I added the codes of sqlite3userauth.h
):
...
#ifdef __cplusplus
} /* end of the 'extern "C"' block */
#endif
#endif /* _FTS5_H */
/******** End of fts5.h *********/
/*
** 2014-09-08
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
...
and this one is part of my sqlite3.c
file ( this shows where have I added the codes of userauth.c
):
...
#if __LINE__!=230511
#undef SQLITE_SOURCE_ID
#define SQLITE_SOURCE_ID "2020-08-14 13:23:32 fca8dc8b578f215a969cd899336378966156154710873e68b3d9ac5881b0alt2"
#endif
/* Return the source-id for this library */
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
/************************** End of sqlite3.c ******************************/
/*
** 2014-09-08
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains the bulk of the implementation of the
** user-authentication extension feature. Some parts of the user-
** authentication code are contained within the SQLite core (in the
** src/ subdirectory of the main source code tree) but those parts
** that could reasonable be separated out are moved into this file.
**
...
And here this is my dbmanager.cpp
file where I utilize sqlite3
:
extern "C"{
#include "sqlite/sqlite3.h"
}
#include<iostream>
using namespace std;
DBmanager::DBmanager(string dbAdd)
{
if(exists(dbAdd)){
cout<<dbAdd<<" file already exists"<<endl;
}else{
cout<<dbAdd<<" file doesn't exist and will be created for the first time"<<endl;
}
this->dbAdd=dbAdd;
int rc;
rc = sqlite3_open(this->dbAdd.c_str(), &this->db);
sqlite3_user_add(db,"Admin","Admin",2,1); // this is the line that throws the exceptions that I have mentioned below.
if( rc ) {
cout<<"Can't open database: "<< sqlite3_errmsg(this->db)<<endl;
return;
} else {
cout<<"Opened database successfully"<<endl;
}
}
Update:
- I have added
QMAKE_CXXFLAGS += -DSQLITE_USER_AUTHENTICATION -ldl -lpthread
into my.pro
file. Now, QtCreator detects functions such assqlite3_user_add
but when I try to compile my project it gives the following error:
undefined reference to `sqlite3_user_add'
:-1: error: collect2.exe: error: ld returned 1 exit status
Error which you attached above , it's an Compilaiton error . Try to add the mysql flag, which help in linking your client library
eg: g++ youSqlCode.cpp -o b lmysqlcppconn
这篇关于c++如何激活sqlite3的用户认证逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!