通过MySQL-X-Devapi在C++中插入MySQL内置函数的结果?
我正在使用MySQL-X-DEVAPI,需要将行插入表格,并在列中添加服务器的 unix_timestamp()
:
sql_client_.getSession().getDefaultSchema()
.getTable("event")
.insert("title", "time")
.values("event title", "UNIX_TIMESTAMP()")
.execute();
此代码为我提供: CDK错误:不正确的整数值'UNIX_TIMESTAMP()'for column'Time'在第1列中
我该如何使用Xdevapi(不是需要SQL String的SQL命令)?
我可以在更新表时使用 mysqlx :: expr(“ unix_timestamp()”)
set 函数。同样的情况不适用于 insert
,并且失败了以下错误:
/usr/include/mysql-cppconn-8/mysqlx/devapi/table_crud.h:157:17: error: ‘mysqlx::abi2::r0::internal::Expression::Expression(V&&) [with V = mysqlx::abi2::r0::internal::Expression&]’ is private within this context
157 | add_values(get_impl(), rest...);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
X Devapi用户指南给出了有关是否应该支持的内容的一些提示。在这种情况下,您可以从函数定义文档,
values()
方法期望a文字
代码> mysqlx.expr()
将起作用。在您的情况下,查看错误消息,这意味着
time
列可能是某种整数
数据类型。给定的“ unix_timestamp()”
是字符串(因为未评估表达式),它不会以任何方式强制强制,并且仅适用于其他列数据类型,例如varchar
varchar < /代码>。
从理论上讲,据我所知,没有什么能真正阻止API允许计算出的表达式。 X协议可容纳,但我不完全确定X插件本身是相同的情况。我建议您使用public mysql )。
免责声明:我是node.js mysql x devapi连接器的首席开发人员
The X DevAPI user guide gives some hints about what should be supported or not. In that case, as you can see from the function definition documentation, the
values()
method expects aLiteral
, so, not evenmysqlx.expr()
will work.In your case, looking at the error message, it means that the
time
column probably is some kind ofINTEGER
data type. Given"UNIX_TIMESTAMP()"
is a string (because the expression is not being evaluated), it is not being coerced in any way and would only work for other column data types such asVARCHAR
.In theory, from what I can tell, there is nothing that really prevents the API from allowing computed expressions. The X Protocol accommodates that but I'm not entirely sure it is the same case for the X Plugin itself. I would suggest you request the feature using the public MySQL bug tracker and the corresponding category (maybe
MySQL Connectors: Document Store: DevAPI
).Disclaimer: I'm the lead developer of the MySQL X DevAPI Connector for Node.js
我使用
mySQLX :: expr(“ unix_timestamp()”)
:然后通过触摸修复编译错误:
/usr/include/mysql/mysql-cppconn-8/mysqlx/mysqlx/devapi/devapi/table_crud.h
替换:用:
/usr/include/mysql-cppconn-8/mysqlx/devapi/detail/detail/crud.h
替换:
I used
mysqlx::expr("UNIX_TIMESTAMP()")
:then fixed the compile error by touching:
/usr/include/mysql-cppconn-8/mysqlx/devapi/table_crud.h
replaced:with:
/usr/include/mysql-cppconn-8/mysqlx/devapi/detail/crud.h
replaced:with: