OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <string> |
| 6 #include "base/logging.h" |
| 7 #include "base/stringprintf.h" |
| 8 #include "chrome/browser/extensions/api_actions.h" |
| 9 |
| 10 namespace extensions { |
| 11 |
| 12 // static |
| 13 bool Action::InitializeTableInternal(sql::Connection* db, |
| 14 const char* table_name, |
| 15 const char* basic_fields, |
| 16 const char* content_fields[], |
| 17 const int num_content_fields) { |
| 18 if (!db->DoesTableExist(table_name)) { |
| 19 std::string table_creator = base::StringPrintf( |
| 20 "CREATE TABLE %s (%s", table_name, basic_fields); |
| 21 for (int i = 0; i < num_content_fields; i++) { |
| 22 table_creator += base::StringPrintf(", %s LONGVARCHAR", |
| 23 content_fields[i]); |
| 24 } |
| 25 table_creator += ")"; |
| 26 if (!db->Execute(table_creator.c_str())) |
| 27 return false; |
| 28 } else { |
| 29 // In case we ever want to add new fields, this initializes them to be |
| 30 // empty strings. |
| 31 for (int i = 0; i < num_content_fields; i++) { |
| 32 if (!db->DoesColumnExist(table_name, content_fields[i])) { |
| 33 std::string table_updater = base::StringPrintf( |
| 34 "ALTER TABLE %s ADD COLUMN %s LONGVARCHAR; ", |
| 35 table_name, |
| 36 content_fields[i]); |
| 37 if (!db->Execute(table_updater.c_str())) |
| 38 return false; |
| 39 } |
| 40 } |
| 41 } |
| 42 return true; |
| 43 } |
| 44 |
| 45 } // namespace extensions |
| 46 |
OLD | NEW |