From 868636f31348fb87992db5d98b45ae61ee77301f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Fri, 8 Jan 2016 13:48:33 +0100 Subject: [PATCH] Prefer SQLITE_MISUSE for statement argument validation errors --- GRDB/Core/Database.swift | 2 +- GRDB/Core/Statement.swift | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/GRDB/Core/Database.swift b/GRDB/Core/Database.swift index f0759b465..1c305b728 100644 --- a/GRDB/Core/Database.swift +++ b/GRDB/Core/Database.swift @@ -103,7 +103,7 @@ public final class Database { // It's not OK if there remains unused arguments: let validateRemainingArguments = { if !remainingValues.isEmpty { - throw DatabaseError(code: SQLITE_ERROR, message: "Statement arguments mismatch: got \(values.count) argument(s) instead of \(values.count - remainingValues.count).", sql: sql, arguments: nil) + throw DatabaseError(code: SQLITE_MISUSE, message: "Statement arguments mismatch: got \(values.count) argument(s) instead of \(values.count - remainingValues.count).", sql: sql, arguments: nil) } } return (consumeArguments, validateRemainingArguments) diff --git a/GRDB/Core/Statement.swift b/GRDB/Core/Statement.swift index 0298c9059..f81862c71 100644 --- a/GRDB/Core/Statement.swift +++ b/GRDB/Core/Statement.swift @@ -55,7 +55,7 @@ public class Statement { } guard consumedCharactersCount == sqlCodeUnits.count else { - throw DatabaseError(code: SQLITE_ERROR, message: "Invalid SQL string: multiple statements found. To execute multiple statements, use Database.execute() instead.", sql: sql, arguments: nil) + throw DatabaseError(code: SQLITE_MISUSE, message: "Invalid SQL string: multiple statements found. To execute multiple statements, use Database.execute() instead.", sql: sql, arguments: nil) } } @@ -189,7 +189,7 @@ public class Statement { assert(keyValueBindings.count >= sqliteArgumentCount) if keyValueBindings.count > sqliteArgumentCount { - throw DatabaseError(code: SQLITE_ERROR, message: "wrong number of statement arguments: \(keyValueBindings.count)", sql: sql, arguments: nil) + throw DatabaseError(code: SQLITE_MISUSE, message: "wrong number of statement arguments: \(keyValueBindings.count)", sql: sql, arguments: nil) } let missingKeys = keyValueBindings.filter { $0.1 == nil }.map { $0.0 } @@ -202,9 +202,9 @@ public class Statement { .sort { $0.0 < $1.0 } .map { $0.1 } } - throw DatabaseError(code: SQLITE_ERROR, message: "missing statement argument(s): \(caseInsensitiveSort(namedMissingKeys).joinWithSeparator(", "))", sql: sql, arguments: nil) + throw DatabaseError(code: SQLITE_MISUSE, message: "missing statement argument(s): \(caseInsensitiveSort(namedMissingKeys).joinWithSeparator(", "))", sql: sql, arguments: nil) } else { - throw DatabaseError(code: SQLITE_ERROR, message: "wrong number of statement arguments: \(sqliteArgumentCount - missingKeys.count)", sql: sql, arguments: nil) + throw DatabaseError(code: SQLITE_MISUSE, message: "wrong number of statement arguments: \(sqliteArgumentCount - missingKeys.count)", sql: sql, arguments: nil) } }