使用DBI的DBIND在R中的弦长限制
我想使用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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论