|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.locomotive.util.SQL
This class contains some useful utilities for dealing with SQL statements and results of queries.
Field Summary | |
static int |
DB_TYPE_CLOUDSCAPE
|
static int |
DB_TYPE_INFORMIX
|
static int |
DB_TYPE_INTERBASE
|
static int |
DB_TYPE_MYSQL
|
static int |
DB_TYPE_ORACLE
|
static int |
DB_TYPE_POSTGRESQL
|
static int |
DB_TYPE_SOLID
|
Constructor Summary | |
SQL()
|
Method Summary | |
static java.lang.String |
buildINClause(java.lang.String colname,
int[] numarray)
builds an SQL "IN clause" using the input column name and number array |
static java.lang.String |
buildNOTINClause(java.lang.String colname,
int[] numarray)
builds an SQL "NOT IN clause" using the input column name and number array |
static int |
getDBType(java.sql.Connection conn)
This will return one of this class's final static int DB_TYPES for the database connection supplied. |
static int |
getInt(java.sql.Connection conn,
java.lang.String query)
executes a query (which should request a single number) and returns an int. |
static long |
getLong(java.sql.Connection conn,
java.lang.String query)
executes a query (which should request a single number) and returns a long. |
static java.lang.String |
quoteString(java.lang.String s)
quotes a String so it can be used in a statement, putting it within single quotes, '...'. |
static java.lang.String |
quoteStringEndLike(java.lang.String s)
creates a quoted String, enclosing the String argument within '..%', to be used in a LIKE '...%' clause for searching for prefixes. |
static java.lang.String |
quoteStringMidLike(java.lang.String s)
creates a quoted String, enclosing the String argument within '%..%', to be used in a LIKE '%...%' clause. |
static java.lang.String |
statementToTestBitInNumber(java.lang.String column_name,
int num_with_nth_bit_on)
Everybody knows that SQL cannot do bit-wise logical operations, such as bit-wise AND or ORs. |
static java.sql.Timestamp |
stringToTimestamp(java.lang.String s)
A handy pre-configured format parser for date text fields. |
static int |
update(java.sql.Connection conn,
java.lang.String statement)
executes a single SQL update (which may be either an insert or an update). |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
public static final int DB_TYPE_ORACLE
public static final int DB_TYPE_INFORMIX
public static final int DB_TYPE_SOLID
public static final int DB_TYPE_CLOUDSCAPE
public static final int DB_TYPE_MYSQL
public static final int DB_TYPE_POSTGRESQL
public static final int DB_TYPE_INTERBASE
Constructor Detail |
public SQL()
Method Detail |
public static int getDBType(java.sql.Connection conn) throws java.sql.SQLException
public static java.sql.Timestamp stringToTimestamp(java.lang.String s) throws java.lang.IllegalArgumentException
public static java.lang.String buildINClause(java.lang.String colname, int[] numarray)
colname
- - the name of the column in the dbnumarray
- - used as the data for the clause contentspublic static java.lang.String buildNOTINClause(java.lang.String colname, int[] numarray)
colname
- - the name of the column in the dbnumarray
- - used as the data for the clause contentspublic static java.lang.String quoteString(java.lang.String s)
public static java.lang.String quoteStringMidLike(java.lang.String s)
public static java.lang.String quoteStringEndLike(java.lang.String s)
public static java.lang.String statementToTestBitInNumber(java.lang.String column_name, int num_with_nth_bit_on)
if (number >= 2^17) and (number/2^18 - floor (number/2^18) >= 0.5)...This method will generate the SQL equivalent of the above statement. The first part, number >= 2^17, is to add speed to the search. Example of using this method:
String criterion = statementToTestBitInNumber ("loco_users.flags", 1<<17);will yield the string:
(loco_users.flags >= 131072) and ((loco_users.flags/262144) - floor(loco_users.flags/262144) >= 0.5)
column_name
- -- the name of the column in your database table.num_with_nth_bit_on
- -- a number with only one bit turned on,
the bit you're interested in. You can pass in 1 << nth-bit.public static int getInt(java.sql.Connection conn, java.lang.String query) throws java.sql.SQLException
public static long getLong(java.sql.Connection conn, java.lang.String query) throws java.sql.SQLException
public static int update(java.sql.Connection conn, java.lang.String statement) throws java.sql.SQLException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |