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();
}
}
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) {
}
}
}
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) {
}
}
}
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());
}
Aggregations