Delphi Interbase Sql 转换为 Sql Server 和 Oracle

发布于 2024-09-26 13:44:53 字数 841 浏览 13 评论 0原文

我有一个使用数据库的delphi应用程序 间基/火鸟。为了查阅和写入数据,我使用 InterBase 组件选项板(IBTable、IBQuery、IBDataset)。我是 正在将我的系统转换为 sqlserver / Oracle,但我有 在运行时使用 SQL 指令组装的数千个查询 特定数据库InterBase/Firebird。有谁知道 任何生成 Parse 命令的组件或工具 Interbase -> SQL Server 或 Interbase->甲骨文?

我需要的是这样的:

Var
  Parser: TParser;
  OutputSql: String;
Begin
   Parser := TParser.Create();
   Parser.Text := 'SELECT FIRST 10 CITYNAME FROM TBCITY';

   if Firebird then
      OutPutSql := Parser.ParseTo('SQLSERVER');

   if Oracle then
      OutPutSql := Parser.ParseTo('ORACLE');

   ComponentAccess.Sql.Text := OutPutSql;
   ...

结果:

Parser.ParseTo('SQLSERVER');

将是

“从 TBCITY 选择前 10 个城市名称”

并且

Parser.ParseTo('ORACLE');

将是

“从 TBCITY 选择城市名称,其中 ROWNUM <= 10”

i have a delphi application which uses database
interbase / firebird. To consult and write data I use the
InterBase components palette (IBTable, IBQuery, IBDataset). I'm
performing the conversion of my system to sqlserver / Oracle but i have
thousands of queries that are assembled at runtime with SQL Instructions
Specific of database InterBase/Firebird. Anyone know
any component or tool that makes Parse commands Interbase -> SQL Server or Interbase-> Oracle ?

what i need its something like:

Var
  Parser: TParser;
  OutputSql: String;
Begin
   Parser := TParser.Create();
   Parser.Text := 'SELECT FIRST 10 CITYNAME FROM TBCITY';

   if Firebird then
      OutPutSql := Parser.ParseTo('SQLSERVER');

   if Oracle then
      OutPutSql := Parser.ParseTo('ORACLE');

   ComponentAccess.Sql.Text := OutPutSql;
   ...

The Result Of:

Parser.ParseTo('SQLSERVER');

Will Be

'SELECT TOP 10 CITYNAME FROM TBCITY'

And

Parser.ParseTo('ORACLE');

Will Be

'SELECT CITYNAME FROM TBCITY WHERE ROWNUM <= 10'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

执着的年纪 2024-10-03 13:44:53

1)据我所知,像AnyDAC这样的库具有SQL抽象语法。也许您可以在 SQL 命令文本中使用此功能。

2) 如果您在运行时组装 SQL,那么为什么不直接这样编写代码:

if Firebird then
  SQL.Add(...)
else if Oracle then
  SQL.Add(...)
...

1) AFAIK, libraries like AnyDAC, have SQL abstraction syntax. May be you can use this feature in your SQL command text.

2) If you are assembling your SQL at runtime, then why not just code like that:

if Firebird then
  SQL.Add(...)
else if Oracle then
  SQL.Add(...)
...
彡翼 2024-10-03 13:44:53

我们已经在 AnyDAC 中实现了这一点。您可以使用 LIMIT 转义函数:

ADQuery1.Sql.Text := 'SELECT {LIMIT(10)} CITYNAME FROM TBCITY';

AnyDAC 会自动将其转换为目标 DBMS 语法。

We have implemented that in AnyDAC. You may use LIMIT escape function:

ADQuery1.Sql.Text := 'SELECT {LIMIT(10)} CITYNAME FROM TBCITY';

AnyDAC will automatically translate that into target DBMS syntax.

煞人兵器 2024-10-03 13:44:53

我使用了 Components4Developers 中的 kbmMW,它有一组抽象的查询,提供宏等来启用 /easier/跨数据库工作,但主要用于客户端/服务器使用。 Devart 也做了一套很好的跨数据库组件 - 我们使用他们的SQL Server 集。然而,我完成的每个项目最终都会为每个数据库编写一组特定的 SQL 脚本。显然,简单的选择内容有相当多的共同点,但不同数据库的功能集通常差异太大,无法轻松使用。

我最终得到的结果与 @oodesigner 的响应类似,只是我们使用 $ifdef 并在单独的 const 单元中定义 SQL 字符串。

{$ifdef USE_MSSQL}
  QUERY_ONE = 'select blah blah blah...';
{$else}
  QUERY_ONE = 'select nah nah nah...';
{$endif}

然后在主单元中进行简单的分配

SQL.Text := QUERY_ONE;

SQL.Text := Format(QUERY_TWO, [some_very_carefully_quoted_stuff_or_use_params]);

不知道任何可以自动化或解析它的东西。这样做的问题是,您仍然必须仔细检查每个查询,因为转换时很容易出错。

I have used kbmMW from Components4Developers and it has an abstracted set of queries that provide macros and the like to enable /easier/ cross database work but it's mainly for client/server use. Devart also do a good set of cross database components - we use their SQL Server set. However, each project I've done I've ended up writing a specific set of SQL scripts for each database. Obviously there is a fair bit of common ground for simple select stuff but the feature sets of the different databases are often too different to make it easily workable.

I end up with something similar to @oodesigner's response except that we use $ifdef and define my SQL strings in a separate const unit.

{$ifdef USE_MSSQL}
  QUERY_ONE = 'select blah blah blah...';
{$else}
  QUERY_ONE = 'select nah nah nah...';
{$endif}

Then in the main unit a simple assignment

SQL.Text := QUERY_ONE;

or

SQL.Text := Format(QUERY_TWO, [some_very_carefully_quoted_stuff_or_use_params]);

Don't know of anything that would automate or parse it. And the problem with that is that you still have to go through and check every single query because it's too easy to get things wrong when converting.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文