SQL Abstraction with FireDAC

2

I would like to know how best to work with SQL abstraction in a multi-banking system. For example: Firebird : SELECT SUBSTRING(nome FROM 5 FOR 8) FROM clientes
Oracle : SELECT SUBSTR(nome,5,8) FROM clientes
How to make the application, after identifying which bank is being used, prepare the SQL statement correctly? I know there are several ways to do this. But technically what is the best way to do it or the most advised?

    
asked by anonymous 23.02.2017 / 18:01

1 answer

2

If you use 2 different connections with the same connection component, you can use Try , following example:

try
  //Tenta efetuar a rotina pensando no Firebird
  SELECT SUBSTRING(nome FROM 5 FOR 8) FROM clientes
except
  //Deu erro no Firebird, então tenta no Oracle
  SELECT SUBSTR(nome,5,8) FROM clientes  
end;

And if you can already identify which bank connected you can do without fear:

if (Banco = Firebird) then
begin
  SELECT SUBSTRING(nome FROM 5 FOR 8) FROM clientes
end
else if (Banco = Oracle) then
begin
  SELECT SUBSTR(nome,5,8) FROM clientes
end;

Both ways will satisfy you, but I use the second way, therefore, of space for new connections! And in my view, it's the right way!

    
01.03.2017 / 12:10