/** * Map the columns using the column names and the specified table. * * @param indexColumns the column list with column names set * @param table the table from where to map the column names to columns */ public static void mapColumns(IndexColumn[] indexColumns, Table table) { for (IndexColumn col : indexColumns) { col.column = table.getColumn(col.columnName); } }
private Column columnIfTableExists(Schema schema, String tableName, String columnName, boolean ifTableExists) { Table table = tableIfTableExists(schema, tableName, ifTableExists); return table == null ? null : table.getColumn(columnName); }
for (int i = 0; i < columnCount; i++) { Expression newExpr = expressionMap.get(columns[i]); Column column = table.getColumn(i); Value newValue; if (newExpr == null) { for (int i = 0; i < columnCount; i++) { if (expressionMap.get(columns[i]) == null) { Column column = table.getColumn(i); if (column.getOnUpdateExpression() != null) { newRow.setValue(i, table.getOnUpdateValue(session, column));
/** {@inheritDoc} */ @Override public Column getColumn(int index) { return innerTable().getColumn(index); }
/** {@inheritDoc} */ @Override public Column getColumn(String columnName) { return innerTable().getColumn(columnName); }
private Column parseColumn(Table table) { String id = readColumnIdentifier(); if (database.getSettings().rowId && Column.ROWID.equals(id)) { return table.getRowIdColumn(); } return table.getColumn(id); }
/** * @param tbl Table. * @param sortCols Sort columns. * @return Index columns. */ public static IndexColumn[] toIndexColumns(Table tbl, List<GridSqlSortColumn> sortCols) { assert !F.isEmpty(sortCols); IndexColumn[] res = new IndexColumn[sortCols.size()]; for (int i = 0; i < res.length; i++) { GridSqlSortColumn sc = sortCols.get(i); Column col = tbl.getColumn(sc.column()); IndexColumn c = new IndexColumn(); c.column = col; c.columnName = col.getName(); c.sortType = sc.asc ? SortOrder.ASCENDING : SortOrder.DESCENDING; if (sc.nullsFirst) c.sortType |= SortOrder.NULLS_FIRST; if (sc.nullsLast) c.sortType |= SortOrder.NULLS_LAST; res[i] = c; } return res; }
private void createIndex() { IndexColumn[] indexCols = null; // If we need to do distinct, the distinct columns may not match the // sort columns. So we need to disregard the sort. Not ideal. if (sort != null && !distinct) { int[] colIndex = sort.getQueryColumnIndexes(); indexCols = new IndexColumn[colIndex.length]; for (int i = 0; i < colIndex.length; i++) { IndexColumn indexColumn = new IndexColumn(); indexColumn.column = table.getColumn(colIndex[i]); indexColumn.sortType = sort.getSortTypes()[i]; indexColumn.columnName = COLUMN_NAME + i; indexCols[i] = indexColumn; } } else { indexCols = new IndexColumn[columnCount]; for (int i = 0; i < columnCount; i++) { IndexColumn indexColumn = new IndexColumn(); indexColumn.column = table.getColumn(i); indexColumn.columnName = COLUMN_NAME + i; indexCols[i] = indexColumn; } } String indexName = table.getSchema().getUniqueIndexName(session, table, Constants.PREFIX_INDEX); int indexId = session.getDatabase().allocateObjectId(); IndexType indexType = IndexType.createNonUnique(true); index = table.addIndex(session, indexName, indexId, indexCols, indexType, true, null); }
buff.appendOnlyFirst(" WHERE "); buff.appendExceptFirst(" AND "); Column col = table.getColumn(i); buff.append(col.getSQL()); if (v == ValueNull.INSTANCE) { buff.appendOnlyFirst(" WHERE "); buff.appendExceptFirst(" AND "); Column col = table.getColumn(i); buff.append(col.getSQL()); if (v == ValueNull.INSTANCE) {
@Override public void remove(Session session, Row row) { ArrayList<Value> params = New.arrayList(); StatementBuilder buff = new StatementBuilder("DELETE FROM "); buff.append(targetTableName).append(" WHERE "); for (int i = 0; i < row.getColumnCount(); i++) { buff.appendExceptFirst("AND "); Column col = table.getColumn(i); buff.append(col.getSQL()); Value v = row.getValue(i); if (isNull(v)) { buff.append(" IS NULL "); } else { buff.append('='); addParameter(buff, col); params.add(v); buff.append(' '); } } String sql = buff.toString(); try { PreparedStatement prep = link.execute(sql, params, false); int count = prep.executeUpdate(); link.reusePreparedStatement(prep, sql); rowCount -= count; } catch (Exception e) { throw TableLink.wrapException(sql, e); } }
for (int i = 0; i < newRow.getColumnCount(); i++) { buff.appendExceptFirst(", "); buff.append(table.getColumn(i).getSQL()).append('='); Value v = newRow.getValue(i); if (v == null) { buff.resetCount(); for (int i = 0; i < oldRow.getColumnCount(); i++) { Column col = table.getColumn(i); buff.appendExceptFirst(" AND "); buff.append(col.getSQL());
return filter.getTable().getColumn(columnName);
@Override public int update() { session.commit(true); Database db = session.getDatabase(); Table table = getSchema().findTableOrView(session, tableName); if (table == null) { if (ifTableExists) { return 0; } throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, tableName); } Column column = table.getColumn(oldName); session.getUser().checkRight(table, Right.ALL); table.checkSupportAlter(); // we need to update CHECK constraint // since it might reference the name of the column Expression newCheckExpr = column.getCheckConstraint(session, newName); table.renameColumn(column, newName); column.removeCheckConstraint(); column.addCheckConstraint(session, newCheckExpr); table.setModified(); db.updateMeta(session, table); for (DbObject child : table.getChildren()) { if (child.getCreateSQL() != null) { db.updateMeta(session, child); } } return 0; }
if (o != newListBackup[i]) { Value v = DataType.convertToValue(session, o, Value.UNKNOWN); session.getGeneratedKeys().add(table.getColumn(i)); newRow.setValue(i, v);
if (column) { Table table = (Table) object; table.getColumn(columnName).setComment(text); } else { object.setComment(text);
public Column[] getColumns(String[] columnNames) throws SQLException { Column[] cols = new Column[columnNames.length]; for (int i = 0; i < cols.length; i++) { cols[i] = getColumn(columnNames[i]); } return cols; }
if (table != null) { if (!ifExists || table.doesColumnExist(columnName)) { Column column = table.getColumn(columnName); columnsToRemove.add(column);