Author: rfm
Date: Fri Aug 8 11:15:13 2014
New Revision: 38042
URL: http://svn.gna.org/viewcvs/gnustep?rev=38042&view=rev
Log:
optimise string buffer size and merge deletes
Modified:
libs/sqlclient/trunk/SQLClient.h
libs/sqlclient/trunk/SQLClient.m
Modified: libs/sqlclient/trunk/SQLClient.h
URL:
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/SQLClient.h?rev=38042&r1=38041&r2=38042&view=diff
==============================================================================
--- libs/sqlclient/trunk/SQLClient.h (original)
+++ libs/sqlclient/trunk/SQLClient.h Fri Aug 8 11:15:13 2014
@@ -1658,10 +1658,10 @@
* merged into something of the form:
* INSERT INTO table (fieldnames) VALUES (values1),(values2),...;
* </p>
- * <p>Or may use this with an update statement of the form:<br />
- * UPDATE table SET settings WHERE condition;<br />
+ * <p>Or may use this with an update or delete statement of the form:<br />
+ * command table SET settings WHERE condition;<br />
* So that statements may be merged into:<br />
- * UPDATE table SET setting WHERE (condition1) OR (condition2) OR ...;
+ * command table SET settings WHERE (condition1) OR (condition2) OR ...;
* </p>
* If no opportunity for merging is found, the new statement is simply
* added to the transaction.<br />
@@ -1671,7 +1671,10 @@
* for eligibility.<br />
* 3. Merging is done only if the statement up to the string 'VALUES'
* (for insert) or 'WHERE' (for update) matches.<br />
- * 4. This is a simple text match rather than sql syntactic analysis,
+ * 4. Merging into any of the last 5 statements may of course change the
+ * order of statements in the transaction, so care must be taken not to
+ * use this feature where that migfht matter.<br />
+ * 5. This is a simple text match rather than sql syntactic analysis,
* so it's possible to confuse the process with complex statements.
*/
- (void) merge: (NSString*)stmt,...;
Modified: libs/sqlclient/trunk/SQLClient.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/SQLClient.m?rev=38042&r1=38041&r2=38042&view=diff
==============================================================================
--- libs/sqlclient/trunk/SQLClient.m (original)
+++ libs/sqlclient/trunk/SQLClient.m Fri Aug 8 11:15:13 2014
@@ -3203,13 +3203,7 @@
}
/* Try to merge the prepared statement p with an earlier statement in the
- * transaction. We search up to 5 earlier statements and we merge if;
- * a. We have something like 'INSERT INTO table (fields) VALUES (values)'
- * where everything up to 'VALUES' is the same, so we can built a multiline
- * insert like 'INSERT INTO table (fields) VALUES (values1),(values2),...'
- * b. We have something like 'UPDATE table SET settings WHERE condition'
- * where everything up to the condition is the same, so we can build
- * 'UPDATE table SET settings WHERE condition1 OR (condition2) OR ...'
+ * transaction. We search up to 5 earlier statements and we merge if we can.
*/
- (void) _merge: (NSMutableArray*)p
{
@@ -3264,7 +3258,9 @@
}
else
{
- m = [[os mutableCopy] autorelease];
+ m = [NSMutableString
+ stringWithCapacity: [os length] * 100];
+ [m appendString: os];
}
[m appendString: @","];
[m appendString: s];
@@ -3281,6 +3277,10 @@
}
r = [s rangeOfString: @"UPDATE" options: NSCaseInsensitiveSearch];
+ if (0 == r.length)
+ {
+ r = [s rangeOfString: @"DELETE" options: NSCaseInsensitiveSearch];
+ }
if (r.length > 0 && 0 == r.location)
{
r = [s rangeOfString: @"WHERE" options: NSCaseInsensitiveSearch];
@@ -3329,7 +3329,9 @@
}
else
{
- m = [[os mutableCopy] autorelease];
+ m = [NSMutableString
+ stringWithCapacity: l * 100];
+ [m appendString: os];
}
}
else
@@ -3339,8 +3341,9 @@
* new statement in which it is bracketed.
*/
os = [os substringFromIndex: pos];
- m = [NSMutableString stringWithFormat:
- @"%@(%@)", t, os];
+ m = [NSMutableString
+ stringWithCapacity: l * 100];
+ [m appendFormat: @"%@(%@)", t, os];
}
[m appendString: @" OR "];
[m appendString: s];
_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs