问题
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