private String identifier(String s) { if (database.getMode().lowerCaseIdentifiers) { s = s == null ? null : StringUtils.toLowerEnglish(s); } return s; }
@Override public String getMode() { return database.getMode().getName(); }
private Column[] createColumns(String... names) { Column[] cols = new Column[names.length]; for (int i = 0; i < names.length; i++) { String nameType = names[i]; int idx = nameType.indexOf(' '); int dataType; String name; if (idx < 0) { dataType = database.getMode().lowerCaseIdentifiers ? Value.STRING_IGNORECASE : Value.STRING; name = nameType; } else { dataType = DataType.getTypeByName(nameType.substring(idx + 1), database.getMode()).type; name = nameType.substring(0, idx); } cols[i] = new Column(name, dataType); } return cols; }
private ArrayList<Table> getTablesByName(Session session, String tableName) { if (database.getMode().lowerCaseIdentifiers) { tableName = StringUtils.toUpperEnglish(tableName); } ArrayList<Table> tables = database.getTableOrViewByName(tableName); for (Table temp : session.getLocalTempTables()) { if (temp.getName().equals(tableName)) { tables.add(temp); } } return tables; }
@Override public Expression optimize(Session session) { if (session.getDatabase().getMode().treatEmptyStringsAsNull) { if (value instanceof ValueString) { value = ValueString.get(value.getString(), true); } } return this; }
/** * Check if this row may have duplicates with the same indexed values in the * current compatibility mode. Duplicates with {@code NULL} values are * allowed in some modes. * * @param searchRow * the row to check * @return {@code true} if specified row may have duplicates, * {@code false otherwise} */ protected boolean mayHaveNullDuplicates(SearchRow searchRow) { switch (database.getMode().uniqueIndexNullsHandling) { case ALLOW_DUPLICATES_WITH_ANY_NULL: for (int index : columnIds) { if (searchRow.getValue(index) == ValueNull.INSTANCE) { return true; } } return false; case ALLOW_DUPLICATES_WITH_ALL_NULLS: for (int index : columnIds) { if (searchRow.getValue(index) != ValueNull.INSTANCE) { return false; } } return true; default: return false; } }
private Schema findSchema(String schemaName) { if (schemaName == null) { return null; } Schema schema = database.findSchema(schemaName); if (schema == null) { if (equalsToken("SESSION", schemaName)) { // for local temporary tables schema = database.getSchema(session.getCurrentSchemaName()); } else if (database.getMode().sysDummy1 && "SYSIBM".equals(schemaName)) { // IBM DB2 and Apache Derby compatibility: SYSIBM.SYSDUMMY1 schema = database.getSchema(session.getCurrentSchemaName()); } } return schema; }
private boolean checkIndex(Session session, String value, Value indexFrom, Value indexTo) { if (value == null || (indexFrom == null && indexTo == null)) { return true; } Database db = session.getDatabase(); Value v; if (database.getMode().lowerCaseIdentifiers) { v = ValueStringIgnoreCase.get(value); } else { v = ValueString.get(value); } if (indexFrom != null && db.compare(v, indexFrom) < 0) { return false; } if (indexTo != null && db.compare(v, indexTo) > 0) { return false; } return true; }
return l == ValueNull.INSTANCE ? l : l.negate(); case CONCAT: { Mode mode = session.getDatabase().getMode(); if (l == ValueNull.INSTANCE) { if (mode.nullConcatIsNull) {
/** * Get the system columns that this table understands. This is used for * compatibility with other databases. The columns are only returned if the * current mode supports system columns. * * @return the system columns */ @Override public Column[] getSystemColumns() { if (!session.getDatabase().getMode().systemColumns) { return null; } Column[] sys = new Column[3]; sys[0] = new Column("oid", Value.INT); sys[0].setTable(table, 0); sys[1] = new Column("ctid", Value.STRING); sys[1].setTable(table, 0); sys[2] = new Column("CTID", Value.STRING); sys[2].setTable(table, 0); return sys; }
private Insert parseInsert() { Insert command = new Insert(session); currentPrepared = command; if (database.getMode().onDuplicateKeyUpdate && readIf("IGNORE")) { command.setIgnore(true); return returnedCommand; if (database.getMode().onDuplicateKeyUpdate) { if (readIf("ON")) { read("DUPLICATE"); if (database.getMode().isolationLevelInSelectOrInsertStatement) { parseIsolationClause();
private Delete parseDelete() { Delete command = new Delete(session); Expression limit = null; if (readIf("TOP")) { limit = readTerm().optimize(session); } currentPrepared = command; int start = lastParseIndex; if (!readIf("FROM") && database.getMode().getEnum() == ModeEnum.MySQL) { readIdentifierWithSchema(); read("FROM"); } TableFilter filter = readSimpleTableFilter(0, null); command.setTableFilter(filter); parseDeleteGivenTable(command, limit, start); return command; }
private Row addRowImpl(Value[] values) { Row newRow = table.getTemplateRow(); setCurrentRowNumber(++rowNumber); for (int j = 0, len = columns.length; j < len; j++) { Column c = columns[j]; int index = c.getColumnId(); try { Value v = c.convert(values[j], session.getDatabase().getMode()); newRow.setValue(index, v); } catch (DbException ex) { throw setRow(ex, rowNumber, getSQL(values)); } } table.validateConvertUpdateSequence(session, newRow); boolean done = table.fireBeforeRow(session, null, newRow); if (!done) { table.addRow(session, newRow); session.log(table, UndoLogRecord.INSERT, newRow); table.fireAfterRow(session, null, newRow, false); return newRow; } return null; }
nullConstraint = NullConstraintType.NULL_IS_ALLOWED; if (database.getMode().getEnum() == ModeEnum.Oracle) { if (readIf("ENABLE")) {
String alias = readAliasIdentifier(); boolean aliasColumnName = database.getSettings().aliasColumnName; aliasColumnName |= database.getMode().aliasColumnName; expr = new Alias(expr, alias, aliasColumnName);
typeName); DataType builtIn = DataType.getTypeByName(typeName, session.getDatabase().getMode()); if (builtIn != null) { if (!builtIn.hidden) {
Value v = c.convert(e.getValue(session), session.getDatabase().getMode()); newRow.setValue(index, v); if (e instanceof SequenceValue) {
right = ValueExpression.get(r.convertTo(resType, MathUtils.convertLongToInt(left.getPrecision()), session.getDatabase().getMode(), column, column.getEnumerators()));
if (database.getMode().swapConvertFunctionParameters) { buff.append(new Column(null, dataType, precision, scale, displaySize).getCreateSQL()).
boolean allowAffinityKey = database.getMode().allowAffinityKey; boolean affinity = allowAffinityKey && readIfAffinity(); if (readIf("PRIMARY")) {