ModSQL
Class Update

java.lang.Object
  |
  +--ModSQL.Update
All Implemented Interfaces:
Query

final class Update
extends Object
implements Query

Update will parse and execute an SQL UPDATE query.

Author:
chris.studholme@utoronto.ca

Field Summary
private  int[] column_index
          Array of indices of columns to update (set by optimize).
private  int[] column_type
          Array of column types (set by optimize).
private  TableReader reader
          Reader used to fetch rows (set by optimize).
private  String[] set_column
          Array of column names to update.
private  Function[] set_value
          New values for columns.
private  DatabaseTable table
          Database table to update (set by optimize).
protected  DatabaseManager tablemanager
          Table manager used to open tables.
private  String tablename
          Name of table.
private  Function where
          Where clause used to choose rows.
 
Constructor Summary
protected Update(StreamTokenizer tokenizer, DatabaseManager manager)
          Contructor to parse query.
 
Method Summary
 void close()
          Close query and free resources in use.
 int execute()
          Execute the query.
 void optimize()
          Optimize query.
private  void ParseUpdate(StreamTokenizer tokenizer)
          Parse update query of the form:
UPDATE tablename SET columns [ WHERE condition ]
 String toString()
          Returns human-readable string version of query (with surrounding brackets).
 String toString(boolean with_brackets)
          Returns human-readable string version of query.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

tablename

private String tablename
Name of table.

set_column

private String[] set_column
Array of column names to update.

set_value

private Function[] set_value
New values for columns.

where

private Function where
Where clause used to choose rows.

reader

private TableReader reader
Reader used to fetch rows (set by optimize).

table

private DatabaseTable table
Database table to update (set by optimize).

column_index

private int[] column_index
Array of indices of columns to update (set by optimize).

column_type

private int[] column_type
Array of column types (set by optimize).

tablemanager

protected transient DatabaseManager tablemanager
Table manager used to open tables.
Constructor Detail

Update

protected Update(StreamTokenizer tokenizer,
                 DatabaseManager manager)
          throws SQLException,
                 IOException
Contructor to parse query.
Parameters:
tokenizer - StreamTokenizer that SQL tokens should be read from
manager - manager to use when looking up tables
Throws:
SQLException - if an error occurs
IOException - if there is a problem reading the query
Method Detail

close

public void close()
Close query and free resources in use.
Specified by:
close in interface Query
Following copied from interface: ModSQL.Query
Throws:
SQLException - if an error occurs

toString

public String toString()
Returns human-readable string version of query (with surrounding brackets).
Overrides:
toString in class Object
Returns:
String representation of query

toString

public String toString(boolean with_brackets)
Returns human-readable string version of query.
Specified by:
toString in interface Query
Parameters:
with_brackets - true to include surrounding brackets
Returns:
String representation of query

ParseUpdate

private void ParseUpdate(StreamTokenizer tokenizer)
                  throws SQLException,
                         IOException
Parse update query of the form:
UPDATE tablename SET columns [ WHERE condition ]
Parameters:
tokenizer - StreamTokenizer that SQL tokens should be read from
Throws:
SQLException - if an error occurs
IOException - if there is a problem reading the query

optimize

public void optimize()
              throws SQLException
Optimize query.
Specified by:
optimize in interface Query
Throws:
SQLException - if an error occurs

execute

public int execute()
            throws SQLException
Execute the query.
Specified by:
execute in interface Query
Returns:
number of rows updated
Throws:
SQLException - if an error occurs