| java.lang.Object org.hsqldb.util.SqlFile
SqlFile | public class SqlFile (Code) | | Encapsulation of a sql text file like 'myscript.sql'.
The ultimate goal is to run the execute() method to feed the SQL
commands within the file to a jdbc connection.
Some implementation comments and variable names use keywords based
on the following definitions.
- COMMAND = Statement || SpecialCommand || BufferCommand
Statement = SQL statement like "SQL Statement;"
SpecialCommand = Special Command like "\x arg..."
BufferCommand = Editing/buffer command like ":s/this/that/"
When entering SQL statements, you are always "appending" to the
"immediate" command (not the "buffer", which is a different thing).
All you can do to the immediate command is append new lines to it,
execute it, or save it to buffer.
When you are entering a buffer edit command like ":s/this/that/",
your immediate command is the buffer-edit-command. The buffer
is the command string that you are editing.
The buffer usually contains either an exact copy of the last command
executed or sent to buffer by entering a blank line,
but BUFFER commands can change the contents of the buffer.
In general, the special commands mirror those of Postgresql's psql,
but SqlFile handles command editing much different from Postgresql
because of Java's lack of support for raw tty I/O.
The \p special command, in particular, is very different from psql's.
Buffer commands are unique to SQLFile. The ":" commands allow
you to edit the buffer and to execute the buffer.
\d commands are very poorly supported for Mysql because
(a) Mysql lacks most of the most basic JDBC support elements, and
the most basic role and schema features, and
(b) to access the Mysql data dictionay, one must change the database
instance (to do that would require work to restore the original state
and could have disastrous effects upon transactions).
To make changes to this class less destructive to external callers,
the input parameters should be moved to setters (probably JavaBean
setters would be best) instead of constructor args and System
Properties.
The process*() methods, other than processBuffHist() ALWAYS execute
on "buffer", and expect it to contain the method specific prefix
(if any).
version: $Revision: 1.169 $ author: Blaine Simpson unsaved@users |
Constructor Summary | |
public | SqlFile(File inFile, boolean inInteractive, Map inVars) Interpret lines of input file as SQL Statements, Comments,
Special Commands, and Buffer Commands. | public | SqlFile(boolean inInteractive, Map inVars) Constructor for reading stdin instead of a file for commands. |
Method Summary | |
public static void | appendLine(StringBuffer sb, String s) | 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. | public static String | convertEscapes(String inString) Translates user-supplied escapes into the traditionaly corresponding
corresponding binary characters. | public void | dsvSafe(String s) Validate that String is safe to display in a DSV file. | public void | execute(Connection conn, Boolean coeOverride) Process all the commands on stdin. | public void | execute(Connection conn, boolean coeOverride) Process all the commands on stdin. | public synchronized void | execute(Connection conn, PrintStream stdIn, PrintStream errIn, Boolean coeOverride) 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'. | public void | importDsv(String filePath, String skipPrefix) Name is self-explanatory. | public static byte[] | loadBinary(File binFile) | static int | pastName(String inString, int startIndex) Returns index specifying 1 past end of a variable name. | public void | processFromBuffer() Execute processSql/processPL/processSpecial from buffer. | public static String | sqlTypeToString(int i) | public static byte[] | streamToBytes(InputStream is) | public String | streamToString(InputStream is, String cs) As the name says... |
binBuffer | byte[] binBuffer(Code) | | |
oldestHist | int oldestHist(Code) | | |
plMode | public boolean plMode(Code) | | |
possiblyUncommitteds | BooleanBucket possiblyUncommitteds(Code) | | |
recursed | public boolean recursed(Code) | | |
SqlFile | public SqlFile(File inFile, boolean inInteractive, Map inVars) throws IOException(Code) | | 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. Parameters: inInteractive - If true, prompts are printed, the interactiveSpecial commands are enabled, andcontinueOnError defaults to true. throws: IOException - If can't open specified SQL file. |
canDisplayType | public static boolean canDisplayType(int i)(Code) | | 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: java.sql.Types |
convertEscapes | public static String convertEscapes(String inString)(Code) | | Translates user-supplied escapes into the traditionaly corresponding
corresponding binary characters.
Allowed sequences:
- \0\d+ (an octal digit)
- \[0-9]\d* (a decimal digit)
- \[Xx][0-9]{2} (a hex digit)
- \n Newline (Ctrl-J)
- \r Carriage return (Ctrl-M)
- \t Horizontal tab (Ctrl-I)
- \f Form feed (Ctrl-L)
Java 1.4 String methods will make this into a 1 or 2 line task.
|
execute | public synchronized void execute(Connection conn, PrintStream stdIn, PrintStream errIn, Boolean coeOverride) throws SqlToolError, SQLException(Code) | | 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: SQLExceptions - thrown by JDBC driver.Only possible if in "\c false" mode. throws: SqlToolError - all other errors.This includes including QuitNow, BreakException,ContinueException for recursive calls only. |
importDsv | public void importDsv(String filePath, String skipPrefix) throws SqlToolError(Code) | | 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: SqlToolError - Would prefer to throw an internal exception,but we want this method to have externalvisibility. |
pastName | static int pastName(String inString, int startIndex)(Code) | | Returns index specifying 1 past end of a variable name.
Parameters: inString - String containing a variable name Parameters: startIndex - Index within inString where the variable name begins |
processFromBuffer | public void processFromBuffer() throws BadSpecial, SQLException, SqlToolError(Code) | | Execute processSql/processPL/processSpecial from buffer.
|
sqlTypeToString | public static String sqlTypeToString(int i)(Code) | | |
|
|