mirror of https://github.com/AMT-Cheif/drift.git
using backticks instead of double quotes to escape and adding bool check constraint for mariadb
DO NOT MERGE THIS since Column.escapedName is hardcoded for mariadb dialect!
This commit is contained in:
parent
3fe50ffc69
commit
d2c3532c3f
|
@ -393,6 +393,8 @@ String escapeIfNeeded(String s, [SqlDialect dialect = SqlDialect.sqlite]) {
|
||||||
isKeyword |= additionalMariaDBKeywords.contains(inUpperCase);
|
isKeyword |= additionalMariaDBKeywords.contains(inUpperCase);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isKeyword || _notInKeyword.hasMatch(s)) return '"$s"';
|
if (isKeyword || _notInKeyword.hasMatch(s)) {
|
||||||
|
return dialect == SqlDialect.mariadb ? '`$s`' : '"$s"';
|
||||||
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ abstract class Column<T extends Object> extends Expression<T> {
|
||||||
/// In the past, this getter only used to add double-quotes when that is
|
/// 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).
|
/// really needed (for instance because [name] is also a reserved keyword).
|
||||||
/// For performance reasons, we unconditionally escape names now.
|
/// For performance reasons, we unconditionally escape names now.
|
||||||
String get escapedName => '"$name"';
|
String get escapedName => '`$name`'; // mariadb backtick escape DOT NOT MERGE
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A column that stores int values.
|
/// A column that stores int values.
|
||||||
|
|
|
@ -87,6 +87,8 @@ class GenerationContext {
|
||||||
void writeWhitespace() => buffer.write(' ');
|
void writeWhitespace() => buffer.write(' ');
|
||||||
|
|
||||||
/// Turns [columnName] into a safe SQL identifier by wrapping it in double
|
/// Turns [columnName] into a safe SQL identifier by wrapping it in double
|
||||||
/// quotes.
|
/// quotes, or backticks depending on the dialect.
|
||||||
String identifier(String columnName) => '"$columnName"';
|
String identifier(String columnName) {
|
||||||
|
return dialect == SqlDialect.mariadb ? '`$columnName`' : '"$columnName"';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,10 +147,13 @@ extension NameWithAlias on ResultSetImplementation<dynamic, dynamic> {
|
||||||
/// can be used in select statements, as it returns something like "users u"
|
/// can be used in select statements, as it returns something like "users u"
|
||||||
/// for a table called users that has been aliased as "u".
|
/// for a table called users that has been aliased as "u".
|
||||||
String get tableWithAlias {
|
String get tableWithAlias {
|
||||||
|
var dialect = attachedDatabase.executor.dialect;
|
||||||
if (aliasedName == entityName) {
|
if (aliasedName == entityName) {
|
||||||
return '"$entityName"';
|
return dialect == SqlDialect.mariadb ? '`$entityName`' : '"$entityName"';
|
||||||
} else {
|
} else {
|
||||||
return '"$entityName" "$aliasedName"';
|
return dialect == SqlDialect.mariadb
|
||||||
|
? '`$entityName` `$aliasedName`'
|
||||||
|
: '"$entityName" "$aliasedName"';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,9 +73,11 @@ Map<SqlDialect, String> defaultConstraints(DriftColumn column) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (column.sqlType == DriftSqlType.bool) {
|
if (column.sqlType == DriftSqlType.bool) {
|
||||||
final name = '"${column.nameInSql}"';
|
final name = column.nameInSql;
|
||||||
dialectSpecificConstraints[SqlDialect.sqlite]!
|
dialectSpecificConstraints[SqlDialect.sqlite]!
|
||||||
.add('CHECK ($name IN (0, 1))');
|
.add('CHECK ("$name" IN (0, 1))');
|
||||||
|
dialectSpecificConstraints[SqlDialect.mariadb]!
|
||||||
|
.add('CHECK (`$name` IN (0, 1))');
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final constraints in dialectSpecificConstraints.values) {
|
for (final constraints in dialectSpecificConstraints.values) {
|
||||||
|
|
Loading…
Reference in New Issue