[英]search in sqlite database c++
首先这是我的完整代码
/*Getting user input and checking it using sqlite*/
string data, sql;
int id, rc;
int al;
do {
cout << "Enter your id:";
cin >> id;
} while (id > 9999999999 || id < 1000000000);
/*Creating a sqlite3 pointer in order to connect to the sql*/
sqlite3* connection = nullptr;
/*opening sql*/
int result = sqlite3_open("sql.db", &connection);
/*Creating a query to search sql*/
if (result) {
cerr << "Error open DB " << sqlite3_errmsg(connection) << std::endl;
}
else {
cout << "Opened Database Successfully!" << std::endl;
}
sqlite3* query = nullptr;
/*Searching database for id*/
data = ("CALLBACK FUNCTION");
sql = ("SELECT * FROM Doctors WHERE nationalCode = " + to_string(id) + " ;");
/*start searching*/
/*if sql found a document, then it will continue; else, it will make a new document then
it will continue*/
rc = sqlite3_exec(connection, sql.c_str(), callback, (void*)data.c_str(), NULL);
if (rc == SQLITE_OK) {
cout << "Operation OK!" << endl;
cout << "What do you want to do?" << endl;
cout << "1:making a Visit" << endl;
cout << "2:cancel your Visit" << endl;
cout << "3:edit your Information" << endl;
cout << "4:delete your Account" << endl;
cin >> al;
switch (al)
{
case 1:
createVisit();
break;
case 2:
cout << "Hello";
break;
case 3:
editDoctor();
break;
case 4:
cout << "Hello";
break;
default:
cout << "Wrong number, Closing the Application";
break;
}
}
else {
cout << "we can't find your information! Creating a new document right now" << endl
<< "+______________________________________________________________________________+" << endl;
sqlite3_close(connection);
createDoctor();
}
sqlite3_close(connection);
我的问题是这些行:
data = ("CALLBACK FUNCTION");
sql = ("SELECT * FROM Doctors WHERE nationalCode = " + to_string(id) + " ;");
/*start searching*/
/*if sql found a document, then it will continue; else, it will make a new document then
it will continue*/
rc = sqlite3_exec(connection, sql.c_str(), callback, (void*)data.c_str(), NULL);
我有一个 sqlite 数据库,它已正确连接到我的控制台应用程序,但是当我在行中搜索用户输入时,不管它会运行什么 if 语句。 我想检查用户输入是否可用。 如果用户输入可用,则运行if语句,如果用户输入不可用,则运行else语句。 我相信“rc”有一些东西在运行。 有人可以告诉我一个正确的方法吗?
如果 SQL 成功执行, sqlite3_exec
将返回SQLITE_OK
,无论是否返回任何行。 您需要使用回调来处理查询的结果。
有关详细信息,请参阅function和 rest 的文档 SQLite ZDB9474238D14CADE
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.