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

Side by Side Diff: sql/connection.cc

Issue 10989063: Changed DB to store node positions as Ordinals. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Implemented feedback changes. Created 8 years, 2 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
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 #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 "third_party/sqlite/sqlite3.h"
14 #include "sql/statement.h" 15 #include "sql/statement.h"
rlarocque 2012/10/01 21:45:55 This should be in alphabetical order.
vishwath 2012/10/02 01:06:33 Done.
15 #include "third_party/sqlite/sqlite3.h"
16 16
17 namespace { 17 namespace {
18 18
19 // Spin for up to a second waiting for the lock to clear when setting 19 // Spin for up to a second waiting for the lock to clear when setting
20 // up the database. 20 // up the database.
21 // TODO(shess): Better story on this. http://crbug.com/56559 21 // TODO(shess): Better story on this. http://crbug.com/56559
22 const int kBusyTimeoutSeconds = 1; 22 const int kBusyTimeoutSeconds = 1;
23 23
24 class ScopedBusyTimeout { 24 class ScopedBusyTimeout {
25 public: 25 public:
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 sql.append(")"); 448 sql.append(")");
449 449
450 Statement statement(GetUntrackedStatement(sql.c_str())); 450 Statement statement(GetUntrackedStatement(sql.c_str()));
451 while (statement.Step()) { 451 while (statement.Step()) {
452 if (!statement.ColumnString(1).compare(column_name)) 452 if (!statement.ColumnString(1).compare(column_name))
453 return true; 453 return true;
454 } 454 }
455 return false; 455 return false;
456 } 456 }
457 457
458 ColType Connection::GetColumnType(char* table_name,
459 int column_index) const {
460 std::string sql("PRAGMA TABLE INFO(");
461 sql.append(table_name);
462 sql.append(")");
463
464 Statement statement(GetUntrackedStatement(sql.c_str()));
465 for(int i = 0; i <= column_index; i++)
466 statement.Step();
467
468 std::string column_type = statement.ColumnString(2);
rlarocque 2012/10/01 21:45:55 When I suggested the PRAGMA TABLE INFO, it didn't
vishwath 2012/10/02 01:06:33 It turns out that the returned information is of a
rlarocque 2012/10/02 01:39:50 Not quite what I had in mind, but that looks OK.
469 if(column_type == "INTEGER")
470 return COLUMN_TYPE_INTEGER;
471 else if(column_type == "FLOAT")
472 return COLUMN_TYPE_FLOAT;
473 else if(column_type == "TEXT")
474 return COLUMN_TYPE_TEXT;
475 else if(column_type == "BLOB")
476 return COLUMN_TYPE_BLOB;
477
478 return COLUMN_TYPE_NULL;
479 }
480
458 int64 Connection::GetLastInsertRowId() const { 481 int64 Connection::GetLastInsertRowId() const {
459 if (!db_) { 482 if (!db_) {
460 DLOG(FATAL) << "Illegal use of connection without a db"; 483 DLOG(FATAL) << "Illegal use of connection without a db";
461 return 0; 484 return 0;
462 } 485 }
463 return sqlite3_last_insert_rowid(db_); 486 return sqlite3_last_insert_rowid(db_);
464 } 487 }
465 488
466 int Connection::GetLastChangeCount() const { 489 int Connection::GetLastChangeCount() const {
467 if (!db_) { 490 if (!db_) {
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 628
606 int Connection::OnSqliteError(int err, sql::Statement *stmt) { 629 int Connection::OnSqliteError(int err, sql::Statement *stmt) {
607 if (error_delegate_.get()) 630 if (error_delegate_.get())
608 return error_delegate_->OnError(err, this, stmt); 631 return error_delegate_->OnError(err, this, stmt);
609 // The default handling is to assert on debug and to ignore on release. 632 // The default handling is to assert on debug and to ignore on release.
610 DLOG(FATAL) << GetErrorMessage(); 633 DLOG(FATAL) << GetErrorMessage();
611 return err; 634 return err;
612 } 635 }
613 636
614 } // namespace sql 637 } // namespace sql
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698