My class is:
#pragma once
#include "MyType.h"
class CPPSERVER_DLL_EXPORT User
{
public:
User() : id(0), is_frozen(false) {};
virtual ~User() {};
int id;
QString user_name;
QString password;
QString valid_code;
QString plugin_name;
bool is_frozen;
QDateTime unbind_date;
QDateTime terminate_date;
QDateTime create_date;
QVariant heart_date;
};
QX_REGISTER_PRIMARY_KEY(User, int)
QX_REGISTER_HPP_CPPSERVER(User, qx::trait::no_base_class_defined, 0)
#include "StdAfx.h"
#include "User.h"
QX_REGISTER_CPP_CPPSERVER(User)
namespace qx
{
template <> void register_class(QxClass<User> & t)
{
t.setName("[User]");
t.id(&User::id, "id");
t.data(&User::user_name, "user_name");
t.data(&User::password, "password");
t.data(&User::valid_code, "valid_code");
t.data(&User::plugin_name, "plugin_name");
t.data(&User::is_frozen, "is_frozen");
t.data(&User::unbind_date, "unbind_date");
t.data(&User::terminate_date, "terminate_date");
t.data(&User::create_date, "create_date");
t.data(&User::heart_date, "heart_date");
}
}
My code is:
UserPtr user = qx::dao::single_or_default<User>(qx_query().where("user_name").isEqualTo(QString::fromStdWString(userName)));
user->valid_code = QString::fromStdWString(validCode);
daoError = qx::dao::update(user); // Error
Error info:
[QxOrm] qx::QxSqlDatabase : create new database connection in thread '4552' with
key '{aaba7a93-03a5-449d-83f2-050a8e094270}'
[QxOrm] sql query (1531 ms) : SELECT [User].id AS User_id_0, [User].user_name AS
User_user_name_0, [User].password AS User_password_0, [User].valid_code AS User
_valid_code_0, [User].plugin_name AS User_plugin_name_0, [User].is_frozen AS Use
r_is_frozen_0, [User].unbind_date AS User_unbind_date_0, [User].terminate_date A
S User_terminate_date_0, [User].create_date AS User_create_date_0, [User].heart_
date AS User_heart_date_0 FROM [User] WHERE user_name = :user_name_1_0
[QxOrm] sql query (0 ms) : SELECT COUNT(*) FROM [User] WHERE valid_code = :valid
_code_1_0 AND is_frozen = :is_frozen_3_0
QODBCResult::exec: Unable to execute statement: "[Microsoft][ODBC SQL Server Dri
ver][SQL Server]Cannot update identity column 'id'. [Microsoft][ODBC SQL Server
Driver][SQL Server]Statement(s) could not be prepared."
[QxOrm] execute sql query failed : UPDATE [User] SET id = :id, user_name = :user
_name, password = :password, valid_code = :valid_code, plugin_name = :plugin_nam
e, is_frozen = :is_frozen, unbind_date = :unbind_date, terminate_date = :termina
te_date, create_date = :create_date, heart_date = :heart_date WHERE id = :id_bis
QODBC3: Unable to execute statement
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot update identity column 'id
'. [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prep
ared.
QODBCResult::exec: Unable to execute statement: "[Microsoft][ODBC SQL Server Dri
ver][SQL Server]Cannot update identity column 'id'. [Microsoft][ODBC SQL Server
Driver][SQL Server]Statement(s) could not be prepared."
[QxOrm] execute sql query failed : UPDATE [User] SET id = :id, user_name = :user
_name, password = :password, valid_code = :valid_code, plugin_name = :plugin_nam
e, is_frozen = :is_frozen, unbind_date = :unbind_date, terminate_date = :termina
te_date, create_date = :create_date, heart_date = :heart_date WHERE id = :id_bis
QODBC3: Unable to execute statement
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot update identity column 'id
'. [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prep
ared.
I think id column shouldn't update by QxOrm, how to fix this?