Skip to content

db_append_table should not double escape already escaped quotes #270

Open
@jd4ds

Description

@jd4ds

Hey there,
long awaited and now available, I was very happy about the possibility to insert data into MySQL databases via local file. However, I may have found a small issue when creating the TSV file.
{readr} seems to escape already escaped quotes, which leads to unwanted results. My suggestion would be to use readr::write_delim(..., escape = "none"), unless the default escaping of readr was chosen on purpose.

Please let me know if you need more information on this!

Cheers,
Janis

escape_testing <- function(escape = "double"){
  file_default_escape <- tempfile(fileext = ".tsv")
  readr::write_delim(
    RMariaDB:::csv_quote(value,
                         warn_factor = TRUE,
                         conn = target_conn),
    file_default_escape,
    quote = "none",
    delim = "\t",
    na = "\\N",
    col_names = FALSE,
    escape = escape
  )
  value_default_escape <- readr::read_tsv(file = file_default_escape)
  print(as.data.frame(value_default_escape))
  unlink(file_default_escape)
}

value <-
  data.frame(test = c("test_header", 'Test \"quote\" escaping.'))

# Escape default value
escape_testing(escape = "double")
#> Rows: 1 Columns: 1
#> -- Column specification --------------------------------------------------------
#> Delimiter: "\t"
#> chr (1): test_header
#> 
#> i Use `spec()` to retrieve the full column specification for this data.
#> i Specify the column types or set `show_col_types = FALSE` to quiet this message.
#>                test_header
#> 1 Test ""quote"" escaping.

# `escape = "none"`
escape_testing(escape = "none")
#> Rows: 1 Columns: 1
#> -- Column specification --------------------------------------------------------
#> Delimiter: "\t"
#> chr (1): test_header
#> 
#> i Use `spec()` to retrieve the full column specification for this data.
#> i Specify the column types or set `show_col_types = FALSE` to quiet this message.
#>              test_header
#> 1 Test "quote" escaping.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions