OLD | NEW |
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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 | 328 |
329 // Returns the errno associated with GetErrorCode(). See | 329 // Returns the errno associated with GetErrorCode(). See |
330 // SQLITE_LAST_ERRNO in SQLite documentation. | 330 // SQLITE_LAST_ERRNO in SQLite documentation. |
331 int GetLastErrno() const; | 331 int GetLastErrno() const; |
332 | 332 |
333 // Returns a pointer to a statically allocated string associated with the | 333 // Returns a pointer to a statically allocated string associated with the |
334 // last sqlite operation. | 334 // last sqlite operation. |
335 const char* GetErrorMessage() const; | 335 const char* GetErrorMessage() const; |
336 | 336 |
337 private: | 337 private: |
| 338 // Allow test-support code to set/reset error ignorer. |
| 339 friend class ScopedErrorIgnorer; |
| 340 |
338 // Statement accesses StatementRef which we don't want to expose to everybody | 341 // Statement accesses StatementRef which we don't want to expose to everybody |
339 // (they should go through Statement). | 342 // (they should go through Statement). |
340 friend class Statement; | 343 friend class Statement; |
341 | 344 |
342 // Internal initialize function used by both Init and InitInMemory. The file | 345 // Internal initialize function used by both Init and InitInMemory. The file |
343 // name is always 8 bits since we want to use the 8-bit version of | 346 // name is always 8 bits since we want to use the 8-bit version of |
344 // sqlite3_open. The string can also be sqlite's special ":memory:" string. | 347 // sqlite3_open. The string can also be sqlite's special ":memory:" string. |
345 bool OpenInternal(const std::string& file_name); | 348 bool OpenInternal(const std::string& file_name); |
346 | 349 |
347 // Internal close function used by Close() and RazeAndClose(). | 350 // Internal close function used by Close() and RazeAndClose(). |
348 // |forced| indicates that orderly-shutdown checks should not apply. | 351 // |forced| indicates that orderly-shutdown checks should not apply. |
349 void CloseInternal(bool forced); | 352 void CloseInternal(bool forced); |
350 | 353 |
351 // Check whether the current thread is allowed to make IO calls, but only | 354 // Check whether the current thread is allowed to make IO calls, but only |
352 // if database wasn't open in memory. Function is inlined to be a no-op in | 355 // if database wasn't open in memory. Function is inlined to be a no-op in |
353 // official build. | 356 // official build. |
354 void AssertIOAllowed() { | 357 void AssertIOAllowed() { |
355 if (!in_memory_) | 358 if (!in_memory_) |
356 base::ThreadRestrictions::AssertIOAllowed(); | 359 base::ThreadRestrictions::AssertIOAllowed(); |
357 } | 360 } |
358 | 361 |
359 // Internal helper for DoesTableExist and DoesIndexExist. | 362 // Internal helper for DoesTableExist and DoesIndexExist. |
360 bool DoesTableOrIndexExist(const char* name, const char* type) const; | 363 bool DoesTableOrIndexExist(const char* name, const char* type) const; |
361 | 364 |
| 365 // Accessors for global error-ignorer, for injecting behavior during tests. |
| 366 // See test/scoped_error_ignorer.h. |
| 367 typedef base::Callback<bool(int)> ErrorIgnorerCallback; |
| 368 static ErrorIgnorerCallback* current_ignorer_cb_; |
| 369 static bool ShouldIgnore(int error); |
| 370 static void SetErrorIgnorer(ErrorIgnorerCallback* ignorer); |
| 371 static void ResetErrorIgnorer(); |
| 372 |
362 // A StatementRef is a refcounted wrapper around a sqlite statement pointer. | 373 // A StatementRef is a refcounted wrapper around a sqlite statement pointer. |
363 // Refcounting allows us to give these statements out to sql::Statement | 374 // Refcounting allows us to give these statements out to sql::Statement |
364 // objects while also optionally maintaining a cache of compiled statements | 375 // objects while also optionally maintaining a cache of compiled statements |
365 // by just keeping a refptr to these objects. | 376 // by just keeping a refptr to these objects. |
366 // | 377 // |
367 // A statement ref can be valid, in which case it can be used, or invalid to | 378 // A statement ref can be valid, in which case it can be used, or invalid to |
368 // indicate that the statement hasn't been created yet, has an error, or has | 379 // indicate that the statement hasn't been created yet, has an error, or has |
369 // been destroyed. | 380 // been destroyed. |
370 // | 381 // |
371 // The Connection may revoke a StatementRef in some error cases, so callers | 382 // The Connection may revoke a StatementRef in some error cases, so callers |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 | 501 |
491 // Tag for auxiliary histograms. | 502 // Tag for auxiliary histograms. |
492 std::string histogram_tag_; | 503 std::string histogram_tag_; |
493 | 504 |
494 DISALLOW_COPY_AND_ASSIGN(Connection); | 505 DISALLOW_COPY_AND_ASSIGN(Connection); |
495 }; | 506 }; |
496 | 507 |
497 } // namespace sql | 508 } // namespace sql |
498 | 509 |
499 #endif // SQL_CONNECTION_H_ | 510 #endif // SQL_CONNECTION_H_ |
OLD | NEW |