Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
插入长html字符串时iOS应用程序Sqlite Prepare语句错误_Ios_Objective C - Fatal编程技术网

插入长html字符串时iOS应用程序Sqlite Prepare语句错误

插入长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">

在iOS应用程序的sqlite数据库中插入长html字符串时,我遇到了一个问题

我得到了一个很长的html内容,它是从邮件服务器中动态提取的。下面是html内容的示例

[我需要存储整个HTML字符串。因为我必须重新获取此字符串并加载到UIWEBVIEW中]

    <div style="padding-bottom: 20px;"><div style="background-color:#eee">                                  
    <div><b>From:</b> martin test &lt;martintest@gmail.com&gt;</div>                                                   
    <div><b>To:</b> Steve test &lt;stevetest@yahoo.com&gt;, martin test &lt;martintest@gmail.com&gt;</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];