QxOrm admin wrote:select * from blog,author where blog.author_id = author.author_id and author.name like '%xxx%'
Just write something like this :
- Code: Select all
QSqlError daoError = qx::dao::fetch_by_query_with_relation("author", qx_query().where("author.name").like("xxx"), my_blog);
I wrote code like this:
- Code: Select all
qx::QxSqlQuery query;
query.where("AccountGroup.name").like(groupName)
.and_("AccountType.name").like(typeName);
AccountList accountList;
daoError = qx::dao::fetch_by_query_with_all_relation(query, accountList);
QxOrm generate sql:
SELECT Account.id AS Account_id_0,
Account.user_name AS Account_user_name_0,
Account.password AS Account_password_0,
Account.cookie AS Account_cookie_0,
Account.status AS Account_status_0,
Account.create_date AS Account_create_date_0,
Account.group_id AS Account_group_id_0,
AccountGroup_1.id AS AccountGroup_1_id_0,
AccountGroup_1.name AS AccountGroup_1_name_0,
Account.type_id AS Account_type_id_0,
AccountType_2.id AS AccountType_2_id_0,
AccountType_2.name AS AccountType_2_name_0,
AccountType_2.script AS AccountType_2_script_0,
Mail_3.id AS Mail_3_id_0,
Mail_3.account_id AS Mail_3_account_id_0,
Mail_3.system_id AS Mail_3_system_id_0,
Mail_3.is_replied AS Mail_3_is_replied_0,
Mail_3.is_read AS Mail_3_is_read_0,
Mail_3.has_attachment AS Mail_3_has_attachment_0,
Mail_3.size AS Mail_3_size_0,
Mail_3.sender AS Mail_3_sender_0,
Mail_3.subject AS Mail_3_subject_0,
Mail_3.content AS Mail_3_content_0,
Mail_3.sent_date AS Mail_3_sent_date_0,
Mail_3.received_date AS Mail_3_received_date_0
FROM Account
LEFT OUTER JOIN AccountGroup AccountGroup_1 ON AccountGroup_1.id = Account.group_id
LEFT OUTER JOIN AccountType AccountType_2 ON AccountType_2.id = Account.type_id
LEFT OUTER JOIN Mail Mail_3 ON Mail_3.account_id = Account.id
WHERE AccountGroup.name LIKE :AccountGroup_name_1_0 AND AccountType.name LIKE :AccountType_name_3_0There is an error occured: "Parameter count mismatch". The correct sql should be:
SELECT Account.id AS Account_id_0,
Account.user_name AS Account_user_name_0,
Account.password AS Account_password_0,
Account.cookie AS Account_cookie_0,
Account.status AS Account_status_0,
Account.create_date AS Account_create_date_0,
Account.group_id AS Account_group_id_0,
AccountGroup_1.id AS AccountGroup_1_id_0,
AccountGroup_1.name AS AccountGroup_1_name_0,
Account.type_id AS Account_type_id_0,
AccountType_2.id AS AccountType_2_id_0,
AccountType_2.name AS AccountType_2_name_0,
AccountType_2.script AS AccountType_2_script_0,
Mail_3.id AS Mail_3_id_0,
Mail_3.account_id AS Mail_3_account_id_0,
Mail_3.system_id AS Mail_3_system_id_0,
Mail_3.is_replied AS Mail_3_is_replied_0,
Mail_3.is_read AS Mail_3_is_read_0,
Mail_3.has_attachment AS Mail_3_has_attachment_0,
Mail_3.size AS Mail_3_size_0,
Mail_3.sender AS Mail_3_sender_0,
Mail_3.subject AS Mail_3_subject_0,
Mail_3.content AS Mail_3_content_0,
Mail_3.sent_date AS Mail_3_sent_date_0,
Mail_3.received_date AS Mail_3_received_date_0
FROM Account
LEFT OUTER JOIN AccountGroup AccountGroup_1 ON AccountGroup_1.id = Account.group_id
LEFT OUTER JOIN AccountType AccountType_2 ON AccountType_2.id = Account.type_id
LEFT OUTER JOIN Mail Mail_3 ON Mail_3.account_id = Account.id
WHERE AccountGroup_1.name LIKE :AccountType_2.name AND AccountType_2_name_0 LIKE :AccountType_name_3_0I can write code like this to fix it, but I think it's not a good way,
- Code: Select all
qx::QxSqlQuery query;
query.where("AccountGroup_1.name").like(groupName)
.and_("AccountType_2.name").like(typeName);
How about your opinion?