Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: sql/connection.h

Issue 16664005: [sql] Framework for allowing tests to handle errors. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Refactor along lines of comment #4. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | sql/connection.cc » ('j') | sql/connection.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef SQL_CONNECTION_H_ 5 #ifndef SQL_CONNECTION_H_
6 #define SQL_CONNECTION_H_ 6 #define SQL_CONNECTION_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 369
370 // Returns the errno associated with GetErrorCode(). See 370 // Returns the errno associated with GetErrorCode(). See
371 // SQLITE_LAST_ERRNO in SQLite documentation. 371 // SQLITE_LAST_ERRNO in SQLite documentation.
372 int GetLastErrno() const; 372 int GetLastErrno() const;
373 373
374 // Returns a pointer to a statically allocated string associated with the 374 // Returns a pointer to a statically allocated string associated with the
375 // last sqlite operation. 375 // last sqlite operation.
376 const char* GetErrorMessage() const; 376 const char* GetErrorMessage() const;
377 377
378 private: 378 private:
379 // Allow test-support code to set/reset error ignorer.
380 friend class ScopedErrorIgnorer;
381
379 // Statement accesses StatementRef which we don't want to expose to everybody 382 // Statement accesses StatementRef which we don't want to expose to everybody
380 // (they should go through Statement). 383 // (they should go through Statement).
381 friend class Statement; 384 friend class Statement;
382 385
383 // Internal initialize function used by both Init and InitInMemory. The file 386 // Internal initialize function used by both Init and InitInMemory. The file
384 // name is always 8 bits since we want to use the 8-bit version of 387 // name is always 8 bits since we want to use the 8-bit version of
385 // sqlite3_open. The string can also be sqlite's special ":memory:" string. 388 // sqlite3_open. The string can also be sqlite's special ":memory:" string.
386 bool OpenInternal(const std::string& file_name); 389 bool OpenInternal(const std::string& file_name);
387 390
388 // Internal close function used by Close() and RazeAndClose(). 391 // Internal close function used by Close() and RazeAndClose().
389 // |forced| indicates that orderly-shutdown checks should not apply. 392 // |forced| indicates that orderly-shutdown checks should not apply.
390 void CloseInternal(bool forced); 393 void CloseInternal(bool forced);
391 394
392 // Check whether the current thread is allowed to make IO calls, but only 395 // Check whether the current thread is allowed to make IO calls, but only
393 // if database wasn't open in memory. Function is inlined to be a no-op in 396 // if database wasn't open in memory. Function is inlined to be a no-op in
394 // official build. 397 // official build.
395 void AssertIOAllowed() { 398 void AssertIOAllowed() {
396 if (!in_memory_) 399 if (!in_memory_)
397 base::ThreadRestrictions::AssertIOAllowed(); 400 base::ThreadRestrictions::AssertIOAllowed();
398 } 401 }
399 402
400 // Internal helper for DoesTableExist and DoesIndexExist. 403 // Internal helper for DoesTableExist and DoesIndexExist.
401 bool DoesTableOrIndexExist(const char* name, const char* type) const; 404 bool DoesTableOrIndexExist(const char* name, const char* type) const;
402 405
406 // Accessors for global error-ignorer, for injecting behavior during tests.
407 // See test/scoped_error_ignorer.h.
408 typedef base::Callback<bool(int)> ErrorIgnorerCallback;
409 static ErrorIgnorerCallback current_ignorer_cb_;
410 static bool ShouldIgnore(int error);
411 static void SetErrorIgnorer(const ErrorIgnorerCallback& ignorer);
412 static void ResetErrorIgnorer();
413
403 // A StatementRef is a refcounted wrapper around a sqlite statement pointer. 414 // A StatementRef is a refcounted wrapper around a sqlite statement pointer.
404 // Refcounting allows us to give these statements out to sql::Statement 415 // Refcounting allows us to give these statements out to sql::Statement
405 // objects while also optionally maintaining a cache of compiled statements 416 // objects while also optionally maintaining a cache of compiled statements
406 // by just keeping a refptr to these objects. 417 // by just keeping a refptr to these objects.
407 // 418 //
408 // A statement ref can be valid, in which case it can be used, or invalid to 419 // A statement ref can be valid, in which case it can be used, or invalid to
409 // indicate that the statement hasn't been created yet, has an error, or has 420 // indicate that the statement hasn't been created yet, has an error, or has
410 // been destroyed. 421 // been destroyed.
411 // 422 //
412 // The Connection may revoke a StatementRef in some error cases, so callers 423 // The Connection may revoke a StatementRef in some error cases, so callers
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 546
536 // Tag for auxiliary histograms. 547 // Tag for auxiliary histograms.
537 std::string histogram_tag_; 548 std::string histogram_tag_;
538 549
539 DISALLOW_COPY_AND_ASSIGN(Connection); 550 DISALLOW_COPY_AND_ASSIGN(Connection);
540 }; 551 };
541 552
542 } // namespace sql 553 } // namespace sql
543 554
544 #endif // SQL_CONNECTION_H_ 555 #endif // SQL_CONNECTION_H_
OLDNEW
« no previous file with comments | « no previous file | sql/connection.cc » ('j') | sql/connection.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698