use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class OdbcRequestHandler method executeQuery.
/**
* {@link OdbcQueryExecuteRequest} command handler.
*
* @param req Execute query request.
* @return Response.
*/
private ClientListenerResponse executeQuery(OdbcQueryExecuteRequest req) {
int cursorCnt = qryResults.size();
if (maxCursors > 0 && cursorCnt >= maxCursors)
return new OdbcResponse(IgniteQueryErrorCode.UNKNOWN, "Too many open cursors (either close " + "other open cursors or increase the limit through " + "ClientConnectorConfiguration.maxOpenCursorsPerConnection) [maximum=" + maxCursors + ", current=" + cursorCnt + ']');
long qryId = QRY_ID_GEN.getAndIncrement();
assert !cliCtx.isStream();
try {
String sql = OdbcEscapeUtils.parse(req.sqlQuery());
if (log.isDebugEnabled())
log.debug("ODBC query parsed [reqId=" + req.requestId() + ", original=" + req.sqlQuery() + ", parsed=" + sql + ']');
SqlFieldsQuery qry = makeQuery(req.schema(), sql, req.arguments(), req.timeout(), req.autoCommit());
List<FieldsQueryCursor<List<?>>> cursors = ctx.query().querySqlFields(null, qry, cliCtx, true, false);
OdbcQueryResults results = new OdbcQueryResults(cursors, ver);
Collection<OdbcColumnMeta> fieldsMeta;
OdbcResultSet set = results.currentResultSet();
if (set == null)
fieldsMeta = new ArrayList<>();
else {
fieldsMeta = set.fieldsMeta();
if (log.isDebugEnabled()) {
for (OdbcColumnMeta meta : fieldsMeta) log.debug("Meta - " + meta.toString());
}
}
if (!results.hasUnfetchedRows())
results.closeAll();
else
qryResults.put(qryId, results);
OdbcQueryExecuteResult res = new OdbcQueryExecuteResult(qryId, fieldsMeta, results.rowsAffected());
return new OdbcResponse(res);
} catch (Exception e) {
qryResults.remove(qryId);
U.error(log, "Failed to execute SQL query [reqId=" + req.requestId() + ", req=" + req + ']', e);
return exceptionToResult(e);
}
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class CacheMvccAbstractTest method mergeSql.
/**
* Merge account by means of SQL API.
*
* @param cache Cache.
* @param key Key.
* @param val Value.
* @param updateCnt Update counter.
*/
protected static void mergeSql(TestCache<Integer, MvccTestAccount> cache, Integer key, Integer val, Integer updateCnt) {
SqlFieldsQuery qry = new SqlFieldsQuery("merge into MvccTestAccount(_key, val, updateCnt) values " + " (" + key + ", " + val + ", " + updateCnt + ")");
cache.cache.query(qry).getAll();
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class CacheMvccAbstractTest method insertSql.
/**
* Inserts account by means of SQL API.
*
* @param cache Cache.
* @param key Key.
* @param val Value.
* @param updateCnt Update counter.
*/
private static void insertSql(TestCache<Integer, MvccTestAccount> cache, int key, Integer val, Integer updateCnt) {
SqlFieldsQuery qry = new SqlFieldsQuery("insert into MvccTestAccount(_key, val, updateCnt) values " + " (" + key + ", " + val + ", " + updateCnt + ")");
cache.cache.query(qry).getAll();
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class CacheMvccAbstractTest method updateSql.
/**
* Updates account by means of SQL API.
*
* @param cache Cache.
* @param key Key.
* @param val Value.
* @param updateCnt Update counter.
*/
private static void updateSql(TestCache<Integer, MvccTestAccount> cache, Integer key, Integer val, Integer updateCnt) {
SqlFieldsQuery qry = new SqlFieldsQuery("update MvccTestAccount set val=" + val + ", updateCnt=" + updateCnt + " where _key=" + key);
cache.cache.query(qry).getAll();
}
use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.
the class CacheMvccAbstractTest method getAllSql.
/**
* Returns all accounts from cache by means of SQL.
*
* @param cache Cache.
* @return All accounts
*/
protected static Map<Integer, MvccTestAccount> getAllSql(TestCache<Integer, MvccTestAccount> cache) {
Map<Integer, MvccTestAccount> accounts = new HashMap<>();
SqlFieldsQuery qry = new SqlFieldsQuery("select _key, val, updateCnt from MvccTestAccount");
for (List<?> row : cache.cache.query(qry).getAll()) {
Integer id = (Integer) row.get(0);
Integer val = (Integer) row.get(1);
Integer updateCnt = (Integer) row.get(2);
MvccTestAccount old = accounts.put(id, new MvccTestAccount(val, updateCnt));
assertNull(old);
}
return accounts;
}
Aggregations