SQL abstraction with Firedac

Asked

Viewed 102 times

2

I would like to know how best to work with abstraction of SQL in a multi-bank 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 instruction SQL correctly?
I know there are several ways to do this. But technically what is the best way to do it or the most advised way?

1 answer

2


If you use 2 different connections with the same connection component, you can use the 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 connected bank 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;

The two forms will satisfy you, but I use the second form, because, space for new connections! And in my view, it is the right way!

  • Thank you for your answer, but in my search for the best way to do that, I would like to not have to write the same code twice. If you value security, I think your answer is the best one, but if you value the speed of development, it becomes complicated. But I think for now is what we can do.

  • Exactly, as there is no standard between the parameters of the "Abstraction" of the two mentioned banks there is no option, we have to write again! If a new alternative appears I edit the answer!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.