我正在尝试将Username
,Password
和Email
添加到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,")")
答案 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)