optimise string buffer size and merge deletes

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/sqlclient/trunk@38042 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2014-08-08 09:15:13 +00:00
parent ff5a0b347f
commit abd0e840eb
2 changed files with 21 additions and 15 deletions

View file

@ -1658,10 +1658,10 @@ SQLCLIENT_PRIVATE
* 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 @@ SQLCLIENT_PRIVATE
* 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,...;

View file

@ -3203,13 +3203,7 @@ static unsigned int maxConnections = 8;
}
/* 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 @@ static unsigned int maxConnections = 8;
}
else
{
m = [[os mutableCopy] autorelease];
m = [NSMutableString
stringWithCapacity: [os length] * 100];
[m appendString: os];
}
[m appendString: @","];
[m appendString: s];
@ -3281,6 +3277,10 @@ static unsigned int maxConnections = 8;
}
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 @@ static unsigned int maxConnections = 8;
}
else
{
m = [[os mutableCopy] autorelease];
m = [NSMutableString
stringWithCapacity: l * 100];
[m appendString: os];
}
}
else
@ -3339,8 +3341,9 @@ static unsigned int maxConnections = 8;
* 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];