QxOrm icon indicating copy to clipboard operation
QxOrm copied to clipboard

NOT Operator

Open gianks opened this issue 2 years ago • 4 comments

Hi, sorry if I am missing something here but i could not find any reference to the NOT operator for composing queries. References:

  • https://www.qxorm.com/qxorm_en/manual.html#manual_360
  • https://www.sqltutorial.org/sql-not/

Is there a reason why it's not implemented (or maybe not documented)?

Thanks a lot

gianks avatar Nov 16 '22 01:11 gianks

Hello,

There are several NOT methods in the qx:QxSqlQuery class :

- virtual QxSqlQuery & notLike(const QString & val);
- virtual QxSqlQuery & isNotEqualTo(const QVariant & val);
- virtual QxSqlQuery & notIn(const QVariantList & values);
- virtual QxSqlQuery & notIn_Select(const QxSqlQuery & query);
- virtual QxSqlQuery & isNotEqualTo_Select(const QxSqlQuery & query);
- virtual QxSqlQuery & isNotNull();
- virtual QxSqlQuery & isNotBetween(const QVariant & val1, const QVariant & val2);

And if something is missing, you can add custom SQL with : virtual QxSqlQuery & freeText(const QString & text, const QVariantList & values = QVariantList());

Is there something missing for you ?

QxOrm avatar Nov 18 '22 13:11 QxOrm

Hello, I've looked a little more into the issue and realized that the way queries are build require the NOT operator to be built in every possible command, as you suggested.

What about:

- virtual QxSqlQuery & and_not(const QString & val);
- virtual QxSqlQuery & and_not_OpenParenthesis(const QString & val);
- virtual QxSqlQuery & or_not(const QString & val);
- ...

Could you please evaluate to add such methods to allow arbitrary usage of the not operator as you did already for the methods you suggested?

Otherwise you could add generic methods as: - virtual QxSqlQuery & not(const QString & val); - virtual QxSqlQuery & not_OpenParenthesis(const QString & val);

But then QxOrm shall also allow the usage of and/or/in/etc. without a parameter, as such: query.and().not("COL").isWhatever()...

Just proposals, not sure about complexity. To be clear i could still find my way around this limitation but forced me to rewrite some queries from a more "human readable" form to a equally working and yet less understandable version.

gianks avatar Nov 18 '22 19:11 gianks

If you try : qx::QxSqlQuery::freeText("NOT") : does it work for you for all your cases ? Because in this case, I can just add a "not()" method which just calls freeText("NOT").

QxOrm avatar Nov 23 '22 09:11 QxOrm

I'll give it a try, it might work, I am not sure it will suffice in all cases but let me see.

gianks avatar Nov 23 '22 10:11 gianks