use of com.axway.ats.action.dbaccess.model.DatabaseRow in project ats-framework by Axway.
the class DatabaseOperations method getDatabaseData.
/**
* Gets some data from a database table. </br>
* <em>Note</em> that client may need to inspect returned type of each value and
* optionally convert it to get value in specific format.
*
* @param sqlQuery the SQL SELECT query to run. Client is resposible for any
* possible escaping needed so this is not security-safe method
* @return the found database data
*/
@PublicAtsApi
public DatabaseRow[] getDatabaseData(String sqlQuery) {
List<DatabaseRow> dbRows = new ArrayList<DatabaseRow>();
try {
log.debug("Executing query: " + sqlQuery);
DbRecordValuesList[] rsList = dbProvider.select(sqlQuery);
if (rsList != null) {
for (DbRecordValuesList rs : rsList) {
Iterator<DbRecordValue> it = rs.iterator();
if (it.hasNext()) {
DatabaseRow dbRow = new DatabaseRow();
while (it.hasNext()) {
DbRecordValue dbRecordValue = it.next();
dbRow.addCell(new DatabaseCell(dbRecordValue.getDbColumn().getColumnName(), dbRecordValue.getValueAsString()));
}
dbRows.add(dbRow);
}
}
}
return dbRows.toArray(new DatabaseRow[dbRows.size()]);
} catch (DbException e) {
throw new DatabaseOperationsException("Error getting data from DB with query '" + sqlQuery + "'", e);
}
}
use of com.axway.ats.action.dbaccess.model.DatabaseRow in project ats-framework by Axway.
the class DatabaseOperations method getDatabaseDataAsStrings.
/**
* <p>
* Gets data from a database table. All values as returned as String representations as needed.<br>
* For example:
* <ul>
* <li>TIMESTAMPs are retuned as java.sql.Timestamp.toString() format
* (yyyy-MM-dd HH:mm:ss.SSS and millis instead of nanos as documented in JavaSE Doc)</li>
* <li>BLOBs bytes are represented in hex format. Beware not to select too big data cells.</li>
* </ul>
* </p>
* @param sqlQuery the SQL SELECT query to run. Client is resposible for any
* possible escaping needed so thread this as not security-safe method
* @return the found database data
*/
@PublicAtsApi
public DatabaseRow[] getDatabaseDataAsStrings(String sqlQuery) {
List<DatabaseRow> dbRows = new LinkedList<DatabaseRow>();
try {
log.debug("Executing query: " + sqlQuery);
DbRecordValuesList[] rsList = dbProvider.select(new DbQuery(sqlQuery), DbReturnModes.STRING);
if (rsList != null) {
for (DbRecordValuesList rs : rsList) {
Iterator<DbRecordValue> it = rs.iterator();
if (it.hasNext()) {
DatabaseRow dbRow = new DatabaseRow();
while (it.hasNext()) {
DbRecordValue dbRecordValue = it.next();
dbRow.addCell(new DatabaseCell(dbRecordValue.getDbColumn().getColumnName(), dbRecordValue.getValueAsString()));
}
dbRows.add(dbRow);
}
}
}
return dbRows.toArray(new DatabaseRow[dbRows.size()]);
} catch (DbException e) {
throw new DatabaseOperationsException("Error getting data from DB with query '" + sqlQuery + "'", e);
}
}
Aggregations