将数据插入表中,给出语法错误 SWIFT

insert data into table giving syntax error SWIFT

提问人:Meenor Ranpura 提问时间:5/30/2018 更新时间:5/30/2018 访问量:124

问:

我从 API 获取数据,这是我的回复

{
author = "Joanne Chiu";
description = "Asian stock markets tumbled Wednesday following overnight declines in the U.S. and Europe. Key markets including Japan, Hong Kong and mainland China fell more than 1.5%. Japan\U2019s Nikkei average shed 1.7% to hit a six-week low, while South Korea\U2019s KOSPI slipped\U2026";
publishedAt = "2018-05-30T05:04:26Z";
source =     {
    id = "the-wall-street-journal";
    name = "The Wall Street Journal";
};
title = "Asian Stocks Down, Following Global Concerns Over Italy's Political Turmoil";
url = https://www.wsj.com/articles/asian-stocks-down-following-global-concerns-over-italys-political-turmoil-1527656546;
urlToImage = https://images.wsj.net/im-12406/social;}

我想将所有数据存储到数据库中。这是我的查询

let query : NSString = NSString(format: "insert into newsData (sourceName, authorName, title,  description, url, urlToImage, publishedAt) values (%@, %@, %@, %@, %@, %@, %@)", sourceName, authorName, title, description, url, urlToImage, publishedAt)

但它给了我一个语法错误

执行查询“靠近”墙“时出错:语法错误

我以为这是因为特殊字符“-”,所以删除了它,但它仍然给了我同样的错误

iOS iPhone Swift SQLite

评论

0赞 Dharmesh Mansata 5/30/2018
似乎您想在数据库中插入双引号。试试这个 stackoverflow.com/questions/24887000/...
0赞 Jigar 5/30/2018
试试这个 String(format:“INSERT INTO newsData (sourceName,authorName,title,description,url,urlToImage,publishedAt) VALUES (\'%@\',\'%@\',\'%@\',\'%@\',\'%@\',\'%@\',\'%@\')”,, sourceName, authorName, title, description, url, urlToImage, publishedAt)
1赞 MadProgrammer 5/30/2018
你的字符串需要用引号引号,即 - 可能还想转义文本以将引号加双引号('%@'')
0赞 Meenor Ranpura 5/30/2018
@MadProgrammer工作正常,谢谢

答: 暂无答案