我在sqlite數據庫插入一些數據,它工作正常,但我注意到,我不能插入字包含字符"
,是?它的一個常見問題我應該改變分析文本和編輯每"
角色,我覺得不能插入「字符到Sqlite數據庫[Objective-C]
這是我使用,以便將數據插入到我的數據庫代碼:
UICollectionViewCell *cell = (UICollectionViewCell *)button.superview.superview;
NSIndexPath *indexPath = [self.customCollectionView indexPathForCell:cell];
FolderProducts *item = _feedItems[indexPath.item];
sqlite3_stmt *statement;
const char *dbpath = [databasePath UTF8String];
if (sqlite3_open(dbpath, &Carrello) == SQLITE_OK)
{
NSString *insertSQL = [NSString stringWithFormat: @"INSERT INTO CarrelloMese (titolo, codice, prezzo, urlImg) VALUES (\"%@\", \"%@\", \"%@\", \"%@\")",item.nomeProdotto, item.codice, item.prezzo, item.urlImg];
const char *insert_stmt = [insertSQL UTF8String];
sqlite3_prepare_v2(Carrello, insert_stmt, -1, &statement, NULL);
if (sqlite3_step(statement) == SQLITE_DONE)
{
} else {
}
sqlite3_finalize(statement);
sqlite3_close(Carrello);
}
綁定變量的準備發言;這就是它的目的。 – Droppy
@Droppy你能解釋一下嗎? – Signo
已準備好的語句旨在讓您可以準備一次語句,並在執行準備好的語句多次時將不同的值綁定到佔位符。這個綁定過程將處理轉義的特殊字符,這是你的情況。 – Droppy