jcolibri.test.database
Class SqlFile

java.lang.Object
  extended by jcolibri.test.database.SqlFile

public class SqlFile
extends java.lang.Object


Field Summary
 boolean plMode
           
 boolean recursed
           
 
Constructor Summary
SqlFile(boolean inInteractive, java.util.HashMap inVars)
          Constructor for reading stdin instead of a file for commands.
SqlFile(java.io.File inFile, boolean inInteractive, java.util.HashMap inVars)
          Interpret lines of input file as SQL Statements, Comments, Special Commands, and Buffer Commands.
 
Method Summary
static boolean canDisplayType(int i)
          This method is used to tell SqlFile whether this Sql Type must ALWAYS be loaded to the binary buffer without displaying.
static java.lang.String convertEscapes(java.lang.String inString)
           
 void csvSafe(java.lang.String s)
          Validate that String is safe to display in a CSV file.
 void execute(java.sql.Connection conn, boolean coeOverride)
          Process all the commands on stdin.
 void execute(java.sql.Connection conn, java.lang.Boolean coeOverride)
          Process all the commands on stdin.
 void execute(java.sql.Connection conn, java.io.PrintStream stdIn, java.io.PrintStream errIn, java.lang.Boolean coeOverride)
          Process all the commands in the file (or stdin) associated with "this" object.
static java.lang.String[] getTokenArray(java.lang.String inString)
           
 void importCsv(java.lang.String filePath)
          Name is self-explanatory.
static java.lang.String sqlTypeToString(int i)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

recursed

public boolean recursed

plMode

public boolean plMode
Constructor Detail

SqlFile

public SqlFile(java.io.File inFile,
               boolean inInteractive,
               java.util.HashMap inVars)
        throws java.io.IOException
Interpret lines of input file as SQL Statements, Comments, Special Commands, and Buffer Commands. Most Special Commands and many Buffer commands are only for interactive use.

Parameters:
inFile - inFile of null means to read stdin.
inInteractive - If true, prompts are printed, the interactive Special commands are enabled, and continueOnError defaults to true.
Throws:
java.io.IOException

SqlFile

public SqlFile(boolean inInteractive,
               java.util.HashMap inVars)
        throws java.io.IOException
Constructor for reading stdin instead of a file for commands.

Throws:
java.io.IOException
Method Detail

execute

public void execute(java.sql.Connection conn,
                    java.lang.Boolean coeOverride)
             throws java.io.IOException,
                    org.hsqldb.util.SqlToolError,
                    java.sql.SQLException
Process all the commands on stdin.

Parameters:
conn - The JDBC connection to use for SQL Commands.
Throws:
java.io.IOException
org.hsqldb.util.SqlToolError
java.sql.SQLException

execute

public void execute(java.sql.Connection conn,
                    boolean coeOverride)
             throws java.io.IOException,
                    org.hsqldb.util.SqlToolError,
                    java.sql.SQLException
Process all the commands on stdin.

Parameters:
conn - The JDBC connection to use for SQL Commands.
Throws:
java.io.IOException
org.hsqldb.util.SqlToolError
java.sql.SQLException

execute

public void execute(java.sql.Connection conn,
                    java.io.PrintStream stdIn,
                    java.io.PrintStream errIn,
                    java.lang.Boolean coeOverride)
             throws java.io.IOException,
                    org.hsqldb.util.SqlToolError,
                    java.sql.SQLException
Process all the commands in the file (or stdin) associated with "this" object. Run SQL in the file through the given database connection. This is synchronized so that I can use object variables to keep track of current line number, command, connection, i/o streams, etc. Sets encoding character set to that specified with System Property 'sqlfile.charset'. Defaults to "US-ASCII".

Parameters:
conn - The JDBC connection to use for SQL Commands.
Throws:
java.io.IOException
org.hsqldb.util.SqlToolError
java.sql.SQLException

getTokenArray

public static java.lang.String[] getTokenArray(java.lang.String inString)

canDisplayType

public static boolean canDisplayType(int i)
This method is used to tell SqlFile whether this Sql Type must ALWAYS be loaded to the binary buffer without displaying. N.b.: If this returns "true" for a type, then the user can never "see" values for these columns. Therefore, if a type may-or-may-not-be displayable, better to return false here and let the user choose. In general, if there is a toString() operator for this Sql Type then return false, since the JDBC driver should know how to make the value displayable. The table on this page lists the most common SqlTypes, all of which must implement toString(): http://java.sun.com/docs/books/tutorial/jdbc/basics/retrieving.html

See Also:
Types

sqlTypeToString

public static java.lang.String sqlTypeToString(int i)

csvSafe

public void csvSafe(java.lang.String s)
             throws java.sql.SQLException
Validate that String is safe to display in a CSV file.

Throws:
java.sql.SQLException - (should throw something else, since this is not an SQL problem. Fix the caller!)

convertEscapes

public static java.lang.String convertEscapes(java.lang.String inString)

importCsv

public void importCsv(java.lang.String filePath)
               throws java.io.IOException,
                      jcolibri.test.database.SqlFile.BadSpecial
Name is self-explanatory. If there is user demand, open file in random access mode so don't need to load 2 copies of the entire file into memory. This will be difficult because can't use standard Java language features to search through a character array for multi-character substrings.

Throws:
java.io.IOException
jcolibri.test.database.SqlFile.BadSpecial

GAIA - Group for Artificial Intelligence Applications
http://gaia.fdi.ucm.es