Erlang ODBC参数查询带空参数

发布于 2024-08-24 18:12:55 字数 604 浏览 2 评论 0原文

是否可以将空值传递给参数查询?例如

Sql = "insert into TableX values (?,?)".
Params = [{sql_integer, [Val1]}, {sql_float, [Val2]}].

% Val2 may be a float, or it may be the atom, undefined

odbc:param_query(OdbcRef, Sql, Params).

,现在,如果在尝试匹配 sql_float 时 Val2 未定义,odbc:param_query/3 当然会抱怨,但我的问题是......是否可以使用参数化查询,例如:

Sql = "insert into TableY values (?,?,?,?,?,?,?,?,?)".

使用任何空参数?我有一个用例,通过插入或更新将大量实时数据转储到数据库中。我正在更新的一些表有十几个左右可为空的字段,并且我不能保证所有数据都会在那里。

将每个查询的 SQL 连接在一起、检查空值似乎很复杂,而且是错误的方法。

对每个排列进行参数化查询根本不是一种选择。

任何想法或想法都会很棒!谢谢你!

Is it possible to pass null values to parameter queries? For example

Sql = "insert into TableX values (?,?)".
Params = [{sql_integer, [Val1]}, {sql_float, [Val2]}].

% Val2 may be a float, or it may be the atom, undefined

odbc:param_query(OdbcRef, Sql, Params).

Now, of course odbc:param_query/3 is going to complain if Val2 is undefined when trying to match to a sql_float, but my question is... Is it possible to use a parameterized query, such as:

Sql = "insert into TableY values (?,?,?,?,?,?,?,?,?)".

with any null parameters? I have a use case where I am dumping a large number of real-time data into a database by either inserting or updating. Some of the tables I am updating have a dozen or so nullable fields, and I do not have a guarantee that all of the data will be there.

Concatenating a SQL together for each query, checking for null values seems complex, and the wrong way to do it.

Having a parameterized query for each permutation is simply not an option.

Any thoughts or ideas would be fantastic! Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何必那么矫情 2024-08-31 18:12:55

您可以使用原子 null 来表示 null 值。例如:

Sql = "insert into TableX values (?,?)".
Params = [{sql_integer, [Val1]}, {sql_float, [null]}].

You can use the atom null to denote a null value. For instance:

Sql = "insert into TableX values (?,?)".
Params = [{sql_integer, [Val1]}, {sql_float, [null]}].
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文