: Class Insert

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## ModSQL
Class Insert

    java.lang.Object
      |
      +--ModSQL.Insert

All Implemented Interfaces:
  Query

final class Insert
extends Object
implements Query

Insert parses and executes an SQL INSERT query.

Author:
  chris.studholme@utoronto.ca

Field Summary
`private int[]` | `column_index` Array of indices of columns to insert (set by optimize).
`private int[]` | `column_type` Array of column types (set by optimize).
`private String[]` | `columns` Array of column names to insert.
`private DatabaseManager` | `manager` Table manager used to open tables.
`private Table` | `source` Rows of data to insert.
`private DatabaseTable` | `table` Database table to insert rows into (set by optimize).
`private String` | `tablename` Name of table.

Constructor Summary
`Insert(StreamTokenizer tokenizer, DatabaseManager manager)` Contructor to parse query.

Method Summary
`void` | `close()` Close query and free resources in use.
`int` | `execute()` Execute the query.
`static Object` | `getCompatibleType(Object x, int type)` Convert the supplied object to an object compatible with the specified SQL type.
`void` | `optimize()` Optimize query.
`private void` | `ParseInsert(StreamTokenizer tokenizer)` Parse update query of the form: `INSERT INTO tablename (columns,...) VALUES (values,...); INSERT INTO tablename (columns,...) SELECT ...;`
`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.

### columns

    private String[] columns

  Array of column names to insert.

### source

    private Table source

  Rows of data to insert.

### table

    private DatabaseTable table

  Database table to insert rows into (set by optimize).

### column_index

    private int[] column_index

  Array of indices of columns to insert (set by optimize).

### column_type

    private int[] column_type

  Array of column types (set by optimize).

### manager

    private transient DatabaseManager manager

  Table manager used to open tables.

Constructor Detail

### Insert

    public Insert(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

### ParseInsert

    private void ParseInsert(StreamTokenizer tokenizer)
                      throws SQLException,
                             IOException

  Parse update query of the form:

  > `INSERT INTO tablename (columns,...) VALUES (values,...);
  > INSERT INTO tablename (columns,...) SELECT ...;`

  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 inserted
  Throws:
    `SQLException` - if an error occurs

### getCompatibleType

    public static Object getCompatibleType(Object x,
                                           int type)
                                    throws SQLException

  Convert the supplied object to an object compatible with the specified SQL type. If the supplied object already has the correct type, it will be returned. If null is passed in, null will be returned.
  Parameters:
    `x` - object to convert
    `type` - SQL type to convert to
  Returns:
    object compatible with the specified type
  Throws:
    `SQLException` - if a type mismatch occurs

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD