[fpc-pascal] Create dynamic SQL according to available params

Martin Schreiber mse00000 at gmail.com
Thu Apr 7 17:53:53 CEST 2016


On Thursday 07 April 2016 16:20:16 Santiago A. wrote:
> El 07/04/2016 a las 14:00, Luiz Americo Pereira Camara escribió:
> > I enconter the following pattern frequently (simplified):
> >
> > SQL:
> > Select * From Customers Where FieldX = 1
> >
> > Later i need a similar query that uses a different filter like
> >
> > Select * From Customers Where FieldX = 1 and FieldY = :paramy
>
> I remember a component of RxLib named TRxQuery. It had a published
> property "macros" of type TParams, so you could write this sql
>
> Select * From Customers Where FieldX = 1 and (%extrafilter).

In MSEgui SQL properties are of type TSQLStringList. TSQLStringList has a 
property "Macros" which is an array of TSQLMacroItem. TSQLMacroItem.Value 
inherits from TSQLStringList, so it is possible to build a macro tree which 
items can be accessed by a name path (TMacroProperty.ItemByNames()).

"
select ${fields} from ${table} where ${filter}
"
in example
http://mseide-msegui.sourceforge.net/pics/sqlmacros.png

expands to
"
select FIELD1 from TABLE1 where FIELD1 = 'abc'
"

Martin



More information about the fpc-pascal mailing list