cds.sql
Class SQLInsert

java.lang.Object
  extended bycds.sql.SQLInsert

public class SQLInsert
extends java.lang.Object

SQL 'INSERT' statement building class.
It receives a table name, and pairs of colums (optional) and values (mandatory).
It is possible to add colums and values in an asynchronous way, as long as the order and number of items remains synchronized. Colums names can be combined in one call: addColumn("col1,col2,col3") for instance.

When finished, the toString() method returns the full INSERT statement.

Version:
1.0 May 2003
Author:
Marc Wenger/CDS

Field Summary
private  java.lang.StringBuffer colNames
           
private  java.lang.String tableName
           
private  java.lang.StringBuffer values
           
 
Constructor Summary
SQLInsert()
          Constructor of an INSERT statement with column names and values
SQLInsert(boolean withNames)
          Constructor of an INSERT statement. the parameter determines if column names will be present.
 
Method Summary
 void addColumn(java.lang.String col)
          Adds a column name into the INSERT command
 void addItem(java.lang.String col, java.lang.String val)
          Adds an item pair (column name and value) into the INSERT command.
 void addNull()
          Sets a null value without a column name into the INSERT command.
 void addNull(java.lang.String col)
          Sets a null value with its column name into the INSERT command.
 void addQuotedItem(java.lang.String col, java.lang.String val)
          Adds an item pair (column name and value) into the INSERT command.
 void addQuotedValue(java.lang.String val)
          Sets a quoted value into the INSERT command.
 void addValue(java.lang.String val)
          Sets an item value into the INSERT command.
 void reset()
          Resets a SQLInsert object (avoiding a object creation)
 void setTable(java.lang.String table)
          Sets the table name.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

tableName

private java.lang.String tableName

colNames

private java.lang.StringBuffer colNames

values

private java.lang.StringBuffer values
Constructor Detail

SQLInsert

public SQLInsert()
Constructor of an INSERT statement with column names and values


SQLInsert

public SQLInsert(boolean withNames)
Constructor of an INSERT statement. the parameter determines if column names will be present.

Parameters:
withNames - true if column names may exist. Even if this parameter is set to true, it is still possible to write only values. But a mixture of calls with and without column names is of course forbidden
Method Detail

setTable

public void setTable(java.lang.String table)
Sets the table name. Such a call is mandatory, but can be written at any stage of the command construction.

Parameters:
table - table name for the INSERT command

addItem

public void addItem(java.lang.String col,
                    java.lang.String val)
Adds an item pair (column name and value) into the INSERT command.

Parameters:
col - column name
val - value. This value will not be enclosed in quotes.

addQuotedItem

public void addQuotedItem(java.lang.String col,
                          java.lang.String val)
Adds an item pair (column name and value) into the INSERT command.

Parameters:
col - column name
val - value. This value will be enclosed in quotes.

addColumn

public void addColumn(java.lang.String col)
Adds a column name into the INSERT command

Parameters:
col - column name

addValue

public void addValue(java.lang.String val)
Sets an item value into the INSERT command.

Parameters:
val - value. This value will not be enclosed in quotes.

addQuotedValue

public void addQuotedValue(java.lang.String val)
Sets a quoted value into the INSERT command.

Parameters:
val - value. This value will be enclosed in quotes.

addNull

public void addNull(java.lang.String col)
Sets a null value with its column name into the INSERT command.

Parameters:
col - column name

addNull

public void addNull()
Sets a null value without a column name into the INSERT command.


reset

public void reset()
Resets a SQLInsert object (avoiding a object creation)


toString

public java.lang.String toString()