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 #include "sql/connection.h" | 5 #include "sql/connection.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "sql/statement.h" | 14 #include "sql/statement.h" |
15 #include "third_party/sqlite/sqlite3.h" | 15 #include "third_party/sqlite/sqlite3.h" |
16 | 16 |
Scott Hess - ex-Googler
2012/10/02 03:58:47
Egregious whitespace change is egregious.
| |
17 | |
17 namespace { | 18 namespace { |
18 | 19 |
19 // Spin for up to a second waiting for the lock to clear when setting | 20 // Spin for up to a second waiting for the lock to clear when setting |
20 // up the database. | 21 // up the database. |
21 // TODO(shess): Better story on this. http://crbug.com/56559 | 22 // TODO(shess): Better story on this. http://crbug.com/56559 |
22 const int kBusyTimeoutSeconds = 1; | 23 const int kBusyTimeoutSeconds = 1; |
23 | 24 |
24 class ScopedBusyTimeout { | 25 class ScopedBusyTimeout { |
25 public: | 26 public: |
26 explicit ScopedBusyTimeout(sqlite3* db) | 27 explicit ScopedBusyTimeout(sqlite3* db) |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
448 sql.append(")"); | 449 sql.append(")"); |
449 | 450 |
450 Statement statement(GetUntrackedStatement(sql.c_str())); | 451 Statement statement(GetUntrackedStatement(sql.c_str())); |
451 while (statement.Step()) { | 452 while (statement.Step()) { |
452 if (!statement.ColumnString(1).compare(column_name)) | 453 if (!statement.ColumnString(1).compare(column_name)) |
453 return true; | 454 return true; |
454 } | 455 } |
455 return false; | 456 return false; |
456 } | 457 } |
457 | 458 |
459 const std::string Connection::GetColumnType(const char* table_name, | |
460 int column_index) const { | |
461 std::string sql("PRAGMA TABLE_INFO ("); | |
462 sql.append(table_name); | |
463 sql.append(")"); | |
464 | |
465 Statement statement(GetUntrackedStatement(sql.c_str())); | |
466 for(int i = 0; i <= column_index; i++) | |
467 statement.Step(); | |
468 | |
469 return statement.ColumnString(2); | |
470 } | |
471 | |
458 int64 Connection::GetLastInsertRowId() const { | 472 int64 Connection::GetLastInsertRowId() const { |
459 if (!db_) { | 473 if (!db_) { |
460 DLOG(FATAL) << "Illegal use of connection without a db"; | 474 DLOG(FATAL) << "Illegal use of connection without a db"; |
461 return 0; | 475 return 0; |
462 } | 476 } |
463 return sqlite3_last_insert_rowid(db_); | 477 return sqlite3_last_insert_rowid(db_); |
464 } | 478 } |
465 | 479 |
466 int Connection::GetLastChangeCount() const { | 480 int Connection::GetLastChangeCount() const { |
467 if (!db_) { | 481 if (!db_) { |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
605 | 619 |
606 int Connection::OnSqliteError(int err, sql::Statement *stmt) { | 620 int Connection::OnSqliteError(int err, sql::Statement *stmt) { |
607 if (error_delegate_.get()) | 621 if (error_delegate_.get()) |
608 return error_delegate_->OnError(err, this, stmt); | 622 return error_delegate_->OnError(err, this, stmt); |
609 // The default handling is to assert on debug and to ignore on release. | 623 // The default handling is to assert on debug and to ignore on release. |
610 DLOG(FATAL) << GetErrorMessage(); | 624 DLOG(FATAL) << GetErrorMessage(); |
611 return err; | 625 return err; |
612 } | 626 } |
613 | 627 |
614 } // namespace sql | 628 } // namespace sql |
OLD | NEW |