使用DBI的DBIND在R中的弦长限制

发布于 2025-01-23 06:34:25 字数 915 浏览 0 评论 0原文

我想使用DBI :: DBBIND运行一些参数化查询来更新SQL Server数据库,但是我编写的字符串值以256个字符被截断。在下面的代码中,我应该在数据库中看到500“ N”的字符串,但我只看到256。

conn <- DBI::dbConnect(odbc::odbc(), Driver = "xxx", Server = "serverx", Database = "dbx", UID = "pathx", PWD = "passwd", PORT = 1234)

query <- "UPDATE tableA SET fieldA = ? WHERE rowID = ?"

para <- list(strrep("n", 500), "id12345")

sentQuery <- dbSendQuery(conn, query)
dbBind(sentQuery, para)
dbClearResult(sentQuery)

我也尝试不使用DBBIND编写500“ N”,结果很好。我看到了所有500 n。我想这消除了问题的一些罪魁祸首,例如conn和数据库中的字段定义。这是有效的代码。

query <- (paste0("UPDATE tableA SET fieldA = '", strrep("n", 500), "' WHERE rowID = 'id12345'"))

dbExecute(conn, query)

我找到了一个没有答案的类似问题(带有r dbi软件包的更新字符串)。但是,这个问题没有指出DBBIND,因此我将其发布以提高特异性。

I want to use DBI::dbBind to run some parameterized queries to update a SQL Server database but the string values I wrote got truncated at 256 characters. In the code below, I am supposed to see a string of 500 "n" in the database but I only see 256.

conn <- DBI::dbConnect(odbc::odbc(), Driver = "xxx", Server = "serverx", Database = "dbx", UID = "pathx", PWD = "passwd", PORT = 1234)

query <- "UPDATE tableA SET fieldA = ? WHERE rowID = ?"

para <- list(strrep("n", 500), "id12345")

sentQuery <- dbSendQuery(conn, query)
dbBind(sentQuery, para)
dbClearResult(sentQuery)

I also tried writing the 500 "n" without using dbBind, and the result is fine. I see all 500 n. I guess this eliminates some culprits of the problem, like the conn and the field definition in the database. This is the code that works.

query <- (paste0("UPDATE tableA SET fieldA = '", strrep("n", 500), "' WHERE rowID = 'id12345'"))

dbExecute(conn, query)

I found one similar question without answer (Truncated updated string with R DBI package). However that question didn't point out dbBind therefore I am posting this for higher specificity.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文