cannot coerce type 'externalptr' to vector of type 'character'

Error:

Error in as.vector(x, "character") :
  cannot coerce type 'externalptr' to vector of type 'character'


Problem Code:

con <- dbConnect(RMySQL::MySQL(), dbname = "test")

sql <-
    paste0(
      "INSERT INTO `devharsh` (`un`, `pw`, `bl`) VALUES ('",TextUN,"', '",TextPW,"', '",0,"')"
    )
  dbGetQuery(con, sql)


Solution:

sql <-
    paste0(
      "INSERT INTO `devharsh` (`un`, `pw`, `bl`) VALUES ('",TextUN$getText(),"', '",TextPW$getText(),"', '",0,"')"
    )


Note:

It was giving error because it was not getting text from textbox that we should get by getText() function.

This R error means a value that is not a plain character vector was passed where a string was expected. Here a database connection handle, an external pointer, was used where text was needed.

The fix is to pass the query string rather than the connection object, and to run it through the proper function such as dbGetQuery or dbSendQuery. Parameterized queries are also safer than building SQL by pasting values together.

Comments

Popular posts from this blog

[Solved] Error: No such keg: /usr/local/Cellar/gcc

[How To] Unfollow Non-followers on Instagram