Package org.h2.tools

Examples of org.h2.tools.SimpleResultSet$SimpleArray


     * @param r the distance from the point 0/0
     * @param alpha the angle
     * @return a result set with two columns: x and y
     */
    public static ResultSet polar2Cartesian(Double r, Double alpha) {
        SimpleResultSet rs = new SimpleResultSet();
        rs.addColumn("X", Types.DOUBLE, 0, 0);
        rs.addColumn("Y", Types.DOUBLE, 0, 0);
        if (r != null && alpha != null) {
            double x = r.doubleValue() * Math.cos(alpha.doubleValue());
            double y = r.doubleValue() * Math.sin(alpha.doubleValue());
            rs.addRow(x, y);
        }
        return rs;
    }
View Full Code Here


     * @param conn the connection
     * @param query the query
     * @return a result set with the coordinates
     */
    public static ResultSet polar2CartesianSet(Connection conn, String query) throws SQLException {
        SimpleResultSet result = new SimpleResultSet();
        result.addColumn("R", Types.DOUBLE, 0, 0);
        result.addColumn("A", Types.DOUBLE, 0, 0);
        result.addColumn("X", Types.DOUBLE, 0, 0);
        result.addColumn("Y", Types.DOUBLE, 0, 0);
        if (query != null) {
            ResultSet rs = conn.createStatement().executeQuery(query);
            while (rs.next()) {
                double r = rs.getDouble("R");
                double alpha = rs.getDouble("A");
                double x = r * Math.cos(alpha);
                double y = r * Math.sin(alpha);
                result.addRow(r, alpha, x, y);
            }
        }
        return result;
    }
