QxOrm 默认的主键类型 是long 而且默认是自动增长的,如果不希望 自动增长,可以在 QDataMemberX.inl 中设置,
IxDataMember * QxDataMemberX<T>::id(typename QxDataMemberX<T>::type_primary_key T::* pDataMemberId, const QString & sKey, long lVersion)
{
if (exist_WithDaoStrategy(sKey) || getId_WithDaoStrategy()) { qAssert(false); return getId_WithDaoStrategy(); }
qAssert(lVersion <= getVersion());
m_pDataMemberId = new QxDataMember<typename QxDataMemberX<T>::type_primary_key, T>(pDataMemberId, sKey);
m_pDataMemberId->setSqlType(qx::trait::get_sql_type<typename QxDataMemberX<T>::type_primary_key>::get());
//m_pDataMemberId->setAutoIncrement(boost::is_integral<typename QxDataMemberX<T>::type_primary_key>::value);
m_pDataMemberId->setNameParent(getName());
m_pDataMemberId->setIsPrimaryKey(true);
m_pDataMemberId->setNotNull(true);
m_pDataMemberId->setVersion(lVersion);
m_pDataMemberId->setParent(this);
m_lstDataMember.insert(sKey, m_pDataMemberId);
return m_pDataMemberId;
}
注释掉了//m_pDataMemberId->setAutoIncrement(boost::is_integral<typename QxDataMemberX<T>::type_primary_key>::value);
其实 QxOrm 在 IxDataMember.h设置了宏
#define QX_CONSTRUCT_IX_DATA_MEMBER() \
m_iPrecision(6), m_iMinLength(-1), m_iMaxLength(-1), m_bRequired(false), \
m_bReadOnly(false), m_bAutoIncrement(false), m_bNotNull(false), \
m_bIsPrimaryKey(false), m_pName(NULL), m_pParent(NULL)
IxDataMember(const QString & sKey) : m_sKey(sKey), m_lVersion(-1), m_bSerialize(true), m_bDao(true), QX_CONSTRUCT_IX_DATA_MEMBER() { qAssert(! m_sKey.isEmpty()); updateNamePtr(); }
IxDataMember(const QString & sKey, long lVersion, bool bSerialize, bool bDao) : m_sKey(sKey), m_lVersion(lVersion), m_bSerialize(bSerialize), m_bDao(bDao), QX_CONSTRUCT_IX_DATA_MEMBER() { qAssert(! m_sKey.isEmpty()); updateNamePtr(); }
两个 构造函数 也是使用这个宏。