freetds AT lists.ibiblio.org
Subject: FreeTDS Development Group
List archive
- From: "Eric Mountain" <e.mountain AT dev.amadeus.net>
- To: "TDS Development Group" <freetds AT franklin.oit.unc.edu>
- Subject: EscapeProcessor patch for FreeTDS JDBC
- Date: Thu, 16 Sep 1999 18:54:08 +0200
Hi,
To whoever maintains the FreeTDS JDBC code... I was wondering if the
following patch could be included for the next release. It fixes some major
performance problems in escape processing (with this patch I achieved 5
times speedup on the program I was working on at the time: it was processing
thousands of SQL statements one after the other and profiling showed it was
spending far too long in this method (and it was really sluggish compared to
using the ODBC bridge) - after the change I was spending most of my time in
SocketRead which was far more reasonable).
[ The performance problem is due to the implicit "new StringBuffer()" code
which is "written" by the compiler for every string concatenation (+). "New"
is costly, and here it occurs inside a loop. ]
Thanks,
Eric
diff --recursive -c freetds_jdbc_29Apr99/EscapeProcessor.java
freetds_jdbc_exp/EscapeProcessor.java
*** freetds_jdbc_29Apr99/EscapeProcessor.java Sat Nov 28 11:58:40 1998
--- freetds_jdbc_exp/EscapeProcessor.java Wed May 05 17:38:06 1999
***************
*** 376,382 ****
private String nativeString(String sql, char escapeCharacter)
throws SQLException
{
! String result = "";
String escape = "";
int i;
--- 376,382 ----
private String nativeString(String sql, char escapeCharacter)
throws SQLException
{
! StringBuffer result = new StringBuffer("");
String escape = "";
int i;
***************
*** 397,404 ****
int escapeStartedAt = -1;
i = 0;
! while(i<sql.length())
{
ch = sql.charAt(i);
switch(state)
--- 397,405 ----
int escapeStartedAt = -1;
+ int sqlLength = sql.length();
i = 0;
! while(i<sqlLength)
{
ch = sql.charAt(i);
switch(state)
***************
*** 413,419 ****
}
else
{
! result = result + ch;
if (ch == '\'') state = inString;
}
--- 414,420 ----
}
else
{
! result.append(ch);
if (ch == '\'') state = inString;
}
***************
*** 422,439 ****
case inString:
case inStringWithBackquote:
{
! if ((i+1)<sql.length()
&& ch == escapeCharacter
&& (sql.charAt(i+1)=='_'
|| sql.charAt(i+1)=='%'))
{
i++;
ch = sql.charAt(i);
! result = result + '\\' + ch;
}
else
{
! result = result + ch;
if (state == inStringWithBackquote)
{
state = inString;
--- 423,440 ----
case inString:
case inStringWithBackquote:
{
! if ((i+1)<sqlLength
&& ch == escapeCharacter
&& (sql.charAt(i+1)=='_'
|| sql.charAt(i+1)=='%'))
{
i++;
ch = sql.charAt(i);
! result.append('\\').append(ch);
}
else
{
! result.append(ch);
if (state == inStringWithBackquote)
{
state = inString;
***************
*** 465,471 ****
char c;
// make sure it is the last thing in the sql
! if (i+1!=sql.length())
{
throw new SQLException("Malformed statement. " +
"escape clause must be at "
+
--- 466,472 ----
char c;
// make sure it is the last thing in the sql
! if (i+1!=sqlLength)
{
throw new SQLException("Malformed statement. " +
"escape clause must be at "
+
***************
*** 479,492 ****
c =
findEscapeCharacter(sql.substring(escapeStartedAt));
! result = nativeString(sql.substring(0,
escapeStartedAt),
! c);
state = normal;
}
else
{
state = normal;
! result = result + expandEscape(escape);
escapeStartedAt = -1;
}
}
--- 480,493 ----
c =
findEscapeCharacter(sql.substring(escapeStartedAt));
! result = new
StringBuffer(nativeString(sql.substring(0, escapeStartedAt),
! c));
state = normal;
}
else
{
state = normal;
! result.append(expandEscape(escape));
escapeStartedAt = -1;
}
}
***************
*** 527,533 ****
{
throw new SQLException("Syntax error in SQL escape syntax");
}
! return result;
} // nativeString()
static char findEscapeCharacter(String original_str)
--- 528,534 ----
{
throw new SQLException("Syntax error in SQL escape syntax");
}
! return result.toString();
} // nativeString()
static char findEscapeCharacter(String original_str)
- EscapeProcessor patch for FreeTDS JDBC, Eric Mountain, 09/16/1999
Archive powered by MHonArc 2.6.24.