dbSendQuery中的错误 - Shiny R.

时间:2018-01-02 13:53:38

标签: r sqlite shiny

我正在尝试将UsernamePasswordEmail添加到users数据库中的表db。知道为什么这个dbSendQuery不起作用。 错误是:Error in rsqlite_send_query: near "username": syntax error

Username <- isolate(input$uname)
Password <- isolate(input$pswd)
Email <- isolate(input$email)
db <- RSQLite::dbConnect(RSQLite::SQLite(), dbname="db.sqlite")
query <- sprintf({"INSERT INTO users username=%s and password=%s and email=%s"},Username, Password, Email, serialize=F)
RSQLite::dbSendQuery(db,query) 
RSQLite::dbDisconnect(db)

其他尝试:

1: query <- sprintf({"INSERT INTO users %s and %s and %s"},Username, Password, Email, serialize=F)
2: query <- sprintf("insert into users (username, password, email) values (%s,%s,%s)", Username, Password, Email)
3: dbSendQuery(db,"INSERT INTO users (username, password, email) VALUES ('Username','Password','Email');")
4: dbSendQuery(db,"INSERT INTO users (username, password, email) VALUES (%s,%s,%s)",Username, Password, Email)
5: query<-paste("insert into users (username, password, email) values (",Username,",",Password,",",Email,")")

1 个答案:

答案 0 :(得分:0)

我用

解决了它
db <- dbConnect(SQLite(), dbname="db.sqlite")
dbSendQuery(db, sprintf({"INSERT INTO users (username,password,email) VALUES ('%s','%s','%s')"},Username, Password,Email))
RSQLite::dbDisconnect(db)