Search in sources :

Example 6 with JaqyResultSet

use of com.teradata.jaqy.interfaces.JaqyResultSet in project jaqy by Teradata.

the class ImportSchemaCommand method execute.

@Override
public void execute(String[] args, boolean silent, JaqyInterpreter interpreter) throws Exception {
    JaqyImporter<?> importer = interpreter.getImporter();
    if (importer == null) {
        interpreter.error("There is no current import.");
    }
    SchemaInfo schemaInfo = importer.getSchema();
    if (schemaInfo == null) {
        interpreter.error("Current import schema is not available.");
    }
    boolean displaySQL = false;
    CommandLine cmdLine = getCommandLine(args);
    for (Option option : cmdLine.getOptions()) {
        switch(option.getOpt().charAt(0)) {
            case 's':
                {
                    displaySQL = true;
                    break;
                }
        }
    }
    SessionUtils.checkOpen(interpreter);
    Session session = interpreter.getSession();
    JaqyHelper helper = session.getConnection().getHelper();
    if (displaySQL) {
        String sql = SchemaUtils.getTableSchema(helper, schemaInfo, "TABLENAME", false);
        interpreter.println(sql);
    } else {
        JaqyResultSet rs = SchemaUtils.getSchemaResultSet(helper, schemaInfo, false, interpreter);
        interpreter.print(rs);
        rs.close();
    }
}
Also used : JaqyResultSet(com.teradata.jaqy.interfaces.JaqyResultSet) CommandLine(org.apache.commons.cli.CommandLine) JaqyHelper(com.teradata.jaqy.interfaces.JaqyHelper) Option(org.apache.commons.cli.Option) SchemaInfo(com.teradata.jaqy.schema.SchemaInfo) Session(com.teradata.jaqy.Session)

Example 7 with JaqyResultSet

use of com.teradata.jaqy.interfaces.JaqyResultSet in project jaqy by Teradata.

the class QueryUtils method getQueryString.

/**
 * Get the string result from a query.
 * @param	conn
 * 			The JDBC connection
 * @param	sql
 * 			The query string
 * @param	column
 * 			The column to retrieve data from
 * @param interpreter TODO
 *
 * @return	a string representation of the output for a particular column.
 * 			It can retrieve multiple rows of data if needed.
 * @throws	SQLException
 * 			in case of error.
 */
public static String getQueryString(JaqyConnection conn, String sql, int column, JaqyInterpreter interpreter) throws SQLException {
    JaqyStatement stmt = null;
    interpreter.getGlobals().log(Level.INFO, "SQL: " + sql);
    try {
        stmt = conn.createStatement(true);
        stmt.execute(sql);
        JaqyResultSet rs = stmt.getResultSet(interpreter);
        if (rs == null)
            return null;
        StringBuilder builder = new StringBuilder();
        while (rs.next()) {
            builder.append(rs.getString(column));
        }
        rs.close();
        return builder.toString();
    } finally {
        try {
            stmt.close();
        } catch (Exception ex) {
        }
    }
}
Also used : JaqyResultSet(com.teradata.jaqy.interfaces.JaqyResultSet) JaqyStatement(com.teradata.jaqy.connection.JaqyStatement) SQLException(java.sql.SQLException)

Example 8 with JaqyResultSet

use of com.teradata.jaqy.interfaces.JaqyResultSet in project jaqy by Teradata.

the class QueryUtils method getResultSet.

/**
 * Get the ResultSet from a query.
 *
 * @param	globals
 *			global variables
 * @param	conn
 * 			The JDBC connection
 * @param	sql
 * 			The query string
 * @param	interpreter
 * 			the interpreter
 * @return	an in-memory COPY of the query ResultSet.
 * @throws	SQLException
 * 			in case of error.
 */
public static JaqyResultSet getResultSet(Globals globals, JaqyConnection conn, String sql, JaqyInterpreter interpreter) throws SQLException {
    JaqyStatement stmt = null;
    globals.log(Level.INFO, "SQL: " + sql);
    try {
        stmt = conn.createStatement(true);
        stmt.execute(sql);
        JaqyResultSet rs = stmt.getResultSet(interpreter);
        if (rs == null)
            return null;
        JaqyResultSet newRS = ResultSetUtils.copyResultSet(rs, 0, interpreter);
        rs.close();
        return newRS;
    } finally {
        try {
            stmt.close();
        } catch (Exception ex) {
        }
    }
}
Also used : JaqyResultSet(com.teradata.jaqy.interfaces.JaqyResultSet) JaqyStatement(com.teradata.jaqy.connection.JaqyStatement) SQLException(java.sql.SQLException)

Example 9 with JaqyResultSet

use of com.teradata.jaqy.interfaces.JaqyResultSet in project jaqy by Teradata.

the class PipeImporterFactory method getHandler.

@Override
public PipeImporter getHandler(CommandLine cmdLine, JaqyInterpreter interpreter) throws Exception {
    JaqyExporter exporter = interpreter.getExporter();
    if (exporter == null)
        interpreter.error("No current pipe export.");
    else if (!(exporter instanceof PipeExporter))
        interpreter.error("Current export is not a pipe export.");
    JaqyResultSet rs = ((PipeExporter) exporter).getResultSet();
    if (rs == null)
        interpreter.error("Data has not been exported.");
    interpreter.setExporter(null);
    return new PipeImporter(rs, interpreter.getGlobals());
}
Also used : PipeExporter(com.teradata.jaqy.exporter.PipeExporter) JaqyResultSet(com.teradata.jaqy.interfaces.JaqyResultSet) JaqyExporter(com.teradata.jaqy.interfaces.JaqyExporter)

Aggregations

JaqyResultSet (com.teradata.jaqy.interfaces.JaqyResultSet)9 SQLException (java.sql.SQLException)3 JaqyStatement (com.teradata.jaqy.connection.JaqyStatement)2 JaqyHelper (com.teradata.jaqy.interfaces.JaqyHelper)2 CommandLine (org.apache.commons.cli.CommandLine)2 Option (org.apache.commons.cli.Option)2 PropertyTable (com.teradata.jaqy.PropertyTable)1 Session (com.teradata.jaqy.Session)1 JaqyParameterMetaData (com.teradata.jaqy.connection.JaqyParameterMetaData)1 JaqyResultSetMetaData (com.teradata.jaqy.connection.JaqyResultSetMetaData)1 PipeExporter (com.teradata.jaqy.exporter.PipeExporter)1 JaqyExporter (com.teradata.jaqy.interfaces.JaqyExporter)1 InMemoryResultSet (com.teradata.jaqy.resultset.InMemoryResultSet)1 SchemaInfo (com.teradata.jaqy.schema.SchemaInfo)1 TypeHandler (com.teradata.jaqy.typehandler.TypeHandler)1