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

Side by Side Diff: sql/connection.h

Issue 10736042: [sql] Refactor to remove use of const_cast<>. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Elaborate on GetUntrackedStatement() usage. Created 8 years, 5 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
« no previous file with comments | « no previous file | sql/connection.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 // A statement ref can be valid, in which case it can be used, or invalid to 332 // A statement ref can be valid, in which case it can be used, or invalid to
333 // indicate that the statement hasn't been created yet, has an error, or has 333 // indicate that the statement hasn't been created yet, has an error, or has
334 // been destroyed. 334 // been destroyed.
335 // 335 //
336 // The Connection may revoke a StatementRef in some error cases, so callers 336 // The Connection may revoke a StatementRef in some error cases, so callers
337 // should always check validity before using. 337 // should always check validity before using.
338 class SQL_EXPORT StatementRef : public base::RefCounted<StatementRef> { 338 class SQL_EXPORT StatementRef : public base::RefCounted<StatementRef> {
339 public: 339 public:
340 // Default constructor initializes to an invalid statement. 340 // Default constructor initializes to an invalid statement.
341 StatementRef(); 341 StatementRef();
342 explicit StatementRef(sqlite3_stmt* stmt);
342 StatementRef(Connection* connection, sqlite3_stmt* stmt); 343 StatementRef(Connection* connection, sqlite3_stmt* stmt);
343 344
344 // When true, the statement can be used. 345 // When true, the statement can be used.
345 bool is_valid() const { return !!stmt_; } 346 bool is_valid() const { return !!stmt_; }
346 347
347 // If we've not been linked to a connection, this will be NULL. Guaranteed 348 // If we've not been linked to a connection, this will be NULL. Guaranteed
348 // non-NULL when is_valid(). 349 // non-NULL when is_valid().
349 Connection* connection() const { return connection_; } 350 Connection* connection() const { return connection_; }
350 351
351 // Returns the sqlite statement if any. If the statement is not active, 352 // Returns the sqlite statement if any. If the statement is not active,
(...skipping 29 matching lines...) Expand all
381 void ClearCache(); 382 void ClearCache();
382 383
383 // Called by Statement objects when an sqlite function returns an error. 384 // Called by Statement objects when an sqlite function returns an error.
384 // The return value is the error code reflected back to client code. 385 // The return value is the error code reflected back to client code.
385 int OnSqliteError(int err, Statement* stmt); 386 int OnSqliteError(int err, Statement* stmt);
386 387
387 // Like |Execute()|, but retries if the database is locked. 388 // Like |Execute()|, but retries if the database is locked.
388 bool ExecuteWithTimeout(const char* sql, base::TimeDelta ms_timeout) 389 bool ExecuteWithTimeout(const char* sql, base::TimeDelta ms_timeout)
389 WARN_UNUSED_RESULT; 390 WARN_UNUSED_RESULT;
390 391
392 // Internal helper for const functions. Like GetUniqueStatement(),
393 // except the statement is not entered into open_statements_,
394 // allowing this function to be const. Open statements can block
395 // closing the database, so only use in cases where the last ref is
396 // released before close could be called (which should always be the
397 // case for const functions).
398 scoped_refptr<StatementRef> GetUntrackedStatement(const char* sql) const;
399
391 // The actual sqlite database. Will be NULL before Init has been called or if 400 // The actual sqlite database. Will be NULL before Init has been called or if
392 // Init resulted in an error. 401 // Init resulted in an error.
393 sqlite3* db_; 402 sqlite3* db_;
394 403
395 // Parameters we'll configure in sqlite before doing anything else. Zero means 404 // Parameters we'll configure in sqlite before doing anything else. Zero means
396 // use the default value. 405 // use the default value.
397 int page_size_; 406 int page_size_;
398 int cache_size_; 407 int cache_size_;
399 bool exclusive_locking_; 408 bool exclusive_locking_;
400 409
(...skipping 20 matching lines...) Expand all
421 // This object handles errors resulting from all forms of executing sqlite 430 // This object handles errors resulting from all forms of executing sqlite
422 // commands or statements. It can be null which means default handling. 431 // commands or statements. It can be null which means default handling.
423 scoped_refptr<ErrorDelegate> error_delegate_; 432 scoped_refptr<ErrorDelegate> error_delegate_;
424 433
425 DISALLOW_COPY_AND_ASSIGN(Connection); 434 DISALLOW_COPY_AND_ASSIGN(Connection);
426 }; 435 };
427 436
428 } // namespace sql 437 } // namespace sql
429 438
430 #endif // SQL_CONNECTION_H_ 439 #endif // SQL_CONNECTION_H_
OLDNEW
« no previous file with comments | « no previous file | sql/connection.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698