【问题标题】:Special Characters in SQLite Query (in iPhone)SQLite 查询中的特殊字符(在 iPhone 中)
【发布时间】:2012-03-03 14:34:16
【问题描述】:

我正在为 iPhone 应用程序使用 SQLite,并且我正在使用这样的查询:

NSString *query = [[NSString alloc] initWithFormat:@"INSERT INTO Courses (name, credits, web, tName, tSurname, tMail, tOffice) VALUES (\'%@\', \'%@\', \'%@\', \'%@\', \'%@\', \'%@\', \'%@\');", self.name, self.credits, self.web, self.tName, self.tSurname, self.tMail, self.tOffice];

这是一个简单的 INSERT,但我来自西班牙,但我在使用波浪号时遇到了一些问题。如果我这样做:

INSERT INTO Courses (name, credits, web, tName, tSurname, tMail, tOffice) VALUES ('test', 'test', 'test', 'test', 'test', 'test', 'test');", self.name, self.credits, self.web, self.tName, self.tSurname, self.tMail, self.tOffice];

一切都很完美。

当我使用“特殊字符”(如 ¿、¡、`、'、ñ...包含特殊字符没有问题。

例如:

这个查询有效(因为只有一个“á”):

INSERT INTO Courses (name, credits, web, tName, tSurname, tMail, tOffice) VALUES ('Matemáticas', '1', '', 'Name', 'Surname', 'a@a.com', '');", self.name, self.credits, self.web, self.tName, self.tSurname, self.tMail, self.tOffice];

这个查询返回错误“错误:靠近“''”:语法错误”(因为有一个“ó”和一个“à”):

INSERT INTO Courses (name, credits, web, tName, tSurname, tMail, tOffice) VALUES ('Gestió', '1', '', 'à', 'Surname', 'a@a.com', '');", self.name, self.credits, self.web, self.tName, self.tSurname, self.tMail, self.tOffice];

我试图把单词放在“和'之间,我得到了相同的结果。

有什么想法吗?

【问题讨论】:

  • 嗨,你有没有找到解决这个问题的可靠方法,我最近三天都在经历同样的事情。

标签: iphone xcode4 ios5 sqlite


【解决方案1】:

我没有在 iPhone 上使用过 SQLite,但您是否浏览过该库以找到某种构建预编译 SQL 语句的方法?这将解决您可能遇到的许多问题,例如对 SQL 查询的误解和意外\有意的 SQL 注入。

【讨论】:

  • 不,我没有浏览过图书馆。有关更多信息,我正在使用 Xcode 附带的官方 libsqlite3.dylib。如果有人知道任何其他图书馆,我会尝试。
猜你喜欢
  • 1970-01-01
  • 2016-04-22
  • 2013-12-15
  • 2011-02-15
  • 1970-01-01
  • 2011-10-08
  • 2016-04-23
  • 2021-08-19
  • 2012-08-23
相关资源
最近更新 更多