Comments (6)
Hi, there is an example for you:
auto q = _db.tbl.query();
if (some_candidate)
q = q->where( Table::fieldField() == value);
if (some_other_candidate)
q = q->where( Table::field2Field() == value2);
//do somthing with q->toList();
If this does not solve your problem let me know
from nut.
Thank you for the reply !
YES. I found this on my own when I was looking for a solution. I figured the difference between setWhere and where functions.
BUT "where" function always use "&&" operator while combining phrases. However, it would be better if I had a way to create more flexible programmatic queries. Here is an example:
The user might want to search for entries that match:
SELECT * FROM TBL WHERE ID=1234 OR ID=6789;
currently I can only combine with AND operator:
SELECT * FROM TBL WHERE ID = 1234 AND ID = 6789;
which doesnt make sense in this case. Because it is impossible.
Also the library should allow me to combine queries like below:
- select * from tbl where ID=2703828 or ID=8080912 and TestDate > "2020-10-16 22:59:00";
- select * from tblReports where (ID=2703828 or ID=8080912) and TestDate > "2020-10-16 22:59:00";
These two queries return different results because 2nd one contains parentheses.
Currently I am generating the query so that it only contains AND conditions. Then I filter results in returned QList once again. It is ok in small db. But im afraid it would be very slow on large db.
Looking to hear from you. Regards...
from nut.
Ok, you can create ConditionalPhrase separately, eg:
auto p = Table::nameField() == "1";
p ||= Table::lastNameField() == "2";
auto list = _db.tbl.query()->where(p)->toList();
from nut.
This doesn't compile on my code. I'm using Nut version you used in OrmTest repo:
Nut commit hash: Commit 6ce50e2 by Jack Lilhammers, 07/07/2020 05:50 PM
Serializer commit hash: Commit b0194da3 by Miklós Márton, 06/13/2020 12:00 AM
my code is:
ConditionalPhrase cp;
cp ||= Report::patientIdField() == id;
error is: expected primary-expression before ‘=’ token
cp ||= (Report::patientIdField() == id);
^
Maybe you didn't implemented this operator overload in this commit yet? If there is stable version with better features, can you guide me how to use it? For example, can you update OrmTest repo such that it uses updated version of Nut? OrmTest repo helped me a lot to understand how to use this lib.
from nut.
Hi @yusufmk
I've tested and that is my mistake to write code without test in comment!
please change it to:
auto p = Table::nameField() == "1";
p = p || Table::lastNameField() == "2";
auto list = _db.tbl.query()->where(p)->toList();
None: New version of nut currently is under development in dev branch is a Qt module, please continue with it, It will be merged into master branch soon.
from nut.
!!! SOLVED !!!
Thank you! This works.
from nut.
Related Issues (20)
- Composite keys HOT 3
- Wiki request for pages Status, Getting Started, and Example HOT 2
- QByteArray not stored correctly HOT 4
- Foreign key objects in Nut::Row HOT 2
- 编译错误
- Q_OUTOFLINE_TEMPLATE Row<T> Query<T>::first() return nullptr error HOT 2
- tst_basic sample Nothing created,just __change_logs table created HOT 4
- Add support for Mongo DB
- unstable inserting or updating fields=false in release HOT 1
- NUT_INFO in NUT_DECLARE_TABLE and NUT_DECLARE_FIELD ...not work HOT 3
- Getting started
- class not registered with qt meta object HOT 2
- Remove Issue
- Custom Type converter. HOT 1
- ERROR with make HOT 1
- Fix typo in NUT_PRIMARY_AUTO_INCREMENT
- It make fail with "sqlserializer.h: No such file or directory" HOT 1
- Linking problem (undefined reference) HOT 2
- [1 to many] relations implementation HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nut.