插入长html字符串时iOS应用程序Sqlite Prepare语句错误
在iOS应用程序的sqlite数据库中插入长html字符串时,我遇到了一个问题 我得到了一个很长的html内容,它是从邮件服务器中动态提取的。下面是html内容的示例 [我需要存储整个HTML字符串。因为我必须重新获取此字符串并加载到UIWEBVIEW中]插入长html字符串时iOS应用程序Sqlite Prepare语句错误,ios,objective-c,Ios,Objective C,在iOS应用程序的sqlite数据库中插入长html字符串时,我遇到了一个问题 我得到了一个很长的html内容,它是从邮件服务器中动态提取的。下面是html内容的示例 [我需要存储整个HTML字符串。因为我必须重新获取此字符串并加载到UIWEBVIEW中] <div style="padding-bottom: 20px;"><div style="background-color:#eee">
<div style="padding-bottom: 20px;"><div style="background-color:#eee">
<div><b>From:</b> martin test <martintest@gmail.com></div>
<div><b>To:</b> Steve test <stevetest@yahoo.com>, martin test <martintest@gmail.com></div>
<div><b>Subject:</b> This for testing</div>
<div><b>Date:</b> July 8, 2015 at 11:05:05 AM GMT+5:30</div>
</div></div><div><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div dir="ltr">This is a testing email.<br />
<div><br /></div>
<div>How are you?</div>
<div><br /></div>
<div>Best of Luck.</div>
<div><br /></div>
<div>Bye take care.</div>
<div><br /></div>
<div><br /></div>
<div>Regards,</div>
<div>Martin</div>
</div>
</body>
</html>
</div>
它给出的错误是
Problem with prepare statement: near "padding": syntax error
在执行以下行时
NSString *insertSQL = [NSString stringWithFormat:@"insert into OfflineMailsDBTable (emailid, foldername, uid, content) values (\"%@\", \"%@\", %d, \"%@\")", emailAddress, folderName, (int)msgUID, msgContent];
在将HTML内容添加到INSERT语句之前,必须对其双引号进行转义 假设HTML内容存储在变量msgContent中,您应该执行以下操作:
NSString *escapedMsgContent = [msgContent stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];
NSString *insertSQL = [NSString stringWithFormat:@"insert into OfflineMailsDBTable (emailid, foldername, uid, content) values (\"%@\", \"%@\", %d, \"%@\")", emailAddress, folderName, (int)msgUID, escapedMsgContent];
NSString *escapedMsgContent = [msgContent stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];
NSString *insertSQL = [NSString stringWithFormat:@"insert into OfflineMailsDBTable (emailid, foldername, uid, content) values (\"%@\", \"%@\", %d, \"%@\")", emailAddress, folderName, (int)msgUID, escapedMsgContent];