ModSQL
Class Create

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

final class Create
extends Object
implements Query

Create will parse a CREATE SQL statement. Currently, only tables and indices can be created.

Author:
chris.studholme@utoronto.ca

Field Summary
(package private)  String[] column_names
          Names of columns to include in new table.
(package private)  int[][] column_types
          SQL types of columns to create.
(package private)  String indexed_column
          Name of column to index.
(package private)  String indexed_table
          Name of table to index.
(package private)  String indexname
          Name of index to create.
(package private)  String indextype
          Type of index to create.
protected  DatabaseManager tablemanager
          Table manager used to open tables and create new tables.
(package private)  String tablename
          Name of table to create.
 
Constructor Summary
protected Create(StreamTokenizer tokenizer, DatabaseManager manager)
          Contructor to parse query.
 
Method Summary
 void close()
          Close query and free resources in use.
private static String columnType(int[] type)
          Returns a String representation of an SQL type.
 int execute()
          Execute the query.
 void optimize()
          Optimize query.
private static int[] parseColumnType(StreamTokenizer tokenizer)
          Parses an SQL type and returns a two element array describing the type.
private  void ParseCreate(StreamTokenizer tokenizer)
          Parse create query of the form:
CREATE INDEX [indexname] ON tablename [USING indextype] (column);
CREATE TABLE tablename (column list);
private  void ParseCreateIndex(StreamTokenizer tokenizer)
          Parse create index query of the form:
CREATE INDEX [indexname] ON tablename [USING indextype] (column);
private  void ParseCreateTable(StreamTokenizer tokenizer)
          Parse create table query of the form:
CREATE TABLE tablename (column list);
 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

indexname

String indexname
Name of index to create.

indextype

String indextype
Type of index to create.

indexed_table

String indexed_table
Name of table to index.

indexed_column

String indexed_column
Name of column to index.

tablename

String tablename
Name of table to create.

column_names

String[] column_names
Names of columns to include in new table.

column_types

int[][] column_types
SQL types of columns to create.

tablemanager

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

Create

protected Create(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

ParseCreate

private void ParseCreate(StreamTokenizer tokenizer)
                  throws SQLException,
                         IOException
Parse create query of the form:
CREATE INDEX [indexname] ON tablename [USING indextype] (column);
CREATE TABLE tablename (column list);
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

ParseCreateIndex

private void ParseCreateIndex(StreamTokenizer tokenizer)
                       throws SQLException,
                              IOException
Parse create index query of the form:
CREATE INDEX [indexname] ON tablename [USING indextype] (column);
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

parseColumnType

private static int[] parseColumnType(StreamTokenizer tokenizer)
                              throws SQLException,
                                     IOException
Parses an SQL type and returns a two element array describing the type. The first element of the array is the SQL type code. The second element is the maximum length for variable length fields.
Parameters:
tokenizer - StreamTokenizer that SQL tokens should be read from
Returns:
two element array describing parsed type
Throws:
SQLException - if an error occurs
IOException - if there is a problem reading the query

ParseCreateTable

private void ParseCreateTable(StreamTokenizer tokenizer)
                       throws SQLException,
                              IOException
Parse create table query of the form:
CREATE TABLE tablename (column list);
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()
Optimize query.
Specified by:
optimize in interface Query
Following copied from interface: ModSQL.Query
Throws:
SQLException - if an error occurs

execute

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

columnType

private static String columnType(int[] type)
Returns a String representation of an SQL type.
Parameters:
type - first index is type, second is maximum length where needed
Returns:
String representing type