use of com.teradata.jaqy.connection.JaqyStatement in project jaqy by Teradata.
the class ResultSetUtils method copyResultSet.
public static JaqyResultSet copyResultSet(JaqyResultSet rs, long limit, JaqyInterpreter interpreter) throws SQLException {
InMemoryResultSetMetaData rsmd = ResultSetMetaDataUtils.copyResultSetMetaData(rs.getMetaData().getMetaData(), rs.getHelper());
ArrayList<Object[]> rows = new ArrayList<Object[]>();
JaqyStatement stmt = rs.getStatement();
int columnCount = rsmd.getColumnCount();
if (limit == 0)
limit = Long.MAX_VALUE;
boolean hasLob = false;
while (rs.next() && limit > 0) {
Object[] row = new Object[columnCount];
for (int i = 0; i < columnCount; ++i) {
Object o = rs.getObject(i + 1);
row[i] = ResultSetUtils.copyIfNecessary(o, interpreter);
if (row[i] instanceof CachedClob || row[i] instanceof CachedBlob || row[i] instanceof CachedSQLXML)
hasLob = true;
}
rows.add(row);
--limit;
}
InMemoryResultSet newRS = new InMemoryResultSet(rows, rsmd, stmt == null ? null : stmt.getStatement());
newRS.setHasLob(hasLob);
JaqyDefaultResultSet jqrs = new JaqyDefaultResultSet(newRS, DummyHelper.getInstance());
jqrs.setStatement(stmt);
return jqrs;
}
use of com.teradata.jaqy.connection.JaqyStatement 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.connection.JaqyStatement 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) {
}
}
}
Aggregations