File: dbQuoteString_DBIConnection.R

package info (click to toggle)
dbi 1.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,740 kB
  • sloc: makefile: 2
file content (49 lines) | stat: -rw-r--r-- 1,177 bytes parent folder | download
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
#' @rdname hidden_aliases
#' @usage NULL
dbQuoteString_DBIConnection <- function(conn, x, ...) {
  if (is(x, "SQL")) {
    return(x)
  }
  if (!is.character(x)) {
    stop("x must be character or SQL", call. = FALSE)
  }

  # Avoid fixed = TRUE due to https://github.com/r-dbi/DBItest/issues/156
  x <- gsub("'", "''", enc2utf8(x))

  if (length(x) == 0L) {
    SQL(character())
  } else {
    # Not calling encodeString() here, see also https://stackoverflow.com/a/549244/946850
    # and especially the comment by Álvaro González
    str <- paste("'", x, "'", sep = "")
    str[is.na(x)] <- "NULL"
    SQL(str)
  }
}

# Need to keep other method declarations around for now, because clients might
# use getMethod(), see e.g. https://github.com/r-dbi/odbc/pull/149
#' @rdname hidden_aliases
#' @export
setMethod(
  "dbQuoteString",
  signature("DBIConnection"),
  dbQuoteString_DBIConnection
)

#' @rdname hidden_aliases
#' @export
setMethod(
  "dbQuoteString",
  signature("DBIConnection", "character"),
  dbQuoteString_DBIConnection
)

#' @rdname hidden_aliases
#' @export
setMethod(
  "dbQuoteString",
  signature("DBIConnection", "SQL"),
  dbQuoteString_DBIConnection
)