-
Notifications
You must be signed in to change notification settings - Fork 78
/
SQLiteDriver.R
69 lines (62 loc) · 1.65 KB
/
SQLiteDriver.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#' @useDynLib RSQLite, .registration = TRUE
#' @importFrom Rcpp sourceCpp
#' @importFrom bit64 integer64 is.integer64
#' @importFrom blob blob
NULL
#' Class SQLiteDriver (and methods)
#'
#' SQLiteDriver objects are created by [SQLite()], and used to select the
#' correct method in [dbConnect()].
#' They are a superclass of the [DBIDriver-class] class,
#' and used purely for dispatch.
#' The "Usage" section lists the class methods overridden by \pkg{RSQLite}.
#' The [dbUnloadDriver()] method is a null-op.
#'
#' @keywords internal
#' @export
setClass("SQLiteDriver",
contains = "DBIDriver"
)
#' @rdname SQLiteDriver-class
#' @export
setMethod("dbDataType", "SQLiteDriver", function(dbObj, obj, ...) {
if (is.factor(obj)) {
return("TEXT")
}
if (is.data.frame(obj)) {
return(callNextMethod(dbObj, obj))
}
if (is.integer64(obj)) {
return("INTEGER")
}
switch(typeof(obj),
integer = "INTEGER",
double = "REAL",
character = "TEXT",
logical = "INTEGER",
list = "BLOB",
raw = "TEXT",
stop("Unsupported type", call. = FALSE)
)
})
#' @rdname SQLiteDriver-class
#' @export
setMethod("dbIsValid", "SQLiteDriver", function(dbObj, ...) {
TRUE
})
#' @rdname SQLiteDriver-class
#' @export
setMethod("dbUnloadDriver", "SQLiteDriver", function(drv, ...) {
invisible(TRUE)
})
# Set during installation time for the correct library
PACKAGE_VERSION <- utils::packageVersion(utils::packageName())
#' @rdname SQLiteDriver-class
#' @export
setMethod("dbGetInfo", "SQLiteDriver", function(dbObj, ...) {
version <- RSQLite::rsqliteVersion()
list(
driver.version = PACKAGE_VERSION,
client.version = package_version(version[[2]])
)
})