use of com.servoy.j2db.persistence.QuerySet in project servoy-client by Servoy.
the class FoundSet method getSerializedQuery.
String getSerializedQuery() {
QuerySelect currentQuery = pksAndRecords.getQuerySelectForReading();
String serverName = DataSourceUtils.getDataSourceServerName(getDataSource());
ArrayList<TableFilter> tableFilterParams = fsm.getTableFilterParams(serverName, currentQuery);
try {
QuerySet qs = fsm.getDataServer().getSQLQuerySet(serverName, currentQuery, tableFilterParams, 0, -1, true, true);
return qs.getSelect().getSql();
} catch (RepositoryException | RemoteException e) {
// $NON-NLS-1$
Debug.error("Can't get a serialized state from " + currentQuery, e);
}
// $NON-NLS-1$
return "";
}
use of com.servoy.j2db.persistence.QuerySet in project servoy-client by Servoy.
the class JSDatabaseManager method js_getSQL.
/**
* Returns the internal SQL which defines the specified (related)foundset.
* Optionally, the foundset and table filter params can be excluded in the sql (includeFilters=false).
* Make sure to set the applicable filters when the sql is used in a loadRecords() call.
* When the founset is in find mode, the find conditions are included in the resulting query.
*
* @sample var sql = databaseManager.getSQL(foundset)
*
* @param foundsetOrQBSelect The JSFoundset or QBSelect to get the sql for.
* @param includeFilters include the foundset and table filters.
*
* @return String representing the sql of the JSFoundset.
*/
public String js_getSQL(Object foundsetOrQBSelect, boolean includeFilters) throws ServoyException {
checkAuthorized();
if (foundsetOrQBSelect instanceof IFoundSetInternal && ((IFoundSetInternal) foundsetOrQBSelect).getTable() != null) {
try {
QuerySet querySet = getQuerySet(((IFoundSetInternal) foundsetOrQBSelect).getCurrentStateQuery(true, false), includeFilters);
StringBuilder sql = new StringBuilder();
QueryString[] prepares = querySet.getPrepares();
for (int i = 0; prepares != null && i < prepares.length; i++) {
// TODO parameters from updates and cleanups
// sql.append(updates[i].getSql());
// sql.append("\n"); //$NON-NLS-1$
}
sql.append(querySet.getSelect().getSql());
QueryString[] cleanups = querySet.getCleanups();
for (int i = 0; cleanups != null && i < cleanups.length; i++) {
// TODO parameters from updates and cleanups
// sql.append("\n"); //$NON-NLS-1$
// sql.append(cleanups[i].getSql());
}
return sql.toString();
} catch (Exception e) {
Debug.error(e);
}
} else if (foundsetOrQBSelect instanceof QBSelect) {
try {
QuerySelect select = ((QBSelect) foundsetOrQBSelect).build();
if (select.getColumns() == null) {
// no columns, add pk
// note that QBSelect.build() already returns a clone
ITable table = application.getFoundSetManager().getTable(select.getTable().getDataSource());
Iterator<Column> pkIt = ((Table) table).getRowIdentColumns().iterator();
if (!pkIt.hasNext()) {
throw new RepositoryException(ServoyException.InternalCodes.PRIMARY_KEY_NOT_FOUND, new Object[] { table.getName() });
}
while (pkIt.hasNext()) {
Column c = pkIt.next();
select.addColumn(c.queryColumn(select.getTable()));
}
}
QuerySet querySet = getQuerySet(select, includeFilters);
return querySet.getSelect().getSql();
} catch (RemoteException e) {
Debug.error(e);
}
}
return null;
}
Aggregations