Fix drift tests

This commit is contained in:
Simon Binder 2023-08-02 17:38:09 +02:00
parent bb7e808487
commit 7678971d36
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
7 changed files with 34 additions and 13 deletions

View File

@ -36,7 +36,7 @@ abstract class Column<T extends Object> extends Expression<T> {
/// The (unescaped) name of this column.
///
/// Use [escapedName] to access a name that's escaped in double quotes if
/// Use [escapedNameFor] to access a name that's escaped in double quotes if
/// needed.
String get name;
@ -45,8 +45,14 @@ abstract class Column<T extends Object> extends Expression<T> {
/// In the past, this getter only used to add double-quotes when that is
/// really needed (for instance because [name] is also a reserved keyword).
/// For performance reasons, we unconditionally escape names now.
String get escapedName =>
'`$name`'; // mariadb backtick escape DOT NOT MERGE STILL
@Deprecated('Use escapedNameFor with the current dialect')
String get escapedName => '"$name"';
/// [name], but wrapped in double quotes or the DBMS-specific escape
/// identifier.
String escapedNameFor(SqlDialect dialect) {
return dialect.escape(name);
}
}
/// A column that stores int values.

View File

@ -157,7 +157,7 @@ abstract class Expression<D extends Object> implements FunctionParameter {
/// For an "is in" comparison with values, use [isIn].
Expression<bool> isInExp(List<Expression<D>> expressions) {
if (expressions.isEmpty) {
return Constant(true);
return Constant(false);
}
return _InExpression(this, expressions, false);

View File

@ -251,7 +251,7 @@ class Migrator {
expressionsForSelect.add(expression);
if (!first) context.buffer.write(', ');
context.buffer.write(column.escapedName);
context.buffer.write(column.escapedNameFor(dialect));
first = false;
}
}
@ -348,7 +348,7 @@ class Migrator {
for (var i = 0; i < pkList.length; i++) {
final column = pkList[i];
context.buffer.write(column.escapedName);
context.buffer.write(column.escapedNameFor(context.dialect));
if (i != pkList.length - 1) context.buffer.write(', ');
}
@ -362,7 +362,7 @@ class Migrator {
for (var i = 0; i < uqList.length; i++) {
final column = uqList[i];
context.buffer.write(column.escapedName);
context.buffer.write(column.escapedNameFor(context.dialect));
if (i != uqList.length - 1) context.buffer.write(', ');
}
@ -418,7 +418,9 @@ class Migrator {
await _issueQueryByDialect(stmts);
} else if (view.query != null) {
final context = GenerationContext.fromDb(_db, supportsVariables: false);
final columnNames = view.$columns.map((e) => e.escapedName).join(', ');
final columnNames = view.$columns
.map((e) => e.escapedNameFor(context.dialect))
.join(', ');
context.generatingForView = view.entityName;
context.buffer.write('CREATE VIEW IF NOT EXISTS '
@ -495,7 +497,7 @@ class Migrator {
context.buffer
..write('ALTER TABLE ${context.identifier(table.aliasedName)} ')
..write('RENAME COLUMN ${context.identifier(oldName)} ')
..write('TO ${column.escapedName};');
..write('TO ${column.escapedNameFor(context.dialect)};');
return _issueCustomQuery(context.sql);
}

View File

@ -134,10 +134,21 @@ enum SqlDialect {
supportsIndexedParameters: false,
);
/// The type to use in `CAST`s and column definitions to store booleans.
final String booleanType;
/// The type to use in `CAST`s and column definitions to store strings.
final String textType;
/// The type to use in `CAST`s and column definitions to store 64-bit
/// integers.
final String integerType;
/// The type to use in `CAST`s and column definitions to store doubles.
final String realType;
/// The type to use in `CAST`s and column definitions to store blobs (as
/// a [Uint8List] in Dart).
final String blobType;
/// The character used to wrap identifiers to distinguish them from keywords.

View File

@ -115,6 +115,7 @@ class GeneratedColumn<T extends Object> extends Column<T> {
/// buffer.
void writeColumnDefinition(GenerationContext into) {
final isSerial = into.dialect == SqlDialect.postgres && hasAutoIncrement;
final escapedName = escapedNameFor(into.dialect);
if (isSerial) {
into.buffer.write('$escapedName bigserial PRIMARY KEY NOT NULL');
@ -177,7 +178,8 @@ class GeneratedColumn<T extends Object> extends Column<T> {
..write(context.identifier(tableName))
..write('.');
}
context.buffer.write(ignoreEscape ? $name : escapedName);
context.buffer
.write(ignoreEscape ? $name : escapedNameFor(context.dialect));
}
}

View File

@ -291,7 +291,7 @@ class InsertStatement<T extends Table, D> {
// Writing the escaped name directly because it should not have a table
// name in front of it.
ctx.buffer.write(target.escapedName);
ctx.buffer.write(target.escapedNameFor(ctx.dialect));
first = false;
}

View File

@ -73,8 +73,8 @@ void main() {
// it and replace it with the direct constant (since nothing can be a
// member of the empty set). sqlite3 seems to do the same thing, as
// `NULL IN ()` is `0` and not `NULL`.
expect(innerExpression.isIn([]), generates('FALSE'));
expect(innerExpression.isNotIn([]), generates('TRUE'));
expect(innerExpression.isIn([]), generates('0'));
expect(innerExpression.isNotIn([]), generates('1'));
});
});
}