2012-06-20 32 views
2

我寫了一個buildfile,它在某些點上將對象安裝在Sybase數據庫中。使用Sybase執行Ant sql任務時出錯

該代碼由我們的開發人員提供,我不允許修改它。 如果使用isql命令手動運行給定的SQL,它將起作用。

這是安裝一個給定的對象構建文件的一部分:每當我試圖運行包含雙引號的腳本(「)時間

<sql 
    driver="${db.driver}" url="${db.url}" userid="${db.user}" 
    password="${db.password}" src="${file}" 
    print="true" delimiter="go" delimitertype="row" 
    classpathref="sybase.lib.path" output="${file}.out" 
    errorproperty="install.failed" onerror="continue" keepformat="true" /> 

雖然解決方案工作的大部分時間,它失敗

例如,如果SQL腳本包含這樣的事情:

declare @var varchar(30) 
set @var = "SOME STRINGS" 

失敗與錯誤:

[sql] com.sybase.jdbc3.jdbc.SybSQLException: Invalid column name 'SOME STRINGS'. 

有人解決了這個問題嗎?

我已閱讀Ant sql task的文檔。 我正在使用Ant版本1.8.2。

我有以下JDBC驅動程序測試:

  • com.sybase.jdbc3.jdbc.SybDriver
  • net.sourceforge.jtds.jdbc.Driver
+0

你可以嘗試設置escapeprocessing假 – Matteo

+0

@Matteo我已經試過了,我也得到了同樣的錯誤。 – Claudio

+0

最後我取代爲下列句子使用SQL任務標記的: \t \t \t \t \t \t \t \t \t \t \t \t \t \t Claudio

回答

0

,在會話建立它的默認設置爲QUOTED_IDENTIFIER設置爲true。我相信你可以與服務器設置調整這一點,但在任何情況下,你可以通過附加這的URL會話設置,如果:

?SQLINITSTRING=set quoted_identifier off 

這樣的URL可能看起來像什麼樣子:

"jdbc:sybase:Tds:<server>:<port>/<db>?SQLINITSTRING=set quoted_identifier off" 

如果您有多個設置,請使用&字符&加入。見also

quoted_identifier

determines whether Adaptive Server recognizes delimited identifiers within double quotation marks. By default, quoted_identifier is off and all identifiers must either:

  • Conform to the rules for valid identifiers.

  • Be enclosed in brackets.

If you use set quoted_identifier on, double quotation marks behave the way brackets do, and you can use table, view, and column names that begin with a nonalphabetic character, including characters that would not otherwise be allowed, or are reserved words, by enclosing the identifiers within double quotation marks. Delimited identifiers cannot exceed 28 bytes, may not be recognized by all front-end products, and may produce unexpected results when used as parameters to system procedures.

When quoted_identifier is on, all character strings enclosed within double quotes are treated as identifiers. Use single quotes around character or binary strings.