QXORM 使用记录

 QxOrm 的 example中

#ifndef _QX_BLOG_AUTHOR_H_ #define _QX_BLOG_AUTHOR_H_  class blog;  class QX_BLOG_DLL_EXPORT author { public: // -- typedef    typedef boost::shared_ptr<blog> blog_ptr;    typedef std::vector<blog_ptr> list_blog; // -- enum    enum enum_sex { male, female, unknown }; // -- properties    QString     m_id;
   QString     m_name;
   QDate       m_birthdate;
   enum_sex    m_sex;
   list_blog   m_blogX; // -- contructor, virtual destructor    author() : m_id(0), m_sex(unknown) { ; }    virtual ~author() { ; } // -- methods    int age() const; };

QX_REGISTER_PRIMARY_KEY(author, QString)
QX_REGISTER_HPP_QX_BLOG(author, qx::trait::no_base_class_defined, 0)  typedef boost::shared_ptr<author> author_ptr; typedef qx::QxCollection<QString, author_ptr> list_author;  #endif // _QX_BLOG_AUTHOR_H_

他的主键的类型默认是  long ,可以用QX_REGISTER_PRIMARY_KEY(author, QString) 来改变默认的主键类型,但是 这里的QString会被注册成

SQL 中的TEXT类型  这在 MSSQL 中是不能用的,所以找寻源代码 QxClassX.cpp中发现

 

 

void QxClassX::initSqlTypeByClassName()
{
   m_lstSqlTypeByClassName.clear();
 
   m_lstSqlTypeByClassName.insert("bool", "SMALLINT");
   m_lstSqlTypeByClassName.insert("qx_bool", "SMALLINT");
   m_lstSqlTypeByClassName.insert("short", "SMALLINT");
   m_lstSqlTypeByClassName.insert("int", "INTEGER");
   m_lstSqlTypeByClassName.insert("long", "INTEGER");
   m_lstSqlTypeByClassName.insert("long long", "INTEGER");
   m_lstSqlTypeByClassName.insert("float", "FLOAT");
   m_lstSqlTypeByClassName.insert("double", "FLOAT");
   m_lstSqlTypeByClassName.insert("long double", "FLOAT");
   m_lstSqlTypeByClassName.insert("unsigned short", "SMALLINT");
   m_lstSqlTypeByClassName.insert("unsigned int", "INTEGER");
   m_lstSqlTypeByClassName.insert("unsigned long", "INTEGER");
   m_lstSqlTypeByClassName.insert("unsigned long long", "INTEGER");
   m_lstSqlTypeByClassName.insert("std::string", "TEXT");
   m_lstSqlTypeByClassName.insert("std::wstring", "TEXT");
   m_lstSqlTypeByClassName.insert("QString", "varchar(10)");
   m_lstSqlTypeByClassName.insert("QVariant", "TEXT");
   m_lstSqlTypeByClassName.insert("QUuid", "TEXT");
   m_lstSqlTypeByClassName.insert("QDate", "DATE");
   m_lstSqlTypeByClassName.insert("QTime", "TIME");
   m_lstSqlTypeByClassName.insert("QDateTime", "TIMESTAMP");
   m_lstSqlTypeByClassName.insert("QByteArray", "BLOB");
   m_lstSqlTypeByClassName.insert("qx::QxDateNeutral", "TEXT");
   m_lstSqlTypeByClassName.insert("qx::QxTimeNeutral", "TEXT");
   m_lstSqlTypeByClassName.insert("qx::QxDateTimeNeutral", "TEXT");
}

 

这里修改了m_lstSqlTypeByClassName.insert("QString", "varchar(10)");

使得 QString 被注册成 varchar(10)类型。

 

你可能感兴趣的:(职场,休闲,QxOrm)