使用 sqlUpdate 解决 "incompatible types" 错误

Resolving "incompatible types" error with sqlUpdate

我正在尝试通过 RODBC 将以下数据写入数据库。我该如何解决以下错误或一些额外的故障排除步骤?

writeData  <- structure(list(`__ActivityID` = c("8000002", "8000003", "8000005"), 
`__ID` = c("ZRH_06d88315", "ZRH_8161772a", "ZRH_b9f9798a")), 
.Names = c("__ActivityID", "__ID"), row.names = c(NA, 3L), class = "data.frame")

这是应该更新数据库的命令。我也试过 test = false:

sqlUpdate(channel = liveConnection, dat = writeData, 
          tablename = "__Marketing Activities", 
index = "__ActivityID", nastring = NULL, test = TRUE)

它returns这个错误:

# Query: UPDATE "__Marketing Activities" SET "__ID"=? WHERE "__ActivityID"=?
Error in sqlUpdate(channel = con$liveConnection, dat =     
res$writeDataNewPKs$`__Marketing Activities`,  : 
HY000 8309 [FileMaker][FileMaker ODBC] FQL0013/(1:36): 
Incompatible types in assignment.[RODBC] 
ERROR: Could not SQLPrepare 'UPDATE "__Marketing Activities" 
SET "__ID"=? WHERE "__ActivityID"=?'

这是关于 __ID 列的结构信息:

  TABLE_CAT TABLE_SCHEM             TABLE_NAME COLUMN_NAME DATA_TYPE TYPE_NAME COLUMN_SIZE BUFFER_LENGTH DECIMAL_DIGITS
1      <NA>        <NA> __Marketing Activities        __ID        12   VARCHAR     1000000       1000000             NA
  NUM_PREC_RADIX NULLABLE REMARKS COLUMN_DEF SQL_DATA_TYPE SQL_DATETIME_SUB CHAR_OCTET_LENGTH ORDINAL_POSITION IS_NULLABLE
1             NA        0    <NA>                       12               NA           1000000              180          NO

这是关于 __ActivityID 列的结构信息:

  TABLE_CAT TABLE_SCHEM             TABLE_NAME  COLUMN_NAME DATA_TYPE TYPE_NAME COLUMN_SIZE BUFFER_LENGTH DECIMAL_DIGITS
1      <NA>        <NA> __Marketing Activities __ActivityID         8   DECIMAL          15             8             15
  NUM_PREC_RADIX NULLABLE REMARKS COLUMN_DEF SQL_DATA_TYPE SQL_DATETIME_SUB CHAR_OCTET_LENGTH ORDINAL_POSITION IS_NULLABLE
1             -1        1    <NA>                        8               NA                NA               39         YES

我尝试将其他数据写入相同的列,但仍然收到相同的错误。

writeData  <-structure(list(`__ActivityID` = c("8000002", "8000003", "8000005", 
"8000008", "8000009", "8000010"), `__ID` = 1:6), .Names = c("__ActivityID", 
"__ID"), row.names = c(NA, 6L), class = "data.frame")

写入同一数据库中的其他列时,我没有任何问题。

我还尝试将 writeData 中的两列转换为这些 类:数字、字符、整数。

我怀疑 __ID 列中的数据类型有一些我在数据库方面不理解的地方。顺便说一句,这是连接到 FileMaker 11 数据库。

最后,这里有一些关于连接本身的数据。它是用这个命令创建的:

sqlTypeInfo(con$liveConnection, type = "all", errors = TRUE, as.is = TRUE)

这是输出:

structure(list(TYPE_NAME = c("VARCHAR", "CHARACTER VARYING", 
"DECIMAL", "NUMERIC", "INT", "DECIMAL", "DECIMAL", "BLOB", "VARBINARY", 
"LONGVARBINARY", "BINARY VARYING", "DATE", "TIME", "TIMESTAMP"
), DATA_TYPE = c(12L, 12L, 3L, 2L, 4L, 6L, 8L, -4L, -4L, -4L, 
-4L, 9L, 10L, 11L), COLUMN_SIZE = c(-1L, -1L, 10L, 10L, 10L, 
15L, 15L, -1L, -1L, -1L, -1L, 10L, 10L, 19L), LITERAL_PREFIX = c("'", 
"'", NA, NA, NA, NA, NA, "X'", "X'", "X'", "X'", "{d '", "{t '", 
"{ts '"), LITERAL_SUFFIX = c("'", "'", NA, NA, NA, NA, NA, "'", 
"'", "'", "'", "'}", "'}", "'}"), CREATE_PARAMS = c("length", 
"length", "precision,scale", "precision,scale", NA, NA, NA, NA, 
NA, NA, NA, NA, "length", "length"), NULLABLE = c(1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), CASE_SENSITIVE = c(1L, 
1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), SEARCHABLE = c(3L, 
3L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L), UNSIGNED_ATTRIBUTE = c(NA, 
NA, 0L, 0L, 0L, 0L, 0L, NA, NA, NA, NA, NA, NA, NA), FIXED_PREC_SCALE = c(0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), AUTO_UNIQUE_VALUE = c(NA, 
NA, 0L, 0L, 0L, 0L, 0L, NA, NA, NA, NA, NA, NA, NA), LOCAL_TYPE_NAME = c("varchar", 
"character varying", "decimal", "numeric", "int", "decimal", 
"decimal", "blob", "varbinary", "longvarbinary", "binary varying", 
"date", "time", "timestamp"), MINIMUM_SCALE = c(NA, NA, 0L, 0L, 
0L, NA, NA, NA, NA, NA, NA, NA, NA, 0L), MAXIMUM_SCALE = c(NA, 
NA, 15L, 15L, 0L, NA, NA, NA, NA, NA, NA, NA, NA, 0L), SQL_DATA_TYPE = c(12L, 
12L, 3L, 2L, 4L, 6L, 8L, -4L, -4L, -4L, -4L, 9L, 9L, 9L), SQL_DATETIME_SUB = c(NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1L, 2L, 3L), NUM_PREC_RADIX = c(NA, 
NA, 10L, 10L, 10L, 10L, 10L, NA, NA, NA, NA, NA, NA, NA), INTERVAL_PRECISION = c(NA_integer_, 
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
NA_integer_, NA_integer_, NA_integer_)), .Names = c("TYPE_NAME", 
"DATA_TYPE", "COLUMN_SIZE", "LITERAL_PREFIX", "LITERAL_SUFFIX", 
"CREATE_PARAMS", "NULLABLE", "CASE_SENSITIVE", "SEARCHABLE", 
"UNSIGNED_ATTRIBUTE", "FIXED_PREC_SCALE", "AUTO_UNIQUE_VALUE", 
"LOCAL_TYPE_NAME", "MINIMUM_SCALE", "MAXIMUM_SCALE", "SQL_DATA_TYPE", 
"SQL_DATETIME_SUB", "NUM_PREC_RADIX", "INTERVAL_PRECISION"), row.names = c(NA, 
14L), class = "data.frame")

错误已通过将 __ID 列的 IS_NULLABLE 参数更改为 true 来解决。

在 FileMaker 中,这是通过关闭 Not empty 字段选项来完成的,如下所示。

或许有人也能解释一下为什么会这样?我只测试过它是否有效并且能够写入该列。