Browse Source

README updated for FMSQLStatementSplitter usage

openthread 11 years ago
parent
commit
1c03cc2251
1 changed files with 18 additions and 0 deletions
  1. 18 0
      README.markdown

+ 18 - 0
README.markdown

@@ -109,6 +109,24 @@ When you have finished executing queries and updates on the database, you should
 
 `FMDatabase` can begin and commit a transaction by invoking one of the appropriate methods or executing a begin/end transaction statement.
 
+### Split Batch Statement
+
+`FMSQLStatementSplitter` can split batch sql statement into several separated statements, then `[FMDatabase executeUpdate:]` or other methods can be used to execute each separated statement:
+
+```
+NSString *batchStatement = @"insert into ftest values ('hello;');"
+                           @"insert into ftest values ('hi;');"
+                           @"insert into ftest values ('not h!\\\\');"
+                           @"insert into ftest values ('definitely not h!')";
+NSArray *statements = [[FMSQLStatementSplitter sharedInstance] statementsFromBatchSqlStatement:batchStatement];
+[queue inDatabase:^(FMDatabase *adb) {
+    for (FMSplittedStatement *sqlittedStatement in statements)
+    {
+        [adb executeUpdate:sqlittedStatement.statementString];
+    }
+}];
+```
+
 ### Data Sanitization
 
 When providing a SQL statement to FMDB, you should not attempt to "sanitize" any values before insertion.  Instead, you should use the standard SQLite binding syntax: