OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 "chrome/browser/predictors/glowplug_key_value_table.h" |
| 6 |
| 7 #include "third_party/protobuf/src/google/protobuf/message_lite.h" |
| 8 |
| 9 namespace predictors { |
| 10 |
| 11 namespace internal { |
| 12 |
| 13 void BindDataToStatement(const std::string& key, |
| 14 const google::protobuf::MessageLite& data, |
| 15 sql::Statement* statement) { |
| 16 int size = data.ByteSize(); |
| 17 DCHECK_GT(size, 0); |
| 18 std::vector<char> proto_buffer(size); |
| 19 data.SerializeToArray(&proto_buffer[0], size); |
| 20 |
| 21 statement->BindString(0, key); |
| 22 statement->BindBlob(1, &proto_buffer[0], size); |
| 23 } |
| 24 |
| 25 std::string GetSelectAllSql(const std::string& table_name) { |
| 26 return base::StringPrintf("SELECT * FROM %s", table_name.c_str()); |
| 27 } |
| 28 std::string GetInsertSql(const std::string& table_name) { |
| 29 return base::StringPrintf("INSERT INTO %s (key, proto) VALUES (?,?)", |
| 30 table_name.c_str()); |
| 31 } |
| 32 std::string GetDeleteSql(const std::string& table_name) { |
| 33 return base::StringPrintf("DELETE FROM %s WHERE key=?", table_name.c_str()); |
| 34 } |
| 35 std::string GetDeleteAllSql(const std::string& table_name) { |
| 36 return base::StringPrintf("DELETE FROM %s", table_name.c_str()); |
| 37 } |
| 38 |
| 39 } // namespace internal |
| 40 } // namespace predictors |
OLD | NEW |