| OLD | NEW |
| 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 #include "chrome/browser/history/visitsegment_database.h" | 5 #include "chrome/browser/history/visitsegment_database.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 } | 53 } |
| 54 | 54 |
| 55 if (!GetDB().Execute("CREATE INDEX segments_name ON segments(name)")) { | 55 if (!GetDB().Execute("CREATE INDEX segments_name ON segments(name)")) { |
| 56 NOTREACHED(); | 56 NOTREACHED(); |
| 57 return false; | 57 return false; |
| 58 } | 58 } |
| 59 } | 59 } |
| 60 | 60 |
| 61 // This was added later, so we need to try to create it even if the table | 61 // This was added later, so we need to try to create it even if the table |
| 62 // already exists. | 62 // already exists. |
| 63 GetDB().Execute("CREATE INDEX segments_url_id ON segments(url_id)"); | 63 if (!GetDB().Execute("CREATE INDEX IF NOT EXISTS segments_url_id ON " |
| 64 "segments(url_id)")) |
| 65 return false; |
| 64 | 66 |
| 65 // Segment usage table. | 67 // Segment usage table. |
| 66 if (!GetDB().DoesTableExist("segment_usage")) { | 68 if (!GetDB().DoesTableExist("segment_usage")) { |
| 67 if (!GetDB().Execute("CREATE TABLE segment_usage (" | 69 if (!GetDB().Execute("CREATE TABLE segment_usage (" |
| 68 "id INTEGER PRIMARY KEY," | 70 "id INTEGER PRIMARY KEY," |
| 69 "segment_id INTEGER NOT NULL," | 71 "segment_id INTEGER NOT NULL," |
| 70 "time_slot INTEGER NOT NULL," | 72 "time_slot INTEGER NOT NULL," |
| 71 "visit_count INTEGER DEFAULT 0 NOT NULL)")) { | 73 "visit_count INTEGER DEFAULT 0 NOT NULL)")) { |
| 72 NOTREACHED(); | 74 NOTREACHED(); |
| 73 return false; | 75 return false; |
| 74 } | 76 } |
| 75 if (!GetDB().Execute( | 77 if (!GetDB().Execute( |
| 76 "CREATE INDEX segment_usage_time_slot_segment_id ON " | 78 "CREATE INDEX segment_usage_time_slot_segment_id ON " |
| 77 "segment_usage(time_slot, segment_id)")) { | 79 "segment_usage(time_slot, segment_id)")) { |
| 78 NOTREACHED(); | 80 NOTREACHED(); |
| 79 return false; | 81 return false; |
| 80 } | 82 } |
| 81 } | 83 } |
| 82 | 84 |
| 83 // Added in a later version, so we always need to try to creat this index. | 85 // Added in a later version, so we always need to try to creat this index. |
| 84 GetDB().Execute("CREATE INDEX segments_usage_seg_id " | 86 if (!GetDB().Execute("CREATE INDEX IF NOT EXISTS segments_usage_seg_id " |
| 85 "ON segment_usage(segment_id)"); | 87 "ON segment_usage(segment_id)")) |
| 88 return false; |
| 86 | 89 |
| 87 // Presentation index table. | 90 // Presentation index table. |
| 88 // | 91 // |
| 89 // Important note: | 92 // Important note: |
| 90 // Right now, this table is only used to store the presentation index. | 93 // Right now, this table is only used to store the presentation index. |
| 91 // If you need to add more columns, keep in mind that rows are currently | 94 // If you need to add more columns, keep in mind that rows are currently |
| 92 // deleted when the presentation index is changed to -1. | 95 // deleted when the presentation index is changed to -1. |
| 93 // See SetPagePresentationIndex() in this file | 96 // See SetPagePresentationIndex() in this file |
| 94 if (!GetDB().DoesTableExist("presentation")) { | 97 if (!GetDB().DoesTableExist("presentation")) { |
| 95 if (!GetDB().Execute("CREATE TABLE presentation(" | 98 if (!GetDB().Execute("CREATE TABLE presentation(" |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 NOTREACHED(); | 379 NOTREACHED(); |
| 377 r = false; | 380 r = false; |
| 378 } | 381 } |
| 379 delete_usage.Reset(); | 382 delete_usage.Reset(); |
| 380 delete_seg.Reset(); | 383 delete_seg.Reset(); |
| 381 } | 384 } |
| 382 return r; | 385 return r; |
| 383 } | 386 } |
| 384 | 387 |
| 385 } // namespace history | 388 } // namespace history |
| OLD | NEW |