summaryrefslogtreecommitdiffstats
path: root/sql/connection.h
diff options
context:
space:
mode:
authorshess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-12 23:50:59 +0000
committershess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-12 23:50:59 +0000
commiteff1fa525ce9cf8965cf187c9e7aef8c2db39bf9 (patch)
tree11404979e9dfe31379468712d8b3acf5c552b345 /sql/connection.h
parentd2528e607d9f876b4db237ebf37a57dcd45a4dbf (diff)
downloadchromium_src-eff1fa525ce9cf8965cf187c9e7aef8c2db39bf9.zip
chromium_src-eff1fa525ce9cf8965cf187c9e7aef8c2db39bf9.tar.gz
chromium_src-eff1fa525ce9cf8965cf187c9e7aef8c2db39bf9.tar.bz2
Put debugging assertions into sql::Statement.
Pulls out the core of gbillock's http://codereview.chromium.org/8283002/ - Move NOTREACHED and similar checks into the sql:: implementation code. - Add malformed SQL checks to Connection::Execute. - Add SQL-checking convenience methods to Connection. The general idea is that the sql:: framework assumes valid statements, rather than having client code contain scattered ad-hoc (and thus inconsistent) checks. This version puts back Statement operator overloading and loosy-goosy Execute() calls to allow other code to be updated in small batches. R=gbillock@chromium.org,jhawkins@chromium.org,dhollowa@chromium.org BUG=none TEST=sql_unittests,unit_tests:*Table*.* Review URL: http://codereview.chromium.org/8899012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114118 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sql/connection.h')
-rw-r--r--sql/connection.h16
1 files changed, 13 insertions, 3 deletions
diff --git a/sql/connection.h b/sql/connection.h
index 2467ff8d..a2bfeef 100644
--- a/sql/connection.h
+++ b/sql/connection.h
@@ -204,8 +204,12 @@ class SQL_EXPORT Connection {
// Executes the given SQL string, returning true on success. This is
// normally used for simple, 1-off statements that don't take any bound
// parameters and don't return any data (e.g. CREATE TABLE).
+ // This will DCHECK if the |sql| contains errors.
bool Execute(const char* sql);
+ // Like Execute(), but returns the error code given by SQLite.
+ int ExecuteAndReturnErrorCode(const char* sql);
+
// Returns true if we have a statement with the given identifier already
// cached. This is normally not necessary to call, but can be useful if the
// caller has to dynamically build up SQL to avoid doing so if it's already
@@ -217,8 +221,10 @@ class SQL_EXPORT Connection {
// keeping commonly-used ones around for future use is important for
// performance.
//
- // The SQL may have an error, so the caller must check validity of the
- // statement before using it.
+ // If the |sql| has an error, an invalid, inert StatementRef is returned (and
+ // the code will crash in debug). The caller must deal with this eventuality,
+ // either by checking validity of the |sql| before calling, by correctly
+ // handling the return of an inert statement, or both.
//
// The StatementID and the SQL must always correspond to one-another. The
// ID is the lookup into the cache, so crazy things will happen if you use
@@ -236,6 +242,10 @@ class SQL_EXPORT Connection {
scoped_refptr<StatementRef> GetCachedStatement(const StatementID& id,
const char* sql);
+ // Used to check a |sql| statement for syntactic validity. If the statement is
+ // valid SQL, returns true.
+ bool IsSQLValid(const char* sql);
+
// Returns a non-cached statement for the given SQL. Use this for SQL that
// is only executed once or only rarely (there is overhead associated with
// keeping a statement cached).
@@ -274,7 +284,7 @@ class SQL_EXPORT Connection {
const char* GetErrorMessage() const;
private:
- // Statement access StatementRef which we don't want to expose to erverybody
+ // Statement accesses StatementRef which we don't want to expose to everybody
// (they should go through Statement).
friend class Statement;