#1 2024-07-02 04:47:45

bigheart
Member
Registered: 2014-08-01
Posts: 49

how to select field for set of enumeration with sqlite

Hello,

The orm field is set type as below:

TTestColor = (Red,Green,Blue);
TTestColors = set of TTestColor;

TTestOrm = class(Torm)
  FColors: TTestColors;
property
  Colors: TTestColors read FColors write FColors;
end;

....

LTestOrm.Colors := Red + Blue;

then Is it possible to select the set field which included set value?

Likewise "Select Colors from TestOrm where colors in [Red]"

Offline

#2 2024-07-02 06:47:49

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

Re: how to select field for set of enumeration with sqlite

Not directly in SQL or ORM because the set is stored as integer, and the DB itself doesn't know anything about the set definition.

But you can search at binary/number level using SQL Bitwise Operators:

var col: TTestColors;
begin
  col := [Red];
  table := orm.MultiFieldValues(TTestOrm, '*', '(colors & ?) <> 0', [byte(col)]);

Of course, it can't use an index, due to the nature of how indexes work.

Offline

Board footer

Powered by FluxBB