From a6ca8b661eaa2b8f1980a293dcbde449199c21ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 4 Jul 2015 16:09:48 +0200 Subject: [PATCH] README.md --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 8eb2bc958..c6d42130f 100644 --- a/README.md +++ b/README.md @@ -325,6 +325,24 @@ try dbQueue.inDatabase { db in } ``` +Note that the `Database.selectStatement()` function is the **only** function of GRDB.swift that may throw an error when building a SELECT statement. All other fetching functions prefer dying in a loud and verbose crash when given an invalid SELECT statements. + +Compare: + +```swift +// fatal error: SQLite error 1 with statement `SELECT foo FROM bar`: +// no such table: bar +db.fetchAllRows("SELECT foo FROM bar") + +do { + let statement = try db.selectStatement("SELECT foo FROM bar") +} catch let error as SQLiteError { + error.code // 1: the SQLite error code + error.message // "no such table: bar": the eventual SQLite message + error.sql // "SELECT foo FROM bar": the eventual erroneous SQL query +} +``` + ## Migrations