### C++ Example Project: qxBlogExec.zip Source: https://www.qxorm.com/qxorm_en/download.html A C++/Qt example project named qxBlogExec.zip, located in the ./samples/ directory. This project depends on generated files from qxBlog.qxee. ```cpp qxBlogExec.zip ``` -------------------------------- ### Initialize Database and Perform CRUD Operations Source: https://www.qxorm.com/qxorm_en/tutorial.html Demonstrates database connection setup, clearing tables, inserting data, and using reflection features like cloning. ```cpp #include "../include/precompiled.h" #include #include "../include/blog.h" #include "../include/author.h" #include "../include/comment.h" #include "../include/category.h" #include int main(int argc, char * argv[]) { // Qt application QApplication app(argc, argv); // Parameters to connect to database qx::QxSqlDatabase::getSingleton()->setDriverName("QSQLITE"); qx::QxSqlDatabase::getSingleton()->setDatabaseName("./qxBlog.sqlite"); qx::QxSqlDatabase::getSingleton()->setHostName("localhost"); qx::QxSqlDatabase::getSingleton()->setUserName("root"); qx::QxSqlDatabase::getSingleton()->setPassword(""); // Ensure there is no element in database QSqlError daoError = qx::dao::delete_all(); daoError = qx::dao::delete_all(); daoError = qx::dao::delete_all(); daoError = qx::dao::delete_all(); // Create a list of 3 author author_ptr author_1; author_1.reset(new author()); author_ptr author_2; author_2.reset(new author()); author_ptr author_3; author_3.reset(new author()); author_1->m_id = "author_id_1"; author_1->m_name = "author_1"; author_1->m_sex = author::male; author_1->m_birthdate = QDate::currentDate(); author_2->m_id = "author_id_2"; author_2->m_name = "author_2"; author_2->m_sex = author::female; author_2->m_birthdate = QDate::currentDate(); author_3->m_id = "author_id_3"; author_3->m_name = "author_3"; author_3->m_sex = author::female; author_3->m_birthdate = QDate::currentDate(); list_author authorX; authorX.insert(author_1->m_id, author_1); authorX.insert(author_2->m_id, author_2); authorX.insert(author_3->m_id, author_3); // Insert list of 3 author into database daoError = qx::dao::insert(authorX); qAssert(qx::dao::count() == 3); // Clone author n°2 : 'author_id_2' author_ptr author_clone = qx::clone(* author_2); qAssert(author_clone->m_id == "author_id_2"); qAssert(author_clone->m_sex == author::female); // Create a query to fetch only female author : 'author_id_2' and 'author_id_3' qx::QxSqlQuery query("WHERE author.sex = :sex"); ``` -------------------------------- ### QxOrm SQL Query Example Source: https://www.qxorm.com/qxorm_en/resource/qxBlog.main.exec.result.txt This is an example of a SQL query generated by QxOrm, including joins and a WHERE clause. It shows the structure of the query and the selected fields. ```sql SELECT blog.blog_id AS blog_blog_id_0, blog.blog_text AS blog_blog_text_0, blog.date_creation AS blog_date_creation_0, blog.author_id AS blog_author_id_0, author_1.author_id AS author_1_author_id_0, author_1.name AS author_1_name_0, author_1.birthdate AS author_1_birthdate_0, author_1.sex AS author_1_sex_0, comment_2.comment_id AS comment_2_comment_id_0, comment_2.blog_id AS comment_2_blog_id_0, comment_2.comment_text AS comment_2_comment_text_0, comment_2.date_creation AS comment_2_date_creation_0, category_3.category_id AS category_3_category_id_0, category_3.name AS category_3_name_0, category_3.description AS category_3_description_0 FROM blog LEFT OUTER JOIN author author_1 ON author_1_author_id_0 = blog_author_id_0 LEFT OUTER JOIN comment comment_2 ON comment_2_blog_id_0 = blog_blog_id_0 LEFT OUTER JOIN category_blog ON blog_blog_id_0 = category_blog.blog_id LEFT OUTER JOIN category category_3 ON category_blog.category_id = category_3_category_id_0 WHERE blog_blog_id_0 = :blog_id ``` -------------------------------- ### Perform CRUD and Serialization with QxOrm Source: https://www.qxorm.com/qxorm_en/quick_sample.html Demonstrates the full lifecycle of a QxOrm application, including database setup, entity manipulation, and XML serialization. ```cpp #include "precompiled.h" #include "drug.h" #include int main(int argc, char * argv[]) { QApplication app(argc, argv); // Qt application // Create 3 new drugs // It is possible to use 'std' and 'Qt' smart pointer : 'std::shared_ptr', 'QSharedPointer', etc... typedef std::shared_ptr drug_ptr; drug_ptr d1; d1.reset(new drug()); d1->name = "name1"; d1->description = "desc1"; drug_ptr d2; d2.reset(new drug()); d2->name = "name2"; d2->description = "desc2"; drug_ptr d3; d3.reset(new drug()); d3->name = "name3"; d3->description = "desc3"; // Insert drugs into container // It is possible to use many containers from 'std', 'boost', 'Qt' and 'qx::QxCollection' typedef std::vector type_lst_drug; type_lst_drug lst_drug; lst_drug.push_back(d1); lst_drug.push_back(d2); lst_drug.push_back(d3); // Init parameters to communicate with a database qx::QxSqlDatabase::getSingleton()->setDriverName("QSQLITE"); qx::QxSqlDatabase::getSingleton()->setDatabaseName("./test_qxorm.db"); qx::QxSqlDatabase::getSingleton()->setHostName("localhost"); qx::QxSqlDatabase::getSingleton()->setUserName("root"); qx::QxSqlDatabase::getSingleton()->setPassword(""); // Create table 'drug' into database to store drugs QSqlError daoError = qx::dao::create_table(); // Insert drugs from container to database // 'id' property of 'd1', 'd2' and 'd3' are auto-updated daoError = qx::dao::insert(lst_drug); // Modify and update the second drug into database d2->name = "name2 modified"; d2->description = "desc2 modified"; daoError = qx::dao::update(d2); // Delete the first drug from database daoError = qx::dao::delete_by_id(d1); // Count drugs into database long lDrugCount = qx::dao::count(); // Fetch drug with id '3' into a new variable drug_ptr d_tmp; d_tmp.reset(new drug()); d_tmp->id = 3; daoError = qx::dao::fetch_by_id(d_tmp); // Export drugs from container to a file under xml format (serialization) qx::serialization::xml::to_file(lst_drug, "./export_drugs.xml"); // Import drugs from xml file into a new container type_lst_drug lst_drug_tmp; qx::serialization::xml::from_file(lst_drug_tmp, "./export_drugs.xml"); // Clone a drug drug_ptr d_clone = qx::clone(* d1); // Create a new drug by class name (factory) qx::any d_any = qx::create("drug"); // Insert drugs container into 'qx::cache' qx::cache::set("drugs", lst_drug); // Remove all elements from 'qx::cache' qx::cache::clear(); // Create a dummy memory leak drug * pDummy = new drug(); return 0; } ``` -------------------------------- ### Import via JSON File Command Line Source: https://www.qxorm.com/qxorm_en/manual_qxee.html Use this command to automatically load a specific JSON project file when starting the QxEntityEditor application. ```bash QxEntityEditor --project="" --plugin=QxEEJsonImport --QxEEJsonImport_file="" ``` -------------------------------- ### Implementing IxPersistable Interface Source: https://www.qxorm.com/qxorm_en/faq.html Steps and examples for implementing the `qx::IxPersistable` interface for custom classes. ```APIDOC ## Implementing IxPersistable Interface ### Description To implement the `qx::IxPersistable` interface, follow these steps: 1. Inherit your persistent class from `qx::IxPersistable`. 2. In your class definition header file (e.g., `myClass.h`), add the `QX_PERSISTABLE_HPP(myClass)` macro. 3. In your class implementation file (e.g., `myClass.cpp`), add the `QX_PERSISTABLE_CPP(myClass)` macro. ### Example: `author` class implementation #### Header File (`author.h`) ```cpp #ifndef _QX_BLOG_AUTHOR_H_ #define _QX_BLOG_AUTHOR_H_ #include #include #include #include // Forward declarations class blog; class QX_BLOG_DLL_EXPORT author : public qx::IxPersistable { QX_PERSISTABLE_HPP(author) public: // -- typedef typedef boost::shared_ptr blog_ptr; typedef std::vector 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_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_ptr; typedef qx::QxCollection list_author; #endif // _QX_BLOG_AUTHOR_H_ ``` #### Implementation File (`author.cpp`) ```cpp #include "../include/precompiled.h" #include "../include/author.h" #include "../include/blog.h" #include QX_REGISTER_CPP_QX_BLOG(author) QX_PERSISTABLE_CPP(author) namespace qx { template <> void register_class(QxClass & t) { t.id(& author::m_id, "author_id"); t.data(& author::m_name, "name"); t.data(& author::m_birthdate, "birthdate"); t.data(& author::m_sex, "sex"); t.relationOneToMany(& author::m_blogX, "list_blog", "author_id"); t.fct_0(& author::age, "age"); }} int author::age() const { if (! m_birthdate.isValid()) { return -1; } return (QDate::currentDate().year() - m_birthdate.year()); } ``` ### Note on `qx::QxPersistable` The `qx::QxPersistable` class (found in `test/qxDllSample/dll1/`) provides a 'super base class' that implements `qx::IxPersistable` and inherits from `QObject`. This allows for the use of Qt's SIGNAL-SLOT mechanism as triggers and provides virtual methods for data validation using the `QxValidator` module. You can copy-paste `QxPersistable.hpp` and `QxPersistable.cpp` into your project to leverage these features. ``` -------------------------------- ### QxSession Persistent Methods Example Source: https://www.qxorm.com/qxorm_en/faq.html Demonstrates using QxSession's persistent methods for CRUD operations, providing a more object-oriented approach compared to qx::dao functions. ```cpp { // Start a scope where a new session is instantiated // Create a session : a valid database connexion by thread is automatically assigned to the session and a transaction is opened ``` -------------------------------- ### Generated SQL Query Example Source: https://www.qxorm.com/qxorm_en/faq.html Shows the SQL query generated by the QxOrm library for MySQL, PostgreSQL, and SQLite based on the advanced query construction example. Note that Oracle and SQLServer have specific LIMIT clause handling. ```sql WHERE sex = :sex_1_0 AND age > :age_3_0 OR last_name <> :last_name_5_0 OR first_name LIKE :first_name_7_0 AND ( id <= :id_10_0 AND birth_date BETWEEN :birth_date_12_0_1 AND :birth_date_12_0_2 ) OR id IN (:id_15_0_0, :id_15_0_1, :id_15_0_2, :id_15_0_3, :id_15_0_4) AND is_deleted IS NOT NULL ORDER BY last_name ASC, first_name ASC, sex ASC LIMIT :limit_rows_count_19_0 OFFSET :offset_start_row_19_0 ``` -------------------------------- ### QxEntityEditor Command-Line Interface Source: https://www.qxorm.com/qxorm_en/manual_qxee.html QxEntityEditor offers a command-line interface (CLI) for running the application with various parameters. Below are examples of common CLI commands. ```APIDOC ## QxEntityEditor CLI Examples ### Load Project Run QxEntityEditor and load a specific project file at startup. ```bash QxEntityEditor --project="c:\test\qxBlog.qxee" ``` ### No GUI with Export Run QxEntityEditor without the graphical user interface, load a project, and automatically execute a C++ export process. ```bash QxEntityEditor --no_gui --project="c:\test\qxBlog.qxee" --plugin=QxEECppExport ``` ### Viewer Mode Run QxEntityEditor in read-only mode, useful for opening large projects without a license. ```bash QxEntityEditor --viewer_mode ``` ### Log SQL Queries Run QxEntityEditor and log all executed SQL queries to the SQLite database. ```bash QxEntityEditor --log_sql ``` ### Import from JSON Run QxEntityEditor, load a project, and import data from a JSON file using the QxEEJsonImport plugin. ```bash QxEntityEditor --project="" --plugin=QxEEJsonImport --QxEEJsonImport_file="" ``` ### Display Help Display documentation for all QxEntityEditor command-line parameters. ```bash QxEntityEditor --? ``` ### MySQL Import Plugin Parameters Import data from a MySQL database using the QxEEMySQLImport plugin. #### Required Parameters - **--QxEEMySQLImport_db_ip** (string) - Database server address (IP) - **--QxEEMySQLImport_db_port** (string) - Port number to connect to the database - **--QxEEMySQLImport_db_name** (string) - Database name #### Optional Parameters - **--QxEEMySQLImport_filter_regexp** (string) - Regular expression to filter tables for import - **--QxEEMySQLImport_login** (string) - Login for database connection - **--QxEEMySQLImport_pwd** (string) - Password for database connection - **--QxEEMySQLImport_namespace** (string) - C++ namespace for imported classes - **--QxEEMySQLImport_delete_namespace** (0 or 1) - Delete all entities in the namespace before importing ``` -------------------------------- ### Manage Server Lifecycle Source: https://www.qxorm.com/qxorm_en/tutorial_2.html Handles starting and stopping the server thread pool and configuring network parameters like compression and encryption. ```cpp void main_dlg::onClickStartStop() { QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); if (m_pThreadPool) { m_pThreadPool->disconnect(); m_pThreadPool.reset(); txtError->setPlainText(""); txtTransaction->setPlainText(""); onServerIsRunning(false, NULL); } else { qx::service::QxConnect::getSingleton()->setPort(spinPortNumber->value()); qx::service::QxConnect::getSingleton()->setThreadCount(spinThreadCount->value()); qx::service::QxConnect::getSingleton()->setSerializationType((qx::service::QxConnect::serialization_type) (cboSerializationType->itemData(cboSerializationType->currentIndex()).toInt())); qx::service::QxConnect::getSingleton()->setCompressData(chkCompressData->isChecked()); qx::service::QxConnect::getSingleton()->setEncryptData(chkEncryptData->isChecked()); m_pThreadPool.reset(new qx::service::QxThreadPool()); QObject::connect(m_pThreadPool.get(), SIGNAL(error(const QString &, qx::service::QxTransaction_ptr)), this, SLOT(onError(const QString &, qx::service::QxTransaction_ptr))); ``` -------------------------------- ### QxEntityEditor JSON Project Structure Source: https://www.qxorm.com/qxorm_en/manual_qxee.html Example of the JSON structure used for project imports, representing entities and their properties. ```json { "app_version": 0, "description": "", "dt_creation": "20131206221737", "dt_modification": "20131206221737", "id": 1, "list_all_entities": [ { "app_version": 0, "description": "", "dt_creation": "20131206221810", "dt_modification": "20140617214144", "id": 1, "is_abstract": false, "is_read_only": false, "key": "", "list_functions": null, "list_functions_static": null, "list_meta_data": null, "list_properties": [ { "accessibility": "protected", "allow_null": false, ``` -------------------------------- ### Configure QxOrm.pri for Boost Include Path Source: https://www.qxorm.com/qxorm_en/tutorial_3.html Set the QX_BOOST_INCLUDE_PATH variable in QxOrm.pri to point to your Boost installation's include directory. This is required if your project uses Boost. ```pri _isEmpty(QX_BOOST_INCLUDE_PATH) { QX_BOOST_INCLUDE_PATH = $$quote( D:/Dvlp/_Libs/Boost/1_57/include) } ``` -------------------------------- ### Configure QxOrm.pri for Boost Serialization Libraries Source: https://www.qxorm.com/qxorm_en/tutorial_3.html When Boost serialization is enabled, configure QxOrm.pri with paths and library names for debug and release builds. This example shows settings for Visual Studio 110. ```pri contains(DEFINES, _QX_ENABLE_BOOST_SERIALIZATION) { isEmpty(QX_BOOST_LIB_PATH) { QX_BOOST_LIB_PATH = $$quote(D:/Dvlp/_Libs/Boost/1_57/lib_shared) } isEmpty(QX_BOOST_LIB_SERIALIZATION_DEBUG) { QX_BOOST_LIB_SERIALIZATION_DEBUG = "boost_serialization-vc110-mt-gd-1_57" } isEmpty(QX_BOOST_LIB_SERIALIZATION_RELEASE) { QX_BOOST_LIB_SERIALIZATION_RELEASE = "boost_serialization-vc110-mt-1_57" } # isEmpty(QX_BOOST_LIB_WIDE_SERIALIZATION_DEBUG) { QX_BOOST_LIB_WIDE_SERIALIZATION_DEBUG = "boost_wserialization-vc110-mt-gd-1_57" } ``` -------------------------------- ### Initialize and Use QxOrm in main() Source: https://www.qxorm.com/qxorm_en/manual_qxee.html Demonstrates setting up a database connection, creating tables, performing CRUD operations, and using transactions with QxOrm. ```cpp int main(int argc, char * argv[]) { // Qt application QCoreApplication app(argc, argv); QFile::remove("./qxBlog.sqlite"); // Parameters to connect to database qx::QxSqlDatabase::getSingleton()->setDriverName("QSQLITE"); qx::QxSqlDatabase::getSingleton()->setDatabaseName("./qxBlog.sqlite"); qx::QxSqlDatabase::getSingleton()->setHostName("localhost"); qx::QxSqlDatabase::getSingleton()->setUserName("root"); qx::QxSqlDatabase::getSingleton()->setPassword(""); // Only for debug purpose : assert if invalid offset detected fetching a relation qx::QxSqlDatabase::getSingleton()->setVerifyOffsetRelation(true); // !!! TO CREATE TABLES, PLEASE USE THE C++ DDL SQL EXPORT PLUGIN OF QXENTITYEDITOR !!! // Create all tables in database (you should not use 'qx::dao::create_table()' function in a production software, use it just for prototypes or samples) QSqlError daoError = qx::dao::create_table(); daoError = qx::dao::create_table(); daoError = qx::dao::create_table(); daoError = qx::dao::create_table(); // Create a list of 3 author author_ptr author_1; author_1.reset(new author()); author_ptr author_2; author_2.reset(new author()); author_ptr author_3; author_3.reset(new author()); author_1->setlastname("author_1"); author_1->setsex(sex::male); author_1->setbirthdate(QDateTime::currentDateTime()); author_2->setlastname("author_2"); author_2->setsex(sex::female); author_2->setbirthdate(QDateTime::currentDateTime()); author_3->setlastname("author_3"); author_3->setsex(sex::female); author_3->setbirthdate(QDateTime::currentDateTime()); list_of_author authorX; authorX.insert(1, author_1); authorX.insert(2, author_2); authorX.insert(3, author_3); // Insert list of 3 author into database daoError = qx::dao::insert(authorX); qAssert(qx::dao::count() == 3); // Clone author n°2 : 'author_id_2' author_ptr author_clone = qx::clone(* author_2); qAssert(author_clone->getauthor_id() == author_2->getauthor_id()); qAssert(author_clone->getsex() == sex::female); // Create a query to fetch only female author : 'author_id_2' and 'author_id_3' qx::QxSqlQuery query("WHERE t_author.sex = :sex"); query.bind(":sex", sex::female); list_of_author list_of_female_author; daoError = qx::dao::fetch_by_query(query, list_of_female_author); qAssert(list_of_female_author.count() == 2); // Dump list of female author (xml serialization) qx::dump(list_of_female_author); // Create 3 categories category_ptr category_1 = category_ptr(new category("cat_1")); category_ptr category_2 = category_ptr(new category("cat_2")); category_ptr category_3 = category_ptr(new category("cat_3")); category_1->setname("category_1"); category_1->setdescription("desc_1"); category_2->setname("category_2"); category_2->setdescription("desc_2"); category_3->setname("category_3"); category_3->setdescription("desc_3"); { // Create a scope to destroy temporary connexion to database // Open a transaction to database QSqlDatabase db = qx::QxSqlDatabase::getDatabase(); bool bCommit = db.transaction(); // Insert 3 categories into database, use 'db' parameter for the transaction daoError = qx::dao::insert(category_1, (& db)); bCommit = (bCommit && ! daoError.isValid()); daoError = qx::dao::insert(category_2, (& db)); bCommit = (bCommit && ! daoError.isValid()); daoError = qx::dao::insert(category_3, (& db)); bCommit = (bCommit && ! daoError.isValid()); qAssert(bCommit); qAssert(category_1->getcategory_id() != ""); qAssert(category_2->getcategory_id() != ""); qAssert(category_3->getcategory_id() != ""); // Terminate transaction => commit or rollback if there is error if (bCommit) { db.commit(); } else { db.rollback(); } } // End of scope : 'db' is destroyed // Create a blog with the class name (factory) boost::any blog_any = qx::create("blog"); blog_ptr blog_1; try { blog_1 = boost::any_cast(blog_any); } ``` -------------------------------- ### Get List of Entities/Enums with Javascript Source: https://www.qxorm.com/qxorm_en/download.html Utilize Javascript functions to retrieve a list of all entities and enums within a QxEntityEditor project. Refer to './samples/custom_script.js' for examples. ```javascript // add functions to get a list of all entities/enums of a project ``` -------------------------------- ### QxOrm Debug Output: Start dump collection Source: https://www.qxorm.com/qxorm_en/tutorial.html QxOrm debug log indicating the start of a data dump operation for a collection of authors. ```log [QxOrm] start dump 'qx::QxCollection>' ``` -------------------------------- ### Run QxEntityEditor with a Project File Source: https://www.qxorm.com/qxorm_en/manual_qxee.html Use the --project parameter to specify a .qxee project file to load at startup. ```bash QxEntityEditor --project="c:\test\qxBlog.qxee" ``` -------------------------------- ### Initialize Application Server Parameters Source: https://www.qxorm.com/qxorm_en/tutorial_2.html Sets up UI components, connects signal-slot events, and configures default serialization and network settings. ```cpp void main_dlg::init() { setupUi(this); QObject::connect(btnStartStop, SIGNAL(clicked()), this, SLOT(onClickStartStop())); QObject::connect(cboSerializationType, SIGNAL(currentIndexChanged(int)), this, SLOT(onCboIndexChanged(int))); cboSerializationType->addItem("0- serialization_binary", QVariant((int)qx::service::QxConnect::serialization_binary)); cboSerializationType->addItem("1- serialization_xml", QVariant((int)qx::service::QxConnect::serialization_xml)); cboSerializationType->addItem("2- serialization_text", QVariant((int)qx::service::QxConnect::serialization_text)); cboSerializationType->addItem("3- serialization_portable_binary", QVariant((int)qx::service::QxConnect::serialization_portable_binary)); cboSerializationType->addItem("4- serialization_wide_binary", QVariant((int)qx::service::QxConnect::serialization_wide_binary)); cboSerializationType->addItem("5- serialization_wide_xml", QVariant((int)qx::service::QxConnect::serialization_wide_xml)); cboSerializationType->addItem("6- serialization_wide_text", QVariant((int)qx::service::QxConnect::serialization_wide_text)); cboSerializationType->addItem("7- serialization_polymorphic_binary", QVariant((int)qx::service::QxConnect::serialization_polymorphic_binary)); cboSerializationType->addItem("8- serialization_polymorphic_xml", QVariant((int)qx::service::QxConnect::serialization_polymorphic_xml)); cboSerializationType->addItem("9- serialization_polymorphic_text", QVariant((int)qx::service::QxConnect::serialization_polymorphic_text)); cboSerializationType->setCurrentIndex(cboSerializationType->findData(QVariant((int)qx::service::QxConnect::getSingleton()->getSerializationType()))); spinPortNumber->setValue(7694); spinThreadCount->setValue(qx::service::QxConnect::getSingleton()->getThreadCount()); onServerIsRunning(false, NULL); onClickStartStop(); } ``` -------------------------------- ### Build qxBlogExec project with qmake Source: https://www.qxorm.com/qxorm_en/manual_qxee.html Instructions for building the qxBlogExec project using qmake after exporting the 'qxBlog.qxee' project. ```bash -------------------------------------------- -- To build qxBlogExec project with qmake -- -------------------------------------------- 1- Export the 'qxBlog.qxee' project as a C++ project with QxEntityEditor and build it 2- Open the 'qxBlogExec.pro' file ``` -------------------------------- ### Display QxEntityEditor Command-Line Help Source: https://www.qxorm.com/qxorm_en/manual_qxee.html Use the --? parameter to display documentation for all QxEntityEditor command-line parameters. ```bash QxEntityEditor --? ``` -------------------------------- ### Execute Validation Source: https://www.qxorm.com/qxorm_en/faq.html Example of triggering the validation process manually on an instance. ```cpp person personValidate; personValidate._lastName = "admin"; qx::QxInvalidValueX invalidValues = qx::validate(personValidate); QString sInvalidValues = invalidValues.text(); qDebug("[QxOrm] test 'QxValidator' module :\n%s", qPrintable(sInvalidValues)); ``` -------------------------------- ### Build QxOrm Library with qmake Source: https://www.qxorm.com/qxorm_en/faq.html Use these commands to build the QxOrm library using the qmake build system. Ensure qmake is in your PATH. ```bash qmake make debug make release ``` -------------------------------- ### Run QxEntityEditor with SQL Logging Source: https://www.qxorm.com/qxorm_en/manual_qxee.html Enable SQL logging with the --log_sql parameter to trace all SQL queries executed against the .qxee SQLite database. ```bash QxEntityEditor --log_sql ``` -------------------------------- ### Create and Save Blog Source: https://www.qxorm.com/qxorm_en/tutorial.html Creates a 'blog' object using QxORM's factory method, sets its properties, and saves it to the database using the 'save()' method. ```cpp boost::any blog_any = qx::create("blog"); blog_ptr blog_1 = boost::any_cast(blog_any); blog_1->m_text = "blog_text_1"; blog_1->m_dt_creation = QDateTime::currentDateTime(); blog_1->m_author = author_1; daoError = qx::dao::save(blog_1); ``` -------------------------------- ### Using QxOrm Cache Engine Source: https://www.qxorm.com/qxorm_en/faq.html Demonstrates cache operations including setting items with costs and timestamps, retrieving items, and managing cache state. ```cpp // Define max cost of cache engine to 500 qx::cache::max_cost(500); // Fetch a list of 'author' from database boost::shared_ptr< QList > list_author; QSqlError daoError = qx::dao::fetch_all(list_author); // Insert the list of 'author' to the cache qx::cache::set("list_author", list_author); // Fetch a list of 'blog' from database QSharedPointer< std::vector > list_blog; daoError = qx::dao::fetch_all(list_blog); // Insert the list of 'blog' to the cache (cost = 'blog' count) qx::cache::set("list_blog", list_blog, list_blog.count()); // Pointer to an object of type 'comment' comment_ptr my_comment; my_comment.reset(new comment(50)); daoError = qx::dao::fetch_by_id(my_comment); // Insert 'comment' to the cache with a date-time insertion qx::cache::set("comment", my_comment, 1, my_comment->dateModif()); // Get the list of 'blog' stored into the cache list_blog = qx::cache::get< QSharedPointer< std::vector > >("list_blog"); // Get the list of 'blog' without providing the type qx_bool bGetOk = qx::cache::get("list_blog", list_blog); // Remove list of 'author' from cache bool bRemoveOk = qx::cache::remove("list_author"); // Get items count stored into the cache long lCount = qx::cache::count(); // Get current cost of items stored into the cache long lCurrentCost = qx::cache::current_cost(); // Verify that an element with the key "comment" exists into the cache bool bExist = qx::cache::exist("comment"); // Get 'comment' stored into the cache with its date-time insertion QDateTime dt; bGetOk = qx::cache::get("comment", my_comment, dt); // Clear the cache qx::cache::clear(); ``` -------------------------------- ### QxOrm Build Configuration Source: https://www.qxorm.com/qxorm_en/resource/qxService.pri This is a standard QxOrm build configuration file. It sets up the project as a DLL, defines necessary include paths and libraries, and lists header and source files. ```pri include(../../../QxOrm.pri) TEMPLATE = lib CONFIG += dll DEFINES += _BUILDING_QX_SERVICE INCLUDEPATH += ../../../../QxOrm/include/ DESTDIR = ../../../../QxOrm/test/_bin/ LIBS += -L"../../../../QxOrm/test/_bin" !contains(DEFINES, _QX_NO_PRECOMPILED_HEADER) { PRECOMPILED_HEADER = ./include/precompiled.h } # !contains(DEFINES, _QX_NO_PRECOMPILED_HEADER) CONFIG(debug, debug|release) { LIBS += -l"QxOrmd" } else { LIBS += -l"QxOrm" } # CONFIG(debug, debug|release) HEADERS += ./include/precompiled.h HEADERS += ./include/export.h HEADERS += ./include/service/server_infos.h HEADERS += ./include/service/user_service.h HEADERS += ./include/business_object/user.h HEADERS += ./include/business_object/user_search.h HEADERS += ./include/dao/user_manager.h SOURCES += ./src/service/server_infos.cpp SOURCES += ./src/service/user_service.cpp SOURCES += ./src/business_object/user.cpp SOURCES += ./src/business_object/user_search.cpp SOURCES += ./src/dao/user_manager.cpp SOURCES += ./src/main.cpp ``` -------------------------------- ### Run QxEntityEditor in Read-Only Mode Source: https://www.qxorm.com/qxorm_en/manual_qxee.html Use the --viewer_mode parameter to open large .qxee projects without requiring a license key. ```bash QxEntityEditor --viewer_mode ``` -------------------------------- ### Execute SQL Schema Operations Source: https://www.qxorm.com/qxorm_en/faq.html Example of executing SQL commands to set column descriptions and handling database errors within a transaction scope. ```cpp if (p->getDescription() != "") // DESCRIPTION { query.exec("COMMENT ON COLUMN " + pClass->getName() + "." + p->getName() + " IS $$" + p->getDescription() + "$$ ;"); session += query.lastError(); } } } // Save current version of the database dbVersion.version = domainVersion; session.save(dbVersion); // End of "try" scope : session is destroyed => commit or rollback automatically // Moreover, a commit or a rollback unlock the process for all users } catch (const qx::dao::sql_error & err) { QSqlError sqlError = err.get(); qDebug() << sqlError.databaseText(); qDebug() << sqlError.driverText(); qDebug() << sqlError.number(); qDebug() << sqlError.type(); } } ``` -------------------------------- ### Configure Boost Paths in QxOrm.pri Source: https://www.qxorm.com/qxorm_en/faq.html Modify the QxOrm.pri file to set the include and library paths for your Boost installation. This is necessary for projects that depend on Boost. ```qmake QX_BOOST_INCLUDE_PATH = $$quote(D:/Dvlp/_Libs/Boost/1_42/include) QX_BOOST_LIB_PATH = $$quote(D:/Dvlp/_Libs/Boost/1_42/lib_shared) QX_BOOST_LIB_SERIALIZATION_DEBUG = "boost_serialization-vc90-mt-gd-1_42" QX_BOOST_LIB_SERIALIZATION_RELEASE = "boost_serialization-vc90-mt-1_42" ``` -------------------------------- ### QxEntityEditor Command-Line Parameters Documentation Source: https://www.qxorm.com/qxorm_en/manual_qxee.html This output details the global command-line parameters for QxEntityEditor, including project loading, GUI control, viewer mode, SQL logging, font and stylesheet customization, and plugin execution. ```text *** QxEntityEditor 1.2.5 application global command line parameters *** --project="" : run QxEntityEditor defining a *.qxee project to load at startup --no_gui : run QxEntityEditor without displaying the user interface --viewer_mode : run QxEntityEditor in read-only mode, this parameter can be used to open large *.qxee projects without any registered license key --log_sql : run QxEntityEditor tracing all SQL logs, this parameter logs all SQL queries executed to *.qxee SQLite database --font : define application font (due to issues since macOS Catalina 10.15) with syntax |||||| (only is required), for example : Courier New||14 --style_sheet : define application style sheet (more details here : https://doc.qt.io/qt-5/stylesheet-reference.html), for example : QWidget { background-color: black } --plugin= : run QxEntityEditor and execute automatically a plugin process (see below for specific parameters per plugin) *** Import plugin QxEEJsonImport *** --QxEEJsonImport_file="" : [Required] run QxEntityEditor loading a *.qxee project from a JSON file *** Import plugin QxEEMySQLImport *** --QxEEMySQLImport_db_ip="" : [Required] Database server address (IP) --QxEEMySQLImport_db_port="" : [Required] Port number to connect to database --QxEEMySQLImport_db_name="" : [Required] Database name --QxEEMySQLImport_filter_regexp="" : [Optional] Filter to select tables from database to import --QxEEMySQLImport_login="" : [Optional] Login to connect to database --QxEEMySQLImport_pwd="" : [Optional] Password to connect to database --QxEEMySQLImport_namespace="" : [Optional] C++ namespace where imported classes will be located --QxEEMySQLImport_delete_namespace=0/1 : [Optional] Delete all entities in the namespace before importing ``` -------------------------------- ### Connect to Server Signals in C++ Source: https://www.qxorm.com/qxorm_en/tutorial_2.html Connects to server signals for tracking server status and transactions. Requires QObject and SIGNAL/SLOT macros from Qt. ```cpp QObject::connect(m_pThreadPool.get(), SIGNAL(serverIsRunning(bool, qx::service::QxServer *)), this, SLOT(onServerIsRunning(bool, qx::service::QxServer *))); QObject::connect(m_pThreadPool.get(), SIGNAL(transactionFinished(qx::service::QxTransaction_ptr)), this, SLOT(onTransactionFinished(qx::service::QxTransaction_ptr))); m_pThreadPool->start(); ``` -------------------------------- ### Get and Print Enumeration Details in Javascript Source: https://www.qxorm.com/qxorm_en/manual_qxee.html Retrieves and logs detailed information about a specific enumeration using its ID. Ensure the enumeration ID is valid before calling. ```javascript var enumeration_id = params[15]; printEnumerationDetails(enumeration_id); //... function printEnumerationDetails(enumeration_id) { var details = helper.getEnumerationDetails(enumeration_id); if (details.length == 0) { return details; } var log = ""; log = log + "\n - enumeration_id = " + details[0]; log = log + "\n - enumeration_key = " + details[1]; log = log + "\n - enumeration_name = " + details[2]; log = log + "\n - enumeration_namespace = " + details[3]; log = log + "\n - enumeration_description = " + details[4]; log = log + "\n - enumeration_version = " + details[5]; log = log + "\n - enumeration_use_qt_enum_macro = " + details[6]; log = log + "\n - enumeration_list_of_keys = " + details[7]; log = log + "\n - enumeration_list_of_values = " + details[8]; print(log); // print value to the custom script debugger window helper.print(log); // print value to the standard output (for example, on Windows, use the 'DebugView' application to see all logs) return details; } ``` -------------------------------- ### Get Property Details with helper.getPropertyDetails Source: https://www.qxorm.com/qxorm_en/manual_qxee.html Retrieve all parameters for a given property ID. This function is useful for inspecting individual property configurations. The output is logged to the console. ```javascript function printPropertyDetails(property_id) { var details = helper.getPropertyDetails(property_id); if (details.length == 0) { return details; } var log = ""; log = log + "\n - property_id = " + details[0]; log = log + "\n - property_key = " + details[1]; log = log + "\n - property_name = " + details[2]; log = log + "\n - property_column_name = " + details[3]; log = log + "\n - property_description = " + details[4]; log = log + "\n - property_type = " + details[5]; log = log + "\n - property_version = " + details[6]; log = log + "\n - property_entity_id = " + details[7]; log = log + "\n - property_is_read_only = " + details[8]; log = log + "\n - property_is_primary_key = " + details[9]; log = log + "\n - property_is_serializable = " + details[10]; log = log + "\n - property_is_transient = " + details[11]; log = log + "\n - property_is_obsolete = " + details[12]; log = log + "\n - property_is_index = " + details[13]; log = log + "\n - property_is_unique = " + details[14]; log = log + "\n - property_allow_null = " + details[15]; log = log + "\n - property_order_level = " + details[16]; log = log + "\n - property_default_value = " + details[17]; log = log + "\n - property_format = " + details[18]; log = log + "\n - property_force_sql_type = " + details[19]; log = log + "\n - property_force_sql_alias = " + details[20]; log = log + "\n - property_min_value = " + details[21]; log = log + "\n - property_max_value = " + details[22]; log = log + "\n - property_min_length = " + details[23]; log = log + "\n - property_max_length = " + details[24]; log = log + "\n - property_reg_exp = " + details[25]; log = log + "\n - property_accessibility = " + details[26]; log = log + "\n - property_is_relationship = " + details[27]; } ``` -------------------------------- ### Export Project via Command Line Source: https://www.qxorm.com/qxorm_en/manual_qxee.html Use QxEntityEditor with the --plugin=QxEESourceControlExport option for source control-friendly exports. Specify the project file and the output directory for the export. ```bash QxEntityEditor --no_gui --project="" --plugin=QxEESourceControlExport --QxEESourceControlExport_path="" ``` -------------------------------- ### QxOrm Soft Delete SQL Query Traces Source: https://www.qxorm.com/qxorm_en/faq.html These are example SQL query traces generated by QxOrm when soft delete is enabled and various delete operations are performed. ```sql [QxOrm] sql query (93 ms) : UPDATE Bar SET deleted_at = '20110617115148615' WHERE id = :id ``` ```sql [QxOrm] sql query (0 ms) : SELECT Bar.id AS Bar_id_0, Bar.deleted_at FROM Bar WHERE Bar.id = :id AND (Bar.deleted_at IS NULL OR Bar.deleted_at = '') ``` ```sql [QxOrm] sql query (78 ms) : UPDATE Bar SET deleted_at = '20110617115148724' ``` ```sql [QxOrm] sql query (0 ms) : SELECT COUNT(*) FROM Bar WHERE (Bar.deleted_at IS NULL OR Bar.deleted_at = '') ``` ```sql [QxOrm] sql query (110 ms) : DELETE FROM Bar ``` -------------------------------- ### Run QxEntityEditor Headless with Export Source: https://www.qxorm.com/qxorm_en/manual_qxee.html Execute QxEntityEditor without the GUI (--no_gui), load a project (--project), and automatically run a C++ export plugin (--plugin). ```bash QxEntityEditor --no_gui --project="c:\test\qxBlog.qxee" --plugin=QxEECppExport ``` -------------------------------- ### Get and Set Environment Variables in Javascript Source: https://www.qxorm.com/qxorm_en/manual_qxee.html Shows how to retrieve the value of an environment variable and set a new environment variable. The `setEnvironmentVariable` function returns a boolean indicating success. ```javascript var env_var = helper.getEnvironmentVariable("QT_DIR"); var set_env_var_ok = helper.setEnvironmentVariable("MY_ENV_VAR", "my_value"); ``` -------------------------------- ### Build QxOrm on Mac Source: https://www.qxorm.com/qxorm_en/faq.html Execute these shell scripts to quickly build the QxOrm library and all tests on Mac. ```bash ./tools/osx_build_all_debug.sh ./tools/osx_build_all_release.sh ``` -------------------------------- ### Build QxOrm with MinGW on Windows Source: https://www.qxorm.com/qxorm_en/faq.html Execute these batch scripts to quickly build the QxOrm library and all tests using the MinGW compiler on Windows. ```batch ./tools/mingw_build_all_debug.bat ./tools/mingw_build_all_release.bat ``` -------------------------------- ### QxOrm Library Location Environment Variable Source: https://www.qxorm.com/qxorm_en/download.html Define the QxOrm library location using an environment variable with the same syntax as qmake, for example, $$(QXORM_DIR). This allows flexible configuration of the library path. ```bash $$(QXORM_DIR) ```