#1 2014-02-03 13:46:55

edismo
Member
From: Brazil
Registered: 2013-10-04
Posts: 34

Filtering with property of set type

I need help with ORM, do not know filtering with property of set type.

See a Sample:

TMySet = (msOne, msTwo);
TMySets = set of TMySet;

TSample = class(TSQLRecord)
private
  FMySets = TMySets;
published
  property   MySets = TMySets read FMySets write FMySets;
end;
...
var
  Sample: TSample;
begin
  Sample := TSample.CreateAnFillPrepare(SQLrest, 'MySets = ?, [Byte(msOne)]';

See records in table:

id | MySets
----------------
1|1 // msOne
2|2 // msTwo
3|3 // msOne and msTwo

I need to return two records when where clause is msOne or msTwo (bits 1 and 3 or 2 and 3).

In my sample return only one record, but not corresponding with where.
What do I need to return two records?

Offline

#2 2014-02-03 13:48:50

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,273
Website

Re: Filtering with property of set type

You need to use binary math:

var aSet = TMySets;

aSet := [msOne,msTwo];
Sample := TSample.CreateAnFillPrepare(SQLrest, 'MySets & ? = ?, [Byte(aSet),Byte(aSet)]);

Offline

#3 2014-02-03 15:29:18

edismo
Member
From: Brazil
Registered: 2013-10-04
Posts: 34

Re: Filtering with property of set type

That's it
Thanks AB.

Offline

Board footer

Powered by FluxBB