Package org.h2.util

Class ScriptReader

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class ScriptReader
    extends java.lang.Object
    implements java.io.Closeable
    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

      Fields 
      Modifier and Type Field Description
      private boolean blockRemark
      Only valid if insideRemark is true.
      private char[] buffer  
      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 java.io.Reader 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

      Constructors 
      Constructor Description
      ScriptReader​(java.io.Reader reader)
      Create a new SQL script reader from the given reader
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void clearRemark()  
      void close()
      Close the underlying reader.
      private void endRemark()  
      boolean isBlockRemark()
      If currently inside a remark, this method tells if it is a block comment (true) or single line comment (false)
      boolean 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 readBuffer()  
      java.lang.String readStatement()
      Read a statement from the reader.
      private java.lang.String readStatementLoop()  
      void setSkipRemarks​(boolean skipRemarks)
      If comments should be skipped completely by this reader.
      private void startRemark​(boolean block)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • reader

        private final java.io.Reader reader
      • buffer

        private char[] buffer
      • bufferPos

        private int bufferPos
        The position in the buffer of the next char to be read
      • bufferStart

        private int bufferStart
        The position in the buffer of the statement start
      • bufferEnd

        private int bufferEnd
        The position in the buffer of the last available char
      • endOfFile

        private boolean endOfFile
        True if we have read past the end of file
      • insideRemark

        private boolean insideRemark
        True if we are inside a comment
      • blockRemark

        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
      • skipRemarks

        private boolean skipRemarks
        True if comments should be skipped completely by this reader.
      • remarkStart

        private int remarkStart
        The position in buffer of start of comment
    • Constructor Detail

      • ScriptReader

        public ScriptReader​(java.io.Reader reader)
        Create a new SQL script reader from the given reader
        Parameters:
        reader - the reader
    • Method Detail

      • close

        public void close()
        Close the underlying reader.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
      • readStatement

        public java.lang.String readStatement()
        Read a statement from the reader. This method returns null if the end has been reached.
        Returns:
        the SQL statement or null
      • readStatementLoop

        private java.lang.String readStatementLoop()
                                            throws java.io.IOException
        Throws:
        java.io.IOException
      • startRemark

        private void startRemark​(boolean block)
      • endRemark

        private void endRemark()
      • clearRemark

        private void clearRemark()
      • read

        private int read()
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • readBuffer

        private int readBuffer()
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • isInsideRemark

        public boolean isInsideRemark()
        Check if this is the last statement, and if the single line or block comment is not finished yet.
        Returns:
        true if the current position is inside a remark
      • isBlockRemark

        public boolean isBlockRemark()
        If currently inside a remark, this method tells if it is a block comment (true) or single line comment (false)
        Returns:
        true if inside a block comment
      • setSkipRemarks

        public void setSkipRemarks​(boolean skipRemarks)
        If comments should be skipped completely by this reader.
        Parameters:
        skipRemarks - true if comments should be skipped