gpt4 book ai didi

c++ - QSqlQuery 行影响结果

转载 作者:行者123 更新时间:2023-11-30 04:56:47 26 4
gpt4 key购买 nike

SHA256 sha256;
std::string s = sha256(pass.toStdString());

QString myquery = "declare @identifier nvarchar(100) = NEWID()\
declare @user_name nvarchar(50) = '"+user+"'\
declare @pass_word nvarchar(100) = '"+QString::fromStdString(s)+"'\
declare @hint nvarchar(50) = '"+hint+"'\
if NOT exists(select * from user_table where (userid=@identifier or username = @user_name))\
insert into user_table (username,password,password_salt,userid) values(@user_name,@pass_word,@hint,@identifier)";
qDebug()<<myquery;
openSqlConnection();
QSqlQuery q3;
q3.exec(myquery);

执行此查询后,如果执行成功,我应该会看到(1 row(s) affected)的结果。

如果数据库中已经存在用户名,则结果为

Command(s) completed successfully.

要查看 select 的结果,我使用 q3.next()

我如何知道我的查询已成功执行?

最佳答案

How do I know that my query has been executed successfully?

这里有多种选择。您可以检查:

Returns true and sets the query state to active if the query was successful; otherwise returns false.

例如:

if (!q3.exec(myquery))
\\ show error

An active QSqlQuery is one that has been exec()'d successfully but not yet finished with.

例如:

q3.exec(myquery);

if (!q3.isActive())
\\ show error

QSqlError::NoError 0 No error occurred.

例如:

q3.exec(myquery);

if (q3.lastError().type() != QSqlError::NoError)
\\ show error

如果您通过了检查(您选择的检查),您可以进一步处理您的查询,例如查看 username 是否已经存在以及有多少行受到影响。

关于c++ - QSqlQuery 行影响结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52351718/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com