tribble.util
Class SQLStrings

java.lang.Object
  extended by tribble.util.SQLStrings

public abstract class SQLStrings
extends java.lang.Object

Utility methods for SQL string and token processing.

Since:
2004-08-12
Version:
$Revision: 1.1 $ $Date: 2004/08/12 00:39:40 $
Author:
David R. Tribble (david@tribble.com).
Copyright ©2004 by David R. Tribble, all rights reserved.
Permission is granted to freely use and distribute this source code provided that the original copyright and authorship notices remain intact.

Method Summary
static int getSQLToken(java.lang.String line, int pos, java.lang.StringBuffer tok)
          Extract the next word token from an SQL-like expression.
static java.lang.String[] splitSQL(java.lang.String line)
          Split an SQL-like expression into separate word tokens.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getSQLToken

public static int getSQLToken(java.lang.String line,
                              int pos,
                              java.lang.StringBuffer tok)
Extract the next word token from an SQL-like expression.

Words may be quoted by surrounding them with single quote (') or double quote (") characters. If a word contains either of these characters, it must be quoted, and the embedded quote characters must be preceded by a backslash character (\). (Embedded backslash characters should not be preceded by another backslash, however.)

Example

Consider the following input text line:

    'Date 2' = "2001-10-01" & ID like '%\'s' & Rec.Size >= 100
    0123456789_123456789_123456789_123456789_123456789_123456789_1
 
The line above contains the following word tokens at the string offsets shown:
     0: "'Date 2'"
     9: "="
    11: ""2001-10-01""
    24: "&"
    26: "ID"
    29: "like"
    34: "'%'s'"
    41: "&"
    46: "Rec"
    49: "."
    50: "Size"
    55: ">="
    58: "100" 

Parameters:
line - A string containing one or more SQL expression word tokens separated by whitespace.
pos - Position within line where token parsing is to begin.
tok - The text of the extracted word token is returned in this object.
Returns:
The position of the character following the last one parsed from line, or zero if there are no more word tokens to extract from the line. The returned value can serve as the starting parse position in a subsequent call to this method.
Since:
1.1, 2004-08-12
See Also:
splitSQL(java.lang.String)

splitSQL

public static java.lang.String[] splitSQL(java.lang.String line)
Split an SQL-like expression into separate word tokens.

Words may be quoted by surrounding them with single quote (') or double quote (") characters. If a word contains either of these characters, it must be quoted, and the embedded quote characters must be preceded by a backslash character (\). (Embedded backslash characters should not be preceded by another backslash, however.)

Example

Consider the following input text line:

    'Date 2' = "2001-10-01" & ID like '%\'s' & Rec.Size >= 100
 
The line above is split into the following word tokens:
    [0]:  "'Date 2'"
    [1]:  "="
    [2]:  ""2001-10-01""
    [3]:  "&"
    [4]:  "ID"
    [5]:  "like"
    [5]:  "'%'s'"
    [6]:  "&"
    [7]:  "Rec"
    [8]:  "."
    [9]:  "Size"
    [10]: ">="
    [11]: "100" 

Parameters:
line - A string containing one or more text tokens separated by whitespace.
Returns:
An array of strings, representing the tokens extracted from line, or null if the input line is empty.
Since:
1.1, 2004-08-12
See Also:
getSQLToken(java.lang.String, int, java.lang.StringBuffer)