[英]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.