-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathResult.R
149 lines (132 loc) · 2.99 KB
/
Result.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#' @include Connection.R
NULL
#' Odbc Result Methods
#'
#' Implementations of pure virtual functions defined in the `DBI` package
#' for OdbcResult objects.
#' @name OdbcResult
#' @docType methods
NULL
OdbcResult <- function(connection, statement, params = NULL, immediate = FALSE, timeout = Inf) {
if (nzchar(connection@encoding)) {
statement <- enc2iconv(statement, connection@encoding)
}
if (is.infinite(timeout)) {
timeout <- 0L
}
ptr <- new_result(
p = connection@ptr,
sql = statement,
immediate = immediate,
timeout = timeout
)
res <- new("OdbcResult", connection = connection, statement = statement, ptr = ptr)
if (!is.null(params)) {
on.exit(dbClearResult(res))
dbBind(res, params = params)
on.exit(NULL)
}
res
}
#' @rdname OdbcResult
#' @keywords internal
#' @export
setClass(
"OdbcResult",
contains = "DBIResult",
slots = list(
connection = "OdbcConnection",
statement = "character",
ptr = "externalptr"
)
)
#' @rdname OdbcResult
#' @inheritParams DBI::dbClearResult
#' @export
setMethod(
"dbClearResult", "OdbcResult",
function(res, ...) {
if (!dbIsValid(res)) {
warning("Result already cleared")
}
result_release(res@ptr)
invisible(TRUE)
})
#' @rdname OdbcResult
#' @inheritParams DBI::dbFetch
#' @export
setMethod(
"dbFetch", "OdbcResult",
function(res, n = -1, ...) {
n <- check_n(n)
result_fetch(res@ptr, n)
})
#' @rdname OdbcResult
#' @inheritParams DBI::dbHasCompleted
#' @export
setMethod(
"dbHasCompleted", "OdbcResult",
function(res, ...) {
result_completed(res@ptr)
})
#' @rdname OdbcResult
#' @inheritParams DBI::dbIsValid
#' @export
setMethod(
"dbIsValid", "OdbcResult",
function(dbObj, ...) {
result_active(dbObj@ptr)
})
#' @rdname OdbcResult
#' @inheritParams DBI::dbGetStatement
#' @export
setMethod(
"dbGetStatement", "OdbcResult",
function(res, ...) {
if (!dbIsValid(res)) {
stop("Result already cleared", call. = FALSE)
}
res@statement
})
#' @rdname OdbcResult
#' @inheritParams DBI::dbColumnInfo
#' @export
setMethod(
"dbColumnInfo", "OdbcResult",
function(res, ...) {
result_column_info(res@ptr)
})
#' @rdname OdbcResult
#' @inheritParams DBI::dbGetRowCount
#' @export
setMethod(
"dbGetRowCount", "OdbcResult",
function(res, ...) {
result_row_count(res@ptr)
})
#' @rdname OdbcResult
#' @inheritParams DBI::dbGetRowsAffected
#' @export
setMethod(
"dbGetRowsAffected", "OdbcResult",
function(res, ...) {
result_rows_affected(res@ptr)
})
#' @rdname OdbcResult
#' @inheritParams DBI::dbBind
#' @inheritParams DBI-tables
#' @export
setMethod(
"dbBind", "OdbcResult",
function(res, params, ..., batch_rows = getOption("odbc.batch_rows", NA)) {
params <- as.list(params)
if (length(params) == 0) {
return(invisible(res))
}
if (is.na(batch_rows)) {
batch_rows <- length(params[[1]])
}
batch_rows <- parse_size(batch_rows)
result_bind(res@ptr, params, batch_rows)
invisible(res)
})