Removed deprecated Join, toSql, sanitizeExpression, isAscii.

This commit is contained in:
Tobe O 2019-08-17 18:00:17 -04:00
parent 1fa9612c8a
commit fa01fd982e
4 changed files with 1 additions and 91 deletions

View file

@ -5,6 +5,7 @@ separate files.
callbacks. callbacks.
* Make `JoinBuilder` take `to` as a `String Function()`. This will allow * Make `JoinBuilder` take `to` as a `String Function()`. This will allow
ORM queries to reference their joined subqueries. ORM queries to reference their joined subqueries.
* Removed deprecated `Join`, `toSql`, `sanitizeExpression`, `isAscii`.
# 2.0.1 # 2.0.1
* Apply `package:pedantic` fixes. * Apply `package:pedantic` fixes.

View file

@ -27,14 +27,5 @@ class Orm {
const Orm({this.tableName, this.generateMigrations = true}); const Orm({this.tableName, this.generateMigrations = true});
} }
@deprecated
class Join {
final Type against;
final String foreignKey;
final JoinType type;
const Join(this.against, this.foreignKey, {this.type = JoinType.inner});
}
/// The various types of join. /// The various types of join.
enum JoinType { inner, left, right, full, self } enum JoinType { inner, left, right, full, self }

View file

@ -1,41 +1,10 @@
import 'dart:convert'; import 'dart:convert';
import 'package:charcode/ascii.dart';
import 'package:intl/intl.dart' show DateFormat; import 'package:intl/intl.dart' show DateFormat;
import 'package:string_scanner/string_scanner.dart';
import 'query.dart'; import 'query.dart';
import 'util.dart';
final DateFormat dateYmd = DateFormat('yyyy-MM-dd'); final DateFormat dateYmd = DateFormat('yyyy-MM-dd');
final DateFormat dateYmdHms = DateFormat('yyyy-MM-dd HH:mm:ss'); final DateFormat dateYmdHms = DateFormat('yyyy-MM-dd HH:mm:ss');
/// The ORM prefers using substitution values, which allow for prepared queries,
/// and prevent SQL injection attacks.
@deprecated
String sanitizeExpression(String unsafe) {
var buf = StringBuffer();
var scanner = StringScanner(unsafe);
int ch;
while (!scanner.isDone) {
// Ignore comment starts
if (scanner.scan('--') || scanner.scan('/*')) {
continue;
}
// Ignore all single quotes and attempted escape sequences
else if (scanner.scan("'") || scanner.scan('\\')) {
continue;
}
// Otherwise, add the next char, unless it's a null byte.
else if ((ch = scanner.readChar()) != $nul && ch != null) {
buf.writeCharCode(ch);
}
}
return toSql(buf.toString(), withQuotes: false);
}
abstract class SqlExpressionBuilder<T> { abstract class SqlExpressionBuilder<T> {
final Query query; final Query query;
final String columnName; final String columnName;

View file

@ -1,54 +1,3 @@
import 'package:charcode/ascii.dart'; import 'package:charcode/ascii.dart';
import 'builder.dart';
bool isAscii(int ch) => ch >= $nul && ch <= $del; bool isAscii(int ch) => ch >= $nul && ch <= $del;
/// The ORM prefers using substitution values, which allow for prepared queries,
/// and prevent SQL injection attacks.
@deprecated
String toSql(Object obj, {bool withQuotes = true}) {
if (obj is DateTime) {
return withQuotes ? "'${dateYmdHms.format(obj)}'" : dateYmdHms.format(obj);
} else if (obj is bool) {
return obj ? 'TRUE' : 'FALSE';
} else if (obj == null) {
return 'NULL';
} else if (obj is String) {
var b = StringBuffer();
var escaped = false;
var it = obj.runes.iterator;
while (it.moveNext()) {
if (it.current == $nul) {
continue; // Skip null byte
} else if (it.current == $single_quote) {
escaped = true;
b.write('\\x');
b.write(it.current.toRadixString(16).padLeft(2, '0'));
} else if (isAscii(it.current)) {
b.writeCharCode(it.current);
} else if (it.currentSize == 1) {
escaped = true;
b.write('\\u');
b.write(it.current.toRadixString(16).padLeft(4, '0'));
} else if (it.currentSize == 2) {
escaped = true;
b.write('\\U');
b.write(it.current.toRadixString(16).padLeft(8, '0'));
} else {
throw UnsupportedError(
'toSql() cannot encode a rune of size (${it.currentSize})');
}
}
if (!withQuotes) {
return b.toString();
} else if (escaped) {
return "E'$b'";
} else {
return "'$b'";
}
} else {
return obj.toString();
}
}