본문 바로가기
언어/R

sqlite 2

by newlibra 2022. 12. 4.

library(DBI)
con <- dbConnect(RSQLite::SQLite(), ":memory:")

dbListTables(con)

dbWriteTable(con, "mtcars", mtcars)
dbListTables(con)

dbListFields(con, "mtcars")

dbReadTable(con, "mtcars")

res <- dbSendQuery(con, "SELECT * FROM mtcars WHERE cyl = 4")
dbFetch(res)
dbClearResult(res)

res <- dbSendQuery(con, "SELECT * FROM mtcars WHERE cyl = 4")
while (!dbHasCompleted(res)) {
  chunk <- dbFetch(res, n = 5)
  print(nrow(chunk))
}

# Clear the result
dbClearResult(res)

# Disconnect from the database
dbDisconnect(con)

'언어 > R' 카테고리의 다른 글

bond  (0) 2023.03.05
script  (0) 2023.02.20
sqlite3  (0) 2023.02.11
postgres  (0) 2022.12.03
sqlite  (0) 2022.11.30