本文介绍了是C ++ OTL SQL数据库库下使用参数化查询,还是字符串concat?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找用于C ++数据库访问的OTL(Oracle,Odbc和DB2-CLI模板库)。我不确定我传递的查询是否转换为基础数据库的参数化查询,或者它基本上只是将所有参数连接到一个大字符串并将查询传递到数据库。我看到你传递给它的查询可以包括参数的类型信息,但是那时和查询命中数据库之间发生了什么,我不能告诉。

I've been looking at the OTL (Oracle, Odbc and DB2-CLI Template Library) for C++ database access. I'm unsure of whether the query I pass in is converted to a parameterized query for the underlying database, or if it's basically just concatenating all the arguments into one big string and passing the query to the database that way. I see that the query you pass in to it can include type information for the arguments, but what happens between then and the query hitting the database, I can't tell.

推荐答案

OTL作者对我的电子邮件的回复:



OTL将带有占位符的查询传递到DB API图层。对于不同的数据库类型,实际绑定变量的命名约定是不同的。对于Oracle,

OTL author's response to my e-mail:

OTL passes queries with placeholders into the DB API layers. The naming conventions for actual bind variables are different for different DB types. Say, for Oracle,

SELECT * FROM staff WHERE fname=:f_name<char[20]>

将翻译为:

SELECT * FROM staff WHERE fname=:f_name

主机变量绑定调用。

对于MS SQL Server或DB2,同样的SELECT将如下所示:

For MS SQL Server, or DB2, the same SELECT would look like this:

SELECT * FROM staff WHERE fname=?

在本手册中,您不能同时拥有多个同名的占位符MS SQL,DB2。具有占位符/绑定变量的SQL语句创建起来相对昂贵,因此如果通过otl_stream实例化参数化的SQL,则尽可能多地重用该流是有意义的。

It's described in the manual that you can't have a placeholder with the same name more than once for MS SQL, DB2. SQL statements with placeholder / bind variables are relatively expensive to create, so if you instantiate an parameterized SQL via an otl_stream, it makes sense to reuse the stream as much as you can.

如果您有更多问题或者如何改进OTL手册的建议,请随时给我发送电子邮件。

If you have more questions, or suggestions on how I can improve the OTL manual, feel free to email me.

干杯,
谢尔盖

Cheers,Sergei

pheadbaq写道:

pheadbaq wrote:

您好,我一直在评估C ++ DB库最近用作ORM库的基础我希望建立,并已经越来越多地向OTL。它看起来很不错的方式,似乎它会满足大部分的需求,我有。我只有一个持续的问题,我不能通过阅读文档似乎澄清。 OTL是否将参数化查询传递给底层DBMS,还是将传递给OTL流的参数和查询连接到单个字符串中并传递给DBMS?

Hi, I've been evaluating C++ DB libraries recently to use as a base for an ORM library I wish to build, and have been gravitating more and more towards the OTL. It looks very nice by the way, and seems like it would meet most of the needs I have. I just have one lingering question that I can't seem to clarify by reading the docs. Does OTL pass a parameterized query on to the underlying DBMS, or is it concatenating the arguments and query I pass to the OTL stream into a single string and hand that to the DBMS?

换句话说,如果我手动OTL这个MSSQL查询,连同字符串Bob作为绑定变量:

In other words, if I hand OTL this MSSQL query, along with with the string "Bob" as the bind variable:

SELECT * FROM staff WHERE fname = :f_name<char[20]>

OTL解析器是否产生:

Does the OTL parser produce this:

SELECT * FROM staff WHERE fname = 'Bob'

这:

SELECT * FROM staff WHERE fname = @f_name

以及我的字符串作为参数

along with my string as a parameter

我已经将这个问题发布到StackOverflow.com如果你关心回应:

I've posted this same question to StackOverflow.com if you care to respond there:http://stackoverflow.com/questions/3149974/is-c-otl-sql-database-library-using-parameterized-queries-under-the-hood-or-st

感谢您的时间

这篇关于是C ++ OTL SQL数据库库下使用参数化查询,还是字符串concat?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 22:51