如何逃避冒号(:)字符在执行原生SQL查询使用NHibernate Informix数据库? [英] How to escape colon (:) character while executing native SQL queries against an Informix database using NHibernate?

查看:550
本文介绍了如何逃避冒号(:)字符在执行原生SQL查询使用NHibernate Informix数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图执行一套针对Informix数据库原生SQL查询,使用NHibernate创建查询。然而,NHibernate的被设置为更改查询,如果它包含冒号(它们理应保留字符)等等查询失败。这是原生SQL查询的示例:

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;

这NHibernate的转变为这个,之前执行查询,

which NHibernate transforms into this, before executing the query,

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

在这一点的Informix抛出无效的语法错误。已经有一些关于这个问题的讨论,但没有合理的答复或解决方法如下所示。

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.

我想知道是否有一种方式来逃避冒号(通过更改设置或配置在NHibernate的,或不同执行查询)。我不会介意改变查询的Informix,但现在看来,这将最终证明试图执行在他们的其他类型的用冒号的查询时,麻烦。

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!

推荐答案

我建议使用转换符号不使用冒号:

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

SELECT FIRST CAST(id AS INTEGER) INTO variable;

处理DATETIME和区间文字将较困难。

Handling DATETIME and INTERVAL literals will be harder than that.

这篇关于如何逃避冒号(:)字符在执行原生SQL查询使用NHibernate Informix数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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