AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
SQLiteDatabase.h
Go to the documentation of this file.
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0/
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 #ifndef ALEXA_CLIENT_SDK_STORAGE_SQLITESTORAGE_INCLUDE_SQLITESTORAGE_SQLITEDATABASE_H_
17 #define ALEXA_CLIENT_SDK_STORAGE_SQLITESTORAGE_INCLUDE_SQLITESTORAGE_SQLITEDATABASE_H_
18 
19 #include <memory>
20 #include <string>
21 #include <vector>
22 
23 #include <sqlite3.h>
24 
26 
27 namespace alexaClientSDK {
28 namespace storage {
29 namespace sqliteStorage {
30 
37 public:
41  class Transaction {
43  friend SQLiteDatabase;
44 
45  public:
49  ~Transaction();
50 
56  bool commit();
57 
63  bool rollback();
64 
65  private:
71  Transaction(std::weak_ptr<SQLiteDatabase> dbHandle);
72 
76  std::weak_ptr<SQLiteDatabase> m_database;
77 
81  bool m_transactionCompleted;
82  };
83 
90  SQLiteDatabase(const std::string& filePath);
91 
99 
107  bool initialize();
108 
116  bool open();
117 
124  bool performQuery(const std::string& sqlString);
125 
132  bool tableExists(const std::string& tableName);
133 
140  bool clearTable(const std::string& tableName);
141 
150  bool dropTable(const std::string& tableName);
151 
155  void close();
156 
163  std::unique_ptr<SQLiteStatement> createStatement(const std::string& sqlString);
164 
170  bool isDatabaseReady();
171 
177  std::unique_ptr<Transaction> beginTransaction();
178 
179 private:
185  bool commitTransaction();
186 
191  bool rollbackTransaction();
192 
194  const std::string m_storageFilePath;
195 
197  bool m_transactionIsInProgress;
198 
200  sqlite3* m_dbHandle;
201 
207  std::shared_ptr<SQLiteDatabase> m_sharedThisPlaceholder;
208 };
209 
210 } // namespace sqliteStorage
211 } // namespace storage
212 } // namespace alexaClientSDK
213 
214 #endif // ALEXA_CLIENT_SDK_STORAGE_SQLITESTORAGE_INCLUDE_SQLITESTORAGE_SQLITEDATABASE_H_
::std::string string
Definition: gtest-port.h:1097
std::unique_ptr< Transaction > beginTransaction()
static const std::string tableName
Definition: SmartScreenCaptionStateManagerTest.cpp:30
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
bool clearTable(const std::string &tableName)
bool dropTable(const std::string &tableName)
std::unique_ptr< SQLiteStatement > createStatement(const std::string &sqlString)
bool tableExists(const std::string &tableName)
bool performQuery(const std::string &sqlString)

AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0