我的data
表位于MariaDB实例下的AWS-RDS中,如下所示:
| id | first | second | third | fourth | fifth | sixth |
|----|-------|--------|-------|--------|-------|-------|
| 3 | foo | foo | foo | foo | 1 | foo |
| 4 | foo | foo | foo | foo | 2 | foo |
| 5 | bar | foo | bar | foo | 3 | bar |
| 6 | bar | bar | bar | bar | 4 | bar |
| 7 | bar | bar | bar | bar | 5 | bar |
更新或删除查询无法生成所需的输出而不返回任何错误:
con <- dbConnect(RMariaDB::MariaDB(), group = "aws-rds")
dbSendQuery(con, statement = "UPDATE data SET second = 'bar' WHERE id = 4;")
dbDisconnect(con)
返回:
SQL UPDATE data SET second = 'bar' WHERE id = 4; ROWS Fetched: 0 [complete] Changed: 1
该表似乎没有变化,但是因为读取它会返回原始表:
con <- dbConnect(RMariaDB::MariaDB(), group = "aws-rds")
data.tbl <- dbReadTable(con, "data") %>% as_tibble()
dbDisconnect(con)
data.tbl
返回:
| id | first | second | third | fourth | fifth | sixth |
|----|-------|--------|-------|--------|-------|-------|
| 3 | foo | foo | foo | foo | 1 | foo |
| 4 | foo | foo | foo | foo | 2 | foo |
| 5 | bar | foo | bar | foo | 3 | bar |
| 6 | bar | bar | bar | bar | 4 | bar |
| 7 | bar | bar | bar | bar | 5 | bar |
我错过了什么?
最佳答案
来自 ?dbSendQuery
This method is for SELECT queries only. Some backends may support data manipulation queries through this method for compatibility reasons. However, callers are strongly encouraged to use dbSendStatement() for data manipulation statements.
尝试使用dbSendStatement
。
关于mysql - MariaDB - 更新/删除无提示失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50190675/