Package org.eigenbase.sql.util

Examples of org.eigenbase.sql.util.SqlBuilder


        RelOptCluster cluster,
        RelOptConnection connection)
    {
        String queryString = getFemView().getQueryExpression().getBody();
        if (datasetName != null) {
            final SqlBuilder buf = new SqlBuilder(SqlDialect.EIGENBASE);
            buf.append(
                ((modality == ModalityTypeEnum.MODALITYTYPE_STREAM)
                 ? "SELECT STREAM"
                 : "SELECT"))
                .append(" * FROM (")
                .append(queryString)
                .append(") AS x TABLESAMPLE SUBSTITUTE (")
                .literal(datasetName)
                .append(")");
            queryString = buf.getSql();
        }
        return expandView(queryString);
    }
View Full Code Here


        String serverName,
        Map<String, String> tableOptions)
        throws SQLException
    {
        final String methodName = "browse_table";
        final SqlBuilder selectSqlBuilder = createSqlBuilder();
        selectSqlBuilder
            .append("select * from table(sys_boot.mgmt.")
            .append(methodName)
            .append("(")
            .literal(serverName)
            .append(", ");
        toValues(selectSqlBuilder, tableOptions)
            .append(", ")
            .literal(locale.toString())
            .append("))");
        final String sql = selectSqlBuilder.getSql();
        return getProperties(methodName, sql);
    }
View Full Code Here

        Map<String, String> tableOptions,
        Map<String, String> columnOptions)
        throws SQLException
    {
        final String methodName = "browse_column";
        final SqlBuilder selectSqlBuilder = createSqlBuilder();
        selectSqlBuilder
            .append("select * from table(sys_boot.mgmt.")
            .append(methodName)
            .append("(")
            .literal(serverName)
            .append(", ");
        toValues(selectSqlBuilder, tableOptions)
            .append(", ");
        toValues(selectSqlBuilder, columnOptions)
            .append(", ")
            .literal(locale.toString())
            .append("))");
        final String sql = selectSqlBuilder.getSql();
        return getProperties(methodName, sql);
    }
View Full Code Here

     */
    public List<ForeignSchemaInfo> browseForeignSchemas(String serverName)
        throws SQLException
    {
        final String methodName = "browse_foreign_schemas";
        final SqlBuilder selectSqlBuilder = createSqlBuilder();
        selectSqlBuilder
            .append("select * from table(sys_boot.mgmt.")
            .append(methodName)
            .append("(")
            .literal(serverName)
            .append("))");
        final String sql = selectSqlBuilder.getSql();
        Connection connection = dataSource.getConnection();
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery(sql);
        assert resultSet.getMetaData().getColumnCount() == 2;
        List<ForeignSchemaInfo> schemaInfo = new ArrayList<ForeignSchemaInfo>();
View Full Code Here

            String serverName,
            String schemaName)
        throws SQLException
    {
        final String methodName = "browse_foreign_schema_tables";
        final SqlBuilder selectSqlBuilder = createSqlBuilder();
        selectSqlBuilder
            .append("select * from table(sys_boot.mgmt.")
            .append(methodName)
            .append("(")
            .literal(serverName)
            .append(",")
            .literal(schemaName)
            .append("))");
        final String sql = selectSqlBuilder.getSql();
        Connection connection = dataSource.getConnection();
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery(sql);
        assert resultSet.getMetaData().getColumnCount() == 2;
        List<ForeignSchemaTableAndColumnInfo> tableInfo =
View Full Code Here

            String serverName,
            String schemaName)
        throws SQLException
    {
        final String methodName = "browse_foreign_schema_columns";
        final SqlBuilder selectSqlBuilder = createSqlBuilder();
        selectSqlBuilder
            .append("select * from table(sys_boot.mgmt.")
            .append(methodName)
            .append("(")
            .literal(serverName)
            .append(",")
            .literal(schemaName)
            .append("))");
        final String sql = selectSqlBuilder.getSql();
        Connection connection = dataSource.getConnection();
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery(sql);
        assert resultSet.getMetaData().getColumnCount() == 10;
        List<ForeignSchemaTableAndColumnInfo> colInfo =
View Full Code Here

        // Add CAST( VAR/CHAR/BINARY(0) to VAR/CHAR/BINARY(1) )
        List<FemViewColumn> columnList =
            Util.cast(view.getFeature(), FemViewColumn.class);
        boolean updateSql = false;
        if (columnList.size() > 0) {
            SqlBuilder buf = new SqlBuilder(SqlDialect.EIGENBASE, "SELECT");
            int k = 0;
            for (RelDataTypeField field : analyzedSql.resultType.getFields()) {
                String targetType = null;
                SqlTypeName sqlType = field.getType().getSqlTypeName();
                SqlTypeFamily typeFamily =
                    SqlTypeFamily.getFamilyForSqlType(sqlType);
                if ((typeFamily == SqlTypeFamily.CHARACTER)
                    || (typeFamily == SqlTypeFamily.BINARY))
                {
                    if (field.getType().getPrecision() == 0) {
                        // Can't have precision of 0
                        // Add cast so there is precision of 1
                        targetType = sqlType.name() + "(1)";
                        updateSql = true;
                    }
                }
                FemViewColumn viewColumn = columnList.get(k);
                if (k > 0) {
                    buf.append(", ");
                }
                if (targetType == null) {
                    buf.identifier(field.getName());
                } else {
                    buf.append(" CAST(");
                    buf.identifier(field.getName());
                    buf.append(" AS ");
                    buf.append(targetType);
                    buf.append(")");
                }
                buf.append(" AS ");
                buf.identifier(viewColumn.getName());
                k++;
            }
            buf.append(" FROM (").append(analyzedSql.canonicalString).append(
                ")");

            if (updateSql) {
                analyzedSql.canonicalString = buf.toSqlString();
            }
        }
    }
View Full Code Here

        int deploy)
        throws SQLException
    {
        url = url.trim();
        jar = jar.trim();
        SqlBuilder sql = new SqlBuilder(SqlDialect.EIGENBASE);
        sql.append("CREATE JAR ");
        // REVIEW: We can't use sql.identifier(jar), because
        // the jar argument to install_jar is already quoted
        // if needed.  But is there some sanitization we need
        // to do, or is no SQL injection attack possible?
        sql.append(jar);
        sql.append(" library ");
        sql.literal(url);
        sql.append(" options(");
        sql.append(deploy);
        sql.append(")");
        executeSql(sql.getSql());
    }
View Full Code Here

        int undeploy)
        throws SQLException
    {
        jar = jar.trim();

        SqlBuilder sql = new SqlBuilder(SqlDialect.EIGENBASE);
        sql.append("DROP JAR ");
        // REVIEW: see comments in install_jar regarding possible
        // sanitization needed
        sql.append(jar);
        sql.append(" options (");
        sql.append(undeploy);
        sql.append(") RESTRICT");
        executeSql(sql.getSql());
    }
View Full Code Here

TOP

Related Classes of org.eigenbase.sql.util.SqlBuilder

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.