How to escape colon (:) character while executing native SQL queries against an Informix database using NHibernate?

故事扮演 提交于 2020-01-04 18:17:26

问题


I'm trying to execute a set of native SQL queries against an Informix database, using NHibernate to create the queries. However, NHibernate is set to change the query if it contains colons (they are supposedly reserved characters), and so the query fails. This is a sample of the native SQL query:

    CREATE PROCEDURE procedure_name()
    ...
    SELECT FIRST id :: INTEGER INTO variable
    ...
    END PROCEDURE;

which NHibernate transforms into this, before executing the query,

    CREATE PROCEDURE procedure_name()
    ...
    SELECT FIRST id ? INTEGER INTO variable
    ...
    END PROCEDURE;

At which point Informix throws an Invalid syntax error. There has been some discussion on the subject, however no plausible response or workaround are shown.

I would like to know if there is a way to escape to colon character (by changing a setting or configuration in NHibernate, or executing the query differently). I wouldn't mind changing the query for Informix, but it seems it will eventually proved troublesome when trying to execute other types of queries with colons in them.

Any ideas or suggestions are welcomed. Thanks!


回答1:


I suggest using the cast notation that doesn't use colons:

SELECT FIRST CAST(id AS INTEGER) INTO variable;

Handling DATETIME and INTERVAL literals will be harder than that.



来源:https://stackoverflow.com/questions/9845130/how-to-escape-colon-character-while-executing-native-sql-queries-against-an

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!