use of com.servoy.j2db.query.TablePlaceholderKey in project servoy-client by Servoy.
the class QBSelect method createOperand.
IQuerySelectValue createOperand(Object value, BaseColumnType columnType, int flags) {
if (value instanceof QBColumn) {
return ((QBColumn) value).getQuerySelectValue();
}
Object val = value;
if (value instanceof QBParameter) {
TablePlaceholderKey key = ((QBParameter) value).getPlaceholderKey();
Placeholder placeholder = null;
if (query != null) {
placeholder = query.getPlaceholder(key);
}
val = placeholder == null ? new Placeholder(key) : placeholder;
} else if (columnType == null) {
if (value instanceof Date && !(value instanceof Timestamp) && !(value instanceof Time)) {
// make sure a date is a timestamp
val = new Timestamp(((Date) value).getTime());
}
} else if (!(value instanceof IQuerySelectValue)) {
// convert the value (especially UUID) to the type of the column
val = getAsRightType(value, columnType, flags);
}
if (val instanceof IQuerySelectValue) {
return (IQuerySelectValue) val;
}
return new QueryColumnValue(val, null);
}
use of com.servoy.j2db.query.TablePlaceholderKey in project servoy-client by Servoy.
the class FoundSet method copyCurrentRecordFoundSet.
public // used for printing current record
IFoundSetInternal copyCurrentRecordFoundSet() throws // used for printing current record
ServoyException {
try {
FoundSet fs = (FoundSet) clone();
// no need for clone, just made one
QuerySelect fs_sqlSelect = fs.pksAndRecords.getQuerySelectForReading();
SQLSheet.SQLDescription select_desc = sheet.getSQLDescription(SQLSheet.SELECT);
if (select_desc != null) {
QuerySelect select = (QuerySelect) select_desc.getSQLQuery();
fs_sqlSelect.setCondition(SQLGenerator.CONDITION_SEARCH, select.getConditionClone(SQLGenerator.CONDITION_SEARCH));
// Leave CONDITION_RELATION and CONDITION_FILTER as is in fs (when it is a related fs)
fs_sqlSelect.clearJoins();
fs_sqlSelect.clearSorts();
// clear, 1 row needs no sort etc.
fs_sqlSelect.clearCondition(SQLGenerator.CONDITION_OMIT);
// make sure the references to the tables from the copies are correct
fs_sqlSelect.relinkTable(select.getTable(), fs_sqlSelect.getTable());
// reset the creation! because we just changed the sqlSelect
fs.creationSqlSelect = AbstractBaseQuery.deepClone(fs_sqlSelect);
fs.lastSortColumns = null;
if (fs.rowManager != null)
fs.rowManager.register(fs);
fs.aggregateCache = new HashMap<String, Object>(6);
fs.pksAndRecords.setPksAndQuery(new BufferedDataSet(), 0, fs_sqlSelect);
}
int selRow = getSelectedIndex();
if (selRow >= 0) {
IRecordInternal selRec = getRecord(selRow);
if (selRec != null) {
Row row = selRec.getRawData();
if (row != null && row.existInDB()) {
Object[] pk = row.getPK();
if (!fs_sqlSelect.setPlaceholderValue(new TablePlaceholderKey(fs_sqlSelect.getTable(), SQLGenerator.PLACEHOLDER_PRIMARY_KEY), pk)) {
Debug.error(new RuntimeException(// $NON-NLS-1$
"Could not set placeholder " + new TablePlaceholderKey(fs_sqlSelect.getTable(), SQLGenerator.PLACEHOLDER_PRIMARY_KEY) + " in query " + fs_sqlSelect + // $NON-NLS-1$ //$NON-NLS-2$
"-- continuing"));
}
fs.pksAndRecords.getPks().setRow(0, pk);
fs.setSelectedIndex(0);
} else {
fs.newRecord(row, 0, true, false);
}
}
}
return fs;
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
}
}
use of com.servoy.j2db.query.TablePlaceholderKey in project servoy-client by Servoy.
the class SQLGenerator method makeQueryColumns.
private static ArrayList<IQuerySelectValue> makeQueryColumns(Iterator<Column> it, QueryTable queryTable, QueryInsert insert) {
ArrayList<IQuerySelectValue> queryColumns = new ArrayList<IQuerySelectValue>();
List<QueryColumn> insertColumns = new ArrayList<QueryColumn>();
while (it.hasNext()) {
Column column = it.next();
ColumnInfo ci = column.getColumnInfo();
if (ci != null && ci.isExcluded()) {
continue;
}
QueryColumn queryColumn = column.queryColumn(queryTable);
if (isBlobColumn(column)) {
String alias = column.getDataProviderID().substring(0, Math.min(Column.MAX_SQL_OBJECT_NAME_LENGTH - (IDataServer.BLOB_MARKER_COLUMN_ALIAS.length() + 1), column.getDataProviderID().length())) + '_' + IDataServer.BLOB_MARKER_COLUMN_ALIAS;
// make sure the alias is unique (2 media columns starting with the same name may clash here)
char c = 'a';
for (int i = 0; i < queryColumns.size(); i++) {
IQuerySelectValue sv = queryColumns.get(i);
if (alias.equals(sv.getAlias())) {
// alias not unique, replace first char to make it unique
alias = (c++) + alias.substring(1);
// search again
i = 0;
}
}
queryColumns.add(new QueryColumnValue(Integer.valueOf(1), alias, true));
} else {
queryColumns.add(queryColumn);
}
if (insert != null && (ci == null || !ci.isDBManaged())) {
insertColumns.add(queryColumn);
}
}
if (insert != null) {
insert.setColumnValues(insertColumns.toArray(new QueryColumn[insertColumns.size()]), new Placeholder(new TablePlaceholderKey(queryTable, PLACEHOLDER_INSERT_KEY)));
}
return queryColumns;
}
use of com.servoy.j2db.query.TablePlaceholderKey in project servoy-client by Servoy.
the class SQLGenerator method createDynamicPKSetConditionForFoundset.
static SetCondition createDynamicPKSetConditionForFoundset(FoundSet foundSet, BaseQueryTable queryTable, IDataSet pks) {
Table table = (Table) foundSet.getTable();
List<Column> rowIdentColumns = table.getRowIdentColumns();
QueryColumn[] pkQueryColumns = new QueryColumn[rowIdentColumns.size()];
// getPrimaryKeys from table
for (int i = 0; i < rowIdentColumns.size(); i++) {
Column column = rowIdentColumns.get(i);
pkQueryColumns[i] = column.queryColumn(queryTable);
}
// Dynamic PK condition, the special placeholder will be updated when the foundset pk set changes
Placeholder placeHolder = new Placeholder(new TablePlaceholderKey(queryTable, SQLGenerator.PLACEHOLDER_FOUNDSET_PKS));
placeHolder.setValue(new DynamicPkValuesArray(rowIdentColumns, pks.clone()));
return new SetCondition(IBaseSQLCondition.EQUALS_OPERATOR, pkQueryColumns, placeHolder, true);
}
use of com.servoy.j2db.query.TablePlaceholderKey in project servoy-client by Servoy.
the class SQLGenerator method isDynamicPKSetCondition.
static boolean isDynamicPKSetCondition(ISQLCondition condition) {
if (condition instanceof SetCondition) {
Object values = ((SetCondition) condition).getValues();
if (!(values instanceof Placeholder)) {
return false;
}
IPlaceholderKey key = ((Placeholder) values).getKey();
if (!(key instanceof TablePlaceholderKey)) {
return false;
}
if (!SQLGenerator.PLACEHOLDER_FOUNDSET_PKS.equals(((TablePlaceholderKey) key).getName())) {
return false;
}
return true;
}
return false;
}
Aggregations