Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion typed_sql/lib/src/dialect/mysql_dialect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ final class _MysqlSqlDialect extends SqlDialect {
/// Example: 'my string' -> '`my string`'
///
/// Throws if [name] cannot be safely escaped.
String escape(String name) => '`$name`'; // TODO: escape `
String escape(String name) => '`${name.replaceAll('`', '``')}`';

abstract class SqlContext {
String addParameter(Object? value);
Expand Down
18 changes: 18 additions & 0 deletions typed_sql/test/dialect/mysql_escape_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'package:test/test.dart';
import 'package:typed_sql/src/dialect/mysql_dialect.dart';

void main() {
group('MySQL escape', () {
test('simple name', () {
expect(escape('my_table'), '`my_table`');
});

test('name with backtick', () {
expect(escape('my`table'), '`my``table`');
});

test('multiple backticks', () {
expect(escape('`a``b`'), '```a````b```');

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙈

});
});
}
Loading