Top Description Fields Constructors Methods
org.h2.util

public Class ScriptReader

extends Object
implements Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable
Imports
java.io.Closeable, .IOException, .Reader, java.util.Arrays, org.h2.engine.Constants, org.h2.message.DbException

This class can split SQL scripts to single SQL statements. Each SQL statement ends with the character ';', however it is ignored in comments and quotes.

Field Summary

Modifier and TypeField and Description
private boolean
blockRemark

Only valid if insideRemark is true.

private char[]
private int
bufferEnd

The position in the buffer of the last available char

private int
bufferPos

The position in the buffer of the next char to be read

private int
bufferStart

The position in the buffer of the statement start

private boolean
endOfFile

True if we have read past the end of file

private boolean
insideRemark

True if we are inside a comment

private final Reader
private int
remarkStart

The position in buffer of start of comment

private boolean
skipRemarks

True if comments should be skipped completely by this reader.

Constructor Summary

AccessConstructor and Description
public
ScriptReader(Reader
the reader
reader
)

Create a new SQL script reader from the given reader

Method Summary

Modifier and TypeMethod and Description
private void
public void
close()

Implements java.io.Closeable.close.

Close the underlying reader.

private void
public boolean

Returns:

true if inside a block comment
isBlockRemark
()

If currently inside a remark, this method tells if it is a block comment (true) or single line comment (false)

public boolean

Returns:

true if the current position is inside a remark
isInsideRemark
()

Check if this is the last statement, and if the single line or block comment is not finished yet.

private int
read()

private int
public String

Returns:

the SQL statement or null
readStatement
()

Read a statement from the reader.

private String
public void
setSkipRemarks(boolean
true if comments should be skipped
skipRemarks
)

If comments should be skipped completely by this reader.

private void
startRemark(boolean block)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

blockRemarkback to summary
private boolean blockRemark

Only valid if insideRemark is true. True if we are inside a block comment, false if we are inside a line comment

bufferback to summary
private char[] buffer
bufferEndback to summary
private int bufferEnd

The position in the buffer of the last available char

bufferPosback to summary
private int bufferPos

The position in the buffer of the next char to be read

bufferStartback to summary
private int bufferStart

The position in the buffer of the statement start

endOfFileback to summary
private boolean endOfFile

True if we have read past the end of file

insideRemarkback to summary
private boolean insideRemark

True if we are inside a comment

readerback to summary
private final Reader reader
remarkStartback to summary
private int remarkStart

The position in buffer of start of comment

skipRemarksback to summary
private boolean skipRemarks

True if comments should be skipped completely by this reader.

Constructor Detail

ScriptReaderback to summary
public ScriptReader(Reader reader)

Create a new SQL script reader from the given reader

Parameters
reader:Reader

the reader

Method Detail

clearRemarkback to summary
private void clearRemark()
closeback to summary
public void close()

Implements java.io.Closeable.close.

Close the underlying reader.

Annotations
@Override
endRemarkback to summary
private void endRemark()
isBlockRemarkback to summary
public boolean isBlockRemark()

If currently inside a remark, this method tells if it is a block comment (true) or single line comment (false)

Returns:boolean

true if inside a block comment

isInsideRemarkback to summary
public boolean isInsideRemark()

Check if this is the last statement, and if the single line or block comment is not finished yet.

Returns:boolean

true if the current position is inside a remark

readback to summary
private int read() throws IOException
readBufferback to summary
private int readBuffer() throws IOException
readStatementback to summary
public String readStatement()

Read a statement from the reader. This method returns null if the end has been reached.

Returns:String

the SQL statement or null

readStatementLoopback to summary
private String readStatementLoop() throws IOException
setSkipRemarksback to summary
public void setSkipRemarks(boolean skipRemarks)

If comments should be skipped completely by this reader.

Parameters
skipRemarks:boolean

true if comments should be skipped

startRemarkback to summary
private void startRemark(boolean block)