蚂蚁SQL INSERT语句上的失败“ - ”字符串。解决方法吗? [英] ant sql insert statement fails on '--' strings. workaround?

查看:150
本文介绍了蚂蚁SQL INSERT语句上的失败“ - ”字符串。解决方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文

我们正在改变我们的安装脚本,以使用Ant的SQL任务和JDBC而不是专有的SQL客户端的sqlplus(Oracle)和OSQL(MSFT)。

We're changing our install scripts to use ant's "sql" task and jdbc rather than proprietary sql clients sqlplus (oracle) and osql (msft).

更新:增加了更多的内容。我们的基础数据(种子数据)组成,内容包含供应商中立.sql文件的集合(即​​,无论是在Oracle和MSSQL工作)的SQL语句。

Updated: added more context. Our "base data" (seed data) consists of a collection of .sql files containing "vendor-neutral"(i.e. works both in oracle and mssql) sql statements.

问题

脚本运行正常,但有一个例外:

The scripts run fine, with one exception:

这个SQL在Oracle中失败。具体而言,一些(蚂蚁或JDBC驱动程序)对待破折号/连字符注释的开始 - 即使它们嵌入在一个字符串。需要注意的是相同的SQL正常工作与蚂蚁/ SQL和微软的JDBC驱动程序。

This sql fails in Oracle. Specifically, something (ant or jdbc driver) treats the dashes/hyphens as "beginning of a comment"--even though they are embedded in a string. Note that the same sql works fine with ant/sql and microsoft's jdbc driver.

INSERT INTO email_client (email_client_id,generated_reply_text) VALUES(100002,'----- Original Message -----');

相关的Bug

蚂蚁虫出现识别问题。因为它仍然打开(8年后),我不会很快希望修复。然而,因为这个问题只出现在预言,它可位于与驱动器。

This ant bug appears to identify the problem. As it's still open (after 8 years), I'm not hoping for a fix soon. However, because the problem appears only in oracle, it may lie with the driver.

Oracle驱动程序:JDBC瘦驱动程序,版本10.2.0.1.0

The oracle driver: jdbc thin driver, version 10.2.0.1.0

问题

没有人有这两个MSSQL和甲骨文工作的解决方法吗? (如更换有问题的线来定义一个转义字符?我没有看到在插入SQL92语法的逃离')

Does anyone have a workaround which works in both mssql and oracle? (e.g. changing the offending lines to define an escape character? I don't see an 'escape' on the 'insert' sql92 syntax)

感谢

推荐答案

查看SQLEXEC'源并打开详细日志记录后,我发现了一个解决方法:

After viewing the 'SQLExec' source and turning on verbose logging, I found a workaround:

解决方法

如果SQL语句包括包含字符串' - ',放在下一行分隔符(分号)

此失败

INSERT INTO email_client (email_client_id,generated_reply_text) VALUES(100002,'----- Original Message -----');

此操作成功

注意,分号是一个单独的行

Note that semi-colon is on a separate line

INSERT INTO email_client (email_client_id,generated_reply_text) VALUES(100002,'----- Original Message -----')
;

详细信息

打开详细日志记录,我看到,当蚂蚁整个问题的SQL语句来了,它实际上在一次通过三个SQL语句的JDBC驱动程序。违规语句,下一个语句(其中也包括一个嵌入式 - ),以及随后的声明(其中不包括嵌入的 - )。

Turning on verbose logging, I saw that when Ant came across the offending sql statement, it actually passed three sql statements in at once to the jdbc driver. The offending statement, the next statement (which also included an embedded '--'), and the subsequent statement (which did not include an embedded '--').

我给蚂蚁code看一眼,并没有看到任何明显的错误。因为我不打算修补蚂蚁,我找了一个解决方法。

I gave the Ant code a quick glance and didn't see any obvious errors. Since I wasn't planning to patch Ant, I looked for a workaround.

与它调整我发现,如果我只是感动的分隔符(分号)为嵌入式报表的下一行' - ',脚本成功执行

Tweaking with it I found that if I simply moved the delimiter (semicolon) to the next line for the statements with embedded '--', the scripts executed successfully.

感谢大家在体重

这篇关于蚂蚁SQL INSERT语句上的失败“ - ”字符串。解决方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