View Full Code Here

     * @param data whether the raw data should be returned
     * @return the result set
     */
    protected static ResultSet search(Connection conn, String text,
            int limit, int offset, boolean data) throws SQLException {
        SimpleResultSet result = createResultSet(data);
        if (conn.getMetaData().getURL().startsWith("jdbc:columnlist:")) {
            // this is just to query the result set columns
            return result;
        }
        if (text == null || text.trim().length() == 0) {
            return result;
        }
        try {
            IndexAccess access = getIndexAccess(conn);
            /*## LUCENE2 begin ##
            access.modifier.flush();
            String path = getIndexPath(conn);
            IndexReader reader = IndexReader.open(path);
            Analyzer analyzer = new StandardAnalyzer();
            Searcher searcher = new IndexSearcher(reader);
            QueryParser parser = new QueryParser(LUCENE_FIELD_DATA, analyzer);
            Query query = parser.parse(text);
            Hits hits = searcher.search(query);
            int max = hits.length();
            if (limit == 0) {
                limit = max;
            }
            for (int i = 0; i < limit && i + offset < max; i++) {
                Document doc = hits.doc(i + offset);
                float score = hits.score(i + offset);
            ## LUCENE2 end ##*/
            //## LUCENE3 begin ##
            // take a reference as the searcher may change
            Searcher searcher = access.searcher;
            // reuse the same analyzer; it's thread-safe;
            // also allows subclasses to control the analyzer used.
            Analyzer analyzer = access.writer.getAnalyzer();
            QueryParser parser = new QueryParser(Version.LUCENE_30,
                    LUCENE_FIELD_DATA, analyzer);
            Query query = parser.parse(text);
            // Lucene 3 insists on a hard limit and will not provide
            // a total hits value. Take at least 100 which is
            // an optimal limit for Lucene as any more
            // will trigger writing results to disk.
            int maxResults = (limit == 0 ? 100 : limit) + offset;
            TopDocs docs = searcher.search(query, maxResults);
            if (limit == 0) {
                limit = docs.totalHits;
            }
            for (int i = 0, len = docs.scoreDocs.length;
                    i < limit && i + offset < docs.totalHits
                    && i + offset < len; i++) {
                ScoreDoc sd = docs.scoreDocs[i + offset];
                Document doc = searcher.doc(sd.doc);
                float score = sd.score;
                //## LUCENE3 end ##
                String q = doc.get(LUCENE_FIELD_QUERY);
                if (data) {
                    int idx = q.indexOf(" WHERE ");
                    JdbcConnection c = (JdbcConnection) conn;
                    Session session = (Session) c.getSession();
                    Parser p = new Parser(session);
                    String tab = q.substring(0, idx);
                    ExpressionColumn expr = (ExpressionColumn) p.parseExpression(tab);
                    String schemaName = expr.getOriginalTableAliasName();
                    String tableName = expr.getColumnName();
                    q = q.substring(idx + " WHERE ".length());
                    Object[][] columnData = parseKey(conn, q);
                    result.addRow(
                            schemaName,
                            tableName,
                            columnData[0],
                            columnData[1],
                            score);
                } else {
                    result.addRow(q, score);
                }
            }
            /*## LUCENE2 begin ##
            // TODO keep it open if possible
            reader.close();
View Full Code Here

    /**
     * Write a CSV file.
     */
    static void write() throws SQLException {
        SimpleResultSet rs = new SimpleResultSet();
        rs.addColumn("NAME", Types.VARCHAR, 255, 0);
        rs.addColumn("EMAIL", Types.VARCHAR, 255, 0);
        rs.addColumn("PHONE", Types.VARCHAR, 255, 0);
        rs.addRow("Bob Meier", "bob.meier@abcde.abc", "+41123456789");
        rs.addRow("John Jones", "john.jones@abcde.abc", "+41976543210");
        Csv.getInstance().write("data/test.csv", rs, null);
    }
View Full Code Here

            if (!parseStatement)
            {
               try
               {
                   // send dataset:
                   SimpleResultSet rs = new SimpleResultSet();
                   rs.addColumn("max_identifier_length", Types.VARCHAR, 255, 0);
                  rs.addRow(new Object[] { "63" });

                   ResultSetMetaData meta = rs.getMetaData();
                   sendRowDescription(meta);
                   while (rs.next())
                   {
                      sendDataRow(rs);
                   }
                   sendCommandComplete(s, 0);
                   s = "";
               }
               catch(Exception e) {}
            }
        }
        // ignore show escape_string_warning: 
        else if (lower.startsWith("show escape_string_warning"))
        {
            if (!parseStatement)
            {
               try
               {
                   // send dataset:
                   SimpleResultSet rs = new SimpleResultSet();
                   rs.addColumn("escape_string_warning", Types.VARCHAR, 255, 0);
                  rs.addRow(new Object[] { "on" });

                   ResultSetMetaData meta = rs.getMetaData();
                   sendRowDescription(meta);
                   while (rs.next())
                   {
                      sendDataRow(rs);
                   }
                   sendCommandComplete(s, 0);
                   s = "";
               }
               catch(Exception e) {}
            }
        }

        // ignore setting encoding:
        else if (lower.startsWith("set client_encoding to"))
        {
            if (!parseStatement)
            {
                sendCommandComplete(s, 0);
                s = "";
            }
            else
            {
                s = "CALL PG_CATALOG.DUMMY_PROCEDURE('')";
            }
        }
        // ignore all LISTEN, NOTIFY & transaction-related commands:
        else if (lower.startsWith("begin") || lower.startsWith("end") || lower.startsWith("commit") || lower.startsWith("start transaction") || lower.startsWith("rollback") || lower.startsWith("notify") || lower.startsWith("listen") || lower.startsWith("unlisten"))       
        {
            if (!parseStatement)
            {
                sendCommandComplete(s, 0);
                s = "";
            }
            // else - replace with relly callable statement:
            else
            {
                // start transaction:
                if (lower.startsWith("begin") || lower.startsWith("start transaction"))
                {               
                    s = "CALL PG_CATALOG.DUMMY_PROCEDURE('START TRANSACTION')";
                }
                // commit:
                else if (lower.startsWith("commit") || lower.startsWith("end"))
                {
                    s = "CALL PG_CATALOG.DUMMY_PROCEDURE('COMMIT')";
                }
                // rollback:
                else if (lower.startsWith("rollback"))
                {
                    s = "CALL PG_CATALOG.DUMMY_PROCEDURE('ROLLBACK')";
                }
                // else:
                else
                {
                    s = "CALL PG_CATALOG.DUMMY_PROCEDURE('')";
                }
            }
        }
        // if not specified FROM clause - replace with pg_catalog.dual table
        // TODO: use regex for better pattern matching
        else if (lower.startsWith("select ") && lower.indexOf("from ") == -1)
        {
            // replace NULL with cast(NULL as char(1))
            s = replaceAll(s, "NULL", "cast(NULL as char(1))");
            // replace current_schema() with current_schema:
            s = replaceAll(s, "current_schema()", "current_schema");
            s = s + " from pg_catalog.dual";
        }
        // columns discovery ODBC query:
        // TODO: ensure that this query will also work in new ODBC provider versions
        else if (lower.startsWith("select n.nspname, c.relname, a.attname, a.atttypid, t.typname, a.attnum, a.attlen, a.atttypmod, a.attnotnull,"))
        {
            // replaced query:
            String replacedQuery = "select * from pg_catalog.internal_columns_view ";

            // where clause:
            String whereClause = "";

            // if search by oid:
            Matcher m = COLUMNS_Q_SEARCH_BY_IDS_1.matcher(s);
            if (m.matches())
            {
                whereClause = " oid = " + m.group(1) + " ";

                m = COLUMNS_Q_SEARCH_BY_IDS_1.matcher(s);
                if (m.find())
                {
                    if (whereClause != "")
                        whereClause += " and ";
                    whereClause += " ordinal_position = " + m.group(1) + " ";
                }
            }
            // else:
            else
            {
                m = COLUMNS_Q_SCHEMA.matcher(s);               
                if (m.find())
                {
                    if (whereClause != "")
                        whereClause += " and ";

                    // remove \\_ escaping:
                    whereClause += " nspname " + m.group(1) + " '" + m.group(2).toString().replace("\\\\_", "_").toUpperCase() + "'";
                }

                m = COLUMNS_Q_TABLE.matcher(s);
                if (m.find())
                {
                    if (whereClause != "")
                        whereClause += " and ";

                    // remove \\_ escaping:
                    whereClause += " relname " + m.group(1) + " '" + m.group(2).toString().replace("\\\\_", "_").toUpperCase() + "'";
                }
            }

            if (whereClause != "")
                replacedQuery += " where " + whereClause;

            replacedQuery += " order by nspname, relname, attnum";
            s = replacedQuery;                       
       
        // ODBC indexes view (ignore it at the moment):
        else if (lower.startsWith("select c.relname, i.indkey, i.indisunique, i.indisclustered, a.amname, c.relhasrules, n.nspname, c.oid from pg_catalog.pg_index"))
        {
            if (!parseStatement)
            {
                try
                {
                    // send dataset:
                    SimpleResultSet rs = new SimpleResultSet();
                    rs.addColumn("RELNAME", Types.VARCHAR, 255, 0);
                    rs.addColumn("INDKEY", Types.INTEGER, 0, 0);
                    rs.addColumn("INDISUNIQUE", Types.BOOLEAN, 0, 0);
                    rs.addColumn("INDISCLUSTERED", Types.BOOLEAN, 0, 0);
                    rs.addColumn("AMNAME", Types.VARCHAR, 0, 0);
                    rs.addColumn("RELHASRULES", Types.BOOLEAN, 0, 0);
                    rs.addColumn("NSPNAME", Types.VARCHAR, 0, 0);
                    rs.addColumn("OID", Types.INTEGER, 0, 0);

                    ResultSetMetaData meta = rs.getMetaData();
                    sendRowDescription(meta);
                    while (rs.next())
                    {
                       sendDataRow(rs);
                    }
                    sendCommandComplete(s, 0);
                    s = "";
View Full Code Here

        return vr;
    }

    private static SimpleResultSet getSimpleResultSet(ResultInterface rs,  int maxrows) {
        int columnCount = rs.getVisibleColumnCount();
        SimpleResultSet simple = new SimpleResultSet();
        for (int i = 0; i < columnCount; i++) {
            String name = rs.getColumnName(i);
            int sqlType = DataType.convertTypeToSQLType(rs.getColumnType(i));
            int precision = MathUtils.convertLongToInt(rs.getColumnPrecision(i));
            int scale = rs.getColumnScale(i);
            simple.addColumn(name, sqlType, precision, scale);
        }
        rs.reset();
        for (int i = 0; i < maxrows && rs.next(); i++) {
            Object[] list = new Object[columnCount];
            for (int j = 0; j < columnCount; j++) {
                list[j] = rs.currentRow()[j].getObject();
            }
            simple.addRow(list);
        }
        return simple;
    }
View Full Code Here

            case BLOB:
                return LobStorage.createSmallLob(BLOB, StringUtils.convertHexToBytes(s.trim()));
            case ARRAY:
                return ValueArray.get(new Value[]{ValueString.get(s)});
            case RESULT_SET: {
                SimpleResultSet rs = new SimpleResultSet();
                rs.addColumn("X", Types.VARCHAR, s.length(), 0);
                rs.addRow(s);
                return ValueResultSet.get(rs);
            }
            case UUID:
                return ValueUuid.get(s);
            default:
View Full Code Here

    public Value copyToTemp() {
        return this;
    }

    public ResultSet getResultSet() {
        SimpleResultSet rs = new SimpleResultSet();
        rs.addColumn("X", DataType.convertTypeToSQLType(getType()), MathUtils.convertLongToInt(getPrecision()), getScale());
        rs.addRow(getObject());
        return rs;
    }
View Full Code Here

                list[i] = readValue();
            }
            return ValueArray.get(list);
        }
        case Value.RESULT_SET: {
            SimpleResultSet rs = new SimpleResultSet();
            int columns = readVarInt();
            for (int i = 0; i < columns; i++) {
                rs.addColumn(readString(), readVarInt(), readVarInt(), readVarInt());
            }
            while (true) {
                if (readByte() == 0) {
                    break;
                }
                Object[] o = new Object[columns];
                for (int i = 0; i < columns; i++) {
                    o[i] = readValue().getObject();
                }
                rs.addRow(o);
            }
            return ValueResultSet.get(rs);
        }
        default:
            if (type >= INT_0_15 && type < INT_0_15 + 16) {
View Full Code Here

            return meta.getUDTs(p[1], p[2], p[3], types);
        } else if (isBuiltIn(sql, "@version_columns")) {
            String[] p = split(sql);
            return meta.getVersionColumns(p[1], p[2], p[3]);
        } else if (isBuiltIn(sql, "@memory")) {
            SimpleResultSet rs = new SimpleResultSet();
            rs.addColumn("Type", Types.VARCHAR, 0, 0);
            rs.addColumn("KB", Types.VARCHAR, 0, 0);
            rs.addRow("Used Memory", "" + Utils.getMemoryUsed());
            rs.addRow("Free Memory", "" + Utils.getMemoryFree());
            return rs;
        } else if (isBuiltIn(sql, "@info")) {
            SimpleResultSet rs = new SimpleResultSet();
            rs.addColumn("KEY", Types.VARCHAR, 0, 0);
            rs.addColumn("VALUE", Types.VARCHAR, 0, 0);
            rs.addRow("conn.getCatalog", conn.getCatalog());
            rs.addRow("conn.getAutoCommit", "" + conn.getAutoCommit());
            rs.addRow("conn.getTransactionIsolation", "" + conn.getTransactionIsolation());
            rs.addRow("conn.getWarnings", "" + conn.getWarnings());
            String map;
            try {
                map = "" + conn.getTypeMap();
            } catch (SQLException e) {
                map = e.toString();
            }
            rs.addRow("conn.getTypeMap", "" + map);
            rs.addRow("conn.isReadOnly", "" + conn.isReadOnly());
            rs.addRow("conn.getHoldability", "" + conn.getHoldability());
            addDatabaseMetaData(rs, meta);
            return rs;
        } else if (isBuiltIn(sql, "@attributes")) {
            String[] p = split(sql);
            return meta.getAttributes(p[1], p[2], p[3], p[4]);
        } else if (isBuiltIn(sql, "@super_tables")) {
            String[] p = split(sql);
            return meta.getSuperTables(p[1], p[2], p[3]);
        } else if (isBuiltIn(sql, "@super_types")) {
            String[] p = split(sql);
            return meta.getSuperTypes(p[1], p[2], p[3]);
        } else if (isBuiltIn(sql, "@prof_stop")) {
            if (profiler != null) {
                profiler.stopCollecting();
                SimpleResultSet rs = new SimpleResultSet();
                rs.addColumn("Top Stack Trace(s)", Types.VARCHAR, 0, 0);
                rs.addRow(profiler.getTop(3));
                profiler = null;
                return rs;
            }
        }
        return null;
View Full Code Here

TOP

Related Classes of org.h2.tools.SimpleResultSet$SimpleArray

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.