mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-26 04:07:50 +00:00
Remove support for check constraint defined with a literal
That's because we can't support it until SQLLiteral is able to quote values
This commit is contained in:
1 parent
4ecef0ea11
commit
f15b2e12d6
1 file changed
+2
-39
@@ -416,22 +416,7 @@ public final class TableDefinition {
|
||||
///
|
||||
/// - parameter sql: An SQL snippet
|
||||
public func check(sql: String) {
|
||||
check(literal: SQLLiteral(sql: sql))
|
||||
}
|
||||
|
||||
/// Adds a CHECK constraint.
|
||||
///
|
||||
/// try db.create(table: "player") { t in
|
||||
/// t.column("personalPhone", .text)
|
||||
/// t.column("workPhone", .text)
|
||||
/// t.check(literal: SQLLiteral(sql: "personalPhone IS NOT NULL OR workPhone IS NOT NULL"))
|
||||
/// }
|
||||
///
|
||||
/// See https://www.sqlite.org/lang_createtable.html#ckconst
|
||||
///
|
||||
/// - parameter sqlLiteral: An SQLLiteral
|
||||
public func check(literal sqlLiteral: SQLLiteral) {
|
||||
var expression = SQLExpressionLiteral(literal: sqlLiteral)
|
||||
var expression = SQLExpressionLiteral(sql)
|
||||
expression.unsafeRaw = true // It's safe because this expression can't be composed with others
|
||||
checkConstraints.append(expression)
|
||||
}
|
||||
@@ -736,29 +721,7 @@ public final class ColumnDefinition {
|
||||
/// - returns: Self so that you can further refine the column definition.
|
||||
@discardableResult
|
||||
public func check(sql: String) -> Self {
|
||||
return check(literal: SQLLiteral(sql: sql))
|
||||
}
|
||||
|
||||
/// Adds a CHECK constraint on the column.
|
||||
///
|
||||
/// try db.create(table: "player") { t in
|
||||
/// t.column("name", .text).check(literal: SQLLiteral(sql: "LENGTH(name) > 0"))
|
||||
/// }
|
||||
///
|
||||
/// With Swift 5, you can safely embed raw values in your SQL queries,
|
||||
/// without any risk of syntax errors or SQL injection:
|
||||
///
|
||||
/// try db.create(table: "player") { t in
|
||||
/// t.column("name", .text).check(literal: "LENGTH(name) > \(minLength)")
|
||||
/// }
|
||||
///
|
||||
/// See https://www.sqlite.org/lang_createtable.html#ckconst
|
||||
///
|
||||
/// - parameter sqlLiteral: An SQLLiteral
|
||||
/// - returns: Self so that you can further refine the column definition.
|
||||
@discardableResult
|
||||
public func check(literal sqlLiteral: SQLLiteral) -> Self {
|
||||
var expression = SQLExpressionLiteral(literal: sqlLiteral)
|
||||
var expression = SQLExpressionLiteral(sql)
|
||||
expression.unsafeRaw = true // It's safe because this expression can't be composed with others
|
||||
checkConstraints.append(expression)
|
||||
return self
|
||||
|
||||
Reference in new issue
Block a user