我正在尝试通过RSQLite将在R中创建的大型列表对象存储到SQLite数据库中。由于这些列表对象包含多个2d和3d矩阵,我想将它们存储为单独的条目。我读取序列化这些并将它们存储为blob就可以了。
然而问题是我的代码似乎不将blob存储为单独的行,而是将每个单独的字节存储为行。这是我的代码:
library(RSQLite)
out1 <- serialize(model1,NULL)
out2 <- serialize(model2,NULL)
out3 <- serialize(model3,NULL)
model4 <- serialize(rnorm(10),NULL)
model5 <- serialize(rnorm(20),NULL)
model6 <- serialize(rnorm(30),NULL)
db <- dbConnect(SQLite(), dbname="Test.sqlite")
dbGetQuery(conn = db,
"CREATE TABLE IF NOT EXISTS models
(_id INTEGER PRIMARY KEY AUTOINCREMENT,
model BLOB)")
test4 <- data.frame(g=I(model4))
test5 <- data.frame(g=I(model5))
test6 <- data.frame(g=I(model6))
dbGetPreparedQuery(db, "INSERT INTO models (model) values (:g)", bind.data=test4)
dbGetPreparedQuery(db, "INSERT INTO models (model) values (:g)", bind.data=test5)
dbGetPreparedQuery(db, "INSERT INTO models (model) values (:g)", bind.data=test6)
dbListTables(db)
p1 = dbGetQuery( db,'select * from models' )
此外,虽然在这种情况下写入过程正常,但是文件大于1000kb的速度非常慢......