From fa01fd982e09ff94de3b2ef619aa416f8dcb06b4 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Sat, 17 Aug 2019 18:00:17 -0400 Subject: [PATCH] Removed deprecated `Join`, `toSql`, `sanitizeExpression`, `isAscii`. --- angel_orm/CHANGELOG.md | 1 + angel_orm/lib/src/annotations.dart | 9 ------ angel_orm/lib/src/builder.dart | 31 ------------------ angel_orm/lib/src/util.dart | 51 ------------------------------ 4 files changed, 1 insertion(+), 91 deletions(-) diff --git a/angel_orm/CHANGELOG.md b/angel_orm/CHANGELOG.md index 36b1f852..1789dfa4 100644 --- a/angel_orm/CHANGELOG.md +++ b/angel_orm/CHANGELOG.md @@ -5,6 +5,7 @@ separate files. callbacks. * Make `JoinBuilder` take `to` as a `String Function()`. This will allow ORM queries to reference their joined subqueries. +* Removed deprecated `Join`, `toSql`, `sanitizeExpression`, `isAscii`. # 2.0.1 * Apply `package:pedantic` fixes. diff --git a/angel_orm/lib/src/annotations.dart b/angel_orm/lib/src/annotations.dart index 4bc7147a..1c06f020 100644 --- a/angel_orm/lib/src/annotations.dart +++ b/angel_orm/lib/src/annotations.dart @@ -27,14 +27,5 @@ class Orm { 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. enum JoinType { inner, left, right, full, self } diff --git a/angel_orm/lib/src/builder.dart b/angel_orm/lib/src/builder.dart index aaca4914..113f76f3 100644 --- a/angel_orm/lib/src/builder.dart +++ b/angel_orm/lib/src/builder.dart @@ -1,41 +1,10 @@ import 'dart:convert'; -import 'package:charcode/ascii.dart'; import 'package:intl/intl.dart' show DateFormat; -import 'package:string_scanner/string_scanner.dart'; import 'query.dart'; -import 'util.dart'; final DateFormat dateYmd = DateFormat('yyyy-MM-dd'); 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 { final Query query; final String columnName; diff --git a/angel_orm/lib/src/util.dart b/angel_orm/lib/src/util.dart index c6dee3ce..939b36c8 100644 --- a/angel_orm/lib/src/util.dart +++ b/angel_orm/lib/src/util.dart @@ -1,54 +1,3 @@ import 'package:charcode/ascii.dart'; -import 'builder.dart'; 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(); - } -}