我在尝试执行以下代码时遇到错误[logging] near "IF": syntax error
:
NSString * saveQuery = [[NSString alloc] initWithFormat:@"IF (NOT EXISTS (SELECT * FROM USERDB WHERE email=\"%@\")) BEGIN INSERT INTO USERDB (firstName, lastName, username, email, password) VALUES (\"%@\", \"%@\", \"%@\", \"%@\", \"%@\") END ELSE BEGIN UPDATE USERDB (firstName, lastName, username, email, password) VALUES (\"%@\", \"%@\", \"%@\", \"%@\", \"%@\") WHERE email = \"%@\" END", email, firstName, lastName, username, email, password, firstName, lastName, username, email, password, email];
[userDB saveData:saveQuery];
如果用户似乎基于其电子邮件地址似乎不存在,我将尝试插入数据库(否则,我想更新其现有数据)。
答案 0 :(得分:0)
更新!发现了INSERT or REPLACE
NSString * saveQuery = [[NSString alloc] initWithFormat:@"INSERT OR REPLACE INTO USERDB (firstName, lastName, username, email, password) VALUES (\"%@\", \"%@\", \"%@\", \"%@\", \"%@\")", firstName, lastName, username, email, password];