Skip to content

sqlAppendTable() needs to quote characters #207

Closed

Description

@krlmlr

http://stackoverflow.com/q/43145145/946850

library(DBI)

dfr <- data.frame(matrix(letters, ncol=2), stringsAsFactors = FALSE)

#dfr: A data frame.
conx <- dbConnect(RSQLite::SQLite(), ":memory:")
on.exit(dbDisconnect(conx))
dbWriteTable(conx, "temp", dfr[1:5, ])
#> Error in rsqlite_send_query(conn@ptr, statement): external pointer is not valid
dbReadTable(conx, 'temp')
#> Error in rsqlite_send_query(conn@ptr, statement): external pointer is not valid
sqlAppendTable(conx, 'temp', dfr[6:10, ])
#> <SQL> INSERT INTO "temp"
#>   ("X1", "X2")
#> VALUES
#>   (f, s),
#>   (g, t),
#>   (h, u),
#>   (i, v),
#>   (j, w)

Activity

  1. self-assigned this
    on Apr 2, 2017
  2. added a commit that references this issue on Apr 3, 2017
  3. added a commit that references this issue on Apr 3, 2017
  4. added a commit that references this issue on Jun 19, 2017
  5. leungi commented on Apr 19, 2018

    @leungi

    Ran into the exact issue with latest DBI 0.8.

    > DBI::sqlAppendTable(con = con, table = table ,values = data)
    <SQL> INSERT INTO "IHS_PDCA_TYPE_CURVE_HEADER"
      ("reservoir", "bin_year", "bin_length", "type_curve_id", "well_count", "last_updated")
    VALUES
      (devonian, 2003, 5000, devonian_5000_2003, 4, 2018-04-19)
    
    ## 1st, 4th and 6th column are supposed to be string (it is in data.frame), but not in sql generated
    
    ## second attempt with your updated sqlData(), but with same results
    
    > DBI::sqlAppendTable(con = con, table = table ,values = sqlData(con = con, value = data) )
    <SQL> INSERT INTO "IHS_PDCA_TYPE_CURVE_HEADER"
      ("reservoir", "bin_year", "bin_length", "type_curve_id", "well_count", "last_updated")
    VALUES
      (devonian, 2003, 5000, devonian_5000_2003, 4, 2018-04-19)
    

    The only reason I'm doing this is because db_write_table() and db_insert_into() forces users to create table, even though I tried temporary = FALSE. This is a case where user has insert but not create privileges.

    Shall I open a new issue or reopen this one?

    Thanks.
    Ivan

  6. krlmlr commented on Jul 15, 2018

    @krlmlr
    MemberAuthor

    DBI 1.0.0 has dbAppendTable(), does that help? Would you mind filing a new issue, which backend does it affect?

  7. leungi commented on Jul 16, 2018

    @leungi

    Thanks @krlmlr; I just filed a new Issue under #265.

  8. github-actions commented on Dec 7, 2020

    @github-actions
    Contributor

    This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.

  9. locked and limited conversation to collaborators on Dec 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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