- Code: Select all
#ifndef TESTDATABASE_H
#define TESTDATABASE_H
#include "QxOrm.h"
class testDatabase
{
public:
testDatabase();
virtual ~testDatabase(){}
long id;
QString value;
};
QX_REGISTER_HPP_EXPORT_DLL(testDatabase, qx::trait::no_base_class_defined, 1)
#endif // TESTDATABASE_H
- Code: Select all
#include "testdatabase.h"
QX_REGISTER_CPP_EXPORT_DLL(testDatabase)
namespace qx {
template <> void register_class(QxClass<testDatabase> & t)
{
t.setName("t_test");
t.id(&testDatabase::id,"id");
t.data(&testDatabase::value,"value");
}
}
testDatabase::testDatabase():
id(0)
{
}
my main:
- Code: Select all
testdatabaseptr d1=testdatabaseptr(new testDatabase);
d1->id=0;
d1->value="aaaa"+QString::number(0);
QSqlError daoError = qx::dao::insert(d1);
my table:
- Code: Select all
CREATE TABLE t_test (id INTEGER NOT NULL, value TEXT, PRIMARY KEY (id));
When I use mysql database,i got the error message:
[QxOrm] execute sql query failed : INSERT INTO t_test (value) VALUES (:value)
QMYSQL3: Unable to execute statement
Field 'id' doesn't have a default value
I found that only the field 'value' would be inserted according to the sql.
Why?
And,how should I do if i want insert both id and value ?