Package org.h2.util

Examples of org.h2.util.ScriptReader


        conn.close();
        deleteDb("nestedJoins");
    }

    private static String cleanRemarks(String sql) {
        ScriptReader r = new ScriptReader(new StringReader(sql));
        r.setSkipRemarks(true);
        sql = r.readStatement();
        sql = sql.replaceAll("\\n", " ");
        while (sql.indexOf("  ") >= 0) {
            sql = sql.replaceAll("  ", " ");
        }
        return sql;
View Full Code Here


        conn.close();
        deleteDb("nestedJoins");
    }

    private static String cleanRemarks(String sql) {
        ScriptReader r = new ScriptReader(new StringReader(sql));
        r.setSkipRemarks(true);
        sql = r.readStatement();
        sql = sql.replaceAll("\\n", " ");
        while (sql.indexOf("  ") >= 0) {
            sql = sql.replaceAll("  ", " ");
        }
        return sql;
View Full Code Here

            stat = conn.createStatement();
        }
        if (sql == null) {
            promptLoop();
        } else {
            ScriptReader r = new ScriptReader(new StringReader(sql));
            while (true) {
                String s = r.readStatement();
                if (s == null) {
                    break;
                }
                execute(s);
            }
View Full Code Here

        try {
            String sql = query;
            if (sql.endsWith(";")) {
                sql += " ";
            }
            ScriptReader reader = new ScriptReader(new StringReader(sql));
            reader.setSkipRemarks(true);
            String lastSql = "";
            while (true) {
                String n = reader.readStatement();
                if (n == null) {
                    break;
                }
                lastSql = n;
            }
            String result = "";
            if (reader.isInsideRemark()) {
                if (reader.isBlockRemark()) {
                    result = "1#(End Remark)# */\n" + result;
                } else {
                    result = "1#(Newline)#\n" + result;
                }
            } else {
View Full Code Here

    }

    private String query() {
        String sql = attributes.getProperty("sql").trim();
        try {
            ScriptReader r = new ScriptReader(new StringReader(sql));
            final ArrayList<String> list = New.arrayList();
            while (true) {
                String s = r.readStatement();
                if (s == null) {
                    break;
                }
                list.add(s);
            }
View Full Code Here

            break;
        }
        case 'Q': {
            server.trace("Query");
            String query = readString();
            ScriptReader reader = new ScriptReader(new StringReader(query));
            while (true) {
                JdbcStatement stat = null;
                try {
                    String s = reader.readStatement();
                    if (s == null) {
                        break;
                    }
                    s = getSQL(s);
                    stat = (JdbcStatement) conn.createStatement();
View Full Code Here

    private static void installPgCatalog(Statement stat) throws SQLException {
        Reader r = null;
        try {
            r = new InputStreamReader(new ByteArrayInputStream(Utils
                    .getResource("/org/h2/server/pg/pg_catalog.sql")));
            ScriptReader reader = new ScriptReader(r);
            while (true) {
                String sql = reader.readStatement();
                if (sql == null) {
                    break;
                }
                stat.execute(sql);
            }
            reader.close();
        } catch (IOException e) {
            throw DbException.convertIOException(e, "Can not read pg_catalog resource");
        } finally {
            IOUtils.closeSilently(r);
        }
View Full Code Here

     * @return the last result set
     */
    public static ResultSet execute(Connection conn, Reader reader) throws SQLException {
        Statement stat = conn.createStatement();
        ResultSet rs = null;
        ScriptReader r = new ScriptReader(reader);
        while (true) {
            String sql = r.readStatement();
            if (sql == null) {
                break;
            }
            boolean resultSet = stat.execute(sql);
            if (resultSet) {
View Full Code Here

    }

    private void process(Connection conn, boolean continueOnError,
            String path, Reader reader, String charsetName) throws SQLException, IOException {
        Statement stat = conn.createStatement();
        ScriptReader r = new ScriptReader(reader);
        while (true) {
            String sql = r.readStatement();
            if (sql == null) {
                break;
            }
            String trim = sql.trim();
            if (trim.startsWith("@") && StringUtils.toUpperEnglish(trim).startsWith("@INCLUDE")) {
                sql = trim;
                sql = sql.substring("@INCLUDE".length()).trim();
                if (!IOUtils.isAbsolute(sql)) {
                    sql = path + SysProperties.FILE_SEPARATOR + sql;
                }
                process(conn, sql, continueOnError, charsetName);
            } else {
                try {
                    if (trim.length() > 0) {
                        if (showResults && !trim.startsWith("-->")) {
                            out.print(sql + ";");
                        }
                        if (showResults || checkResults) {
                            boolean query = stat.execute(sql);
                            if (query) {
                                ResultSet rs = stat.getResultSet();
                                int columns = rs.getMetaData().getColumnCount();
                                StringBuilder buff = new StringBuilder();
                                while (rs.next()) {
                                    buff.append("\n-->");
                                    for (int i = 0; i < columns; i++) {
                                        String s = rs.getString(i + 1);
                                        if (s != null) {
                                            s = StringUtils.replaceAll(s, "\r\n", "\n");
                                            s = StringUtils.replaceAll(s, "\n", "\n-->    ");
                                            s = StringUtils.replaceAll(s, "\r", "\r-->    ");
                                        }
                                        buff.append(' ').append(s);
                                    }
                                }
                                buff.append("\n;");
                                String result = buff.toString();
                                if (showResults) {
                                    out.print(result);
                                }
                                if (checkResults) {
                                    String expected = r.readStatement() + ";";
                                    expected = StringUtils.replaceAll(expected, "\r\n", "\n");
                                    expected = StringUtils.replaceAll(expected, "\r", "\n");
                                    if (!expected.equals(result)) {
                                        expected = StringUtils.replaceAll(expected, " ", "+");
                                        result = StringUtils.replaceAll(result, " ", "+");
View Full Code Here

            Class.forName("org.h2.upgrade.v1_1.Driver");
            conn = DriverManager.getConnection("jdbc:h2v1_1:mem:");
        }
        conn.createStatement().execute(buildSql);
        String newsfeed = IOUtils.readStringAndClose(new FileReader("src/tools/org/h2/build/doc/buildNewsfeed.sql"), -1);
        ScriptReader r = new ScriptReader(new StringReader(newsfeed));
        Statement stat = conn.createStatement();
        ResultSet rs = null;
        while (true) {
            String s = r.readStatement();
            if (s == null) {
                break;
            }
            if (stat.execute(s)) {
                rs = stat.getResultSet();
View Full Code Here

TOP

Related Classes of org.h2.util.ScriptReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.