forked from google/bindiff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sqlite.h
108 lines (79 loc) · 3.06 KB
/
sqlite.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright 2011-2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// TODO(cblichmann): We may want to export directly to SQLite from BinExport in
// the future. In that case, move this file to BinExport.
#ifndef SQLITE_H_
#define SQLITE_H_
#include <cstdint>
#include <memory>
#include "third_party/absl/status/statusor.h"
#include "third_party/absl/strings/string_view.h"
#include "third_party/zynamics/binexport/util/types.h"
struct sqlite3;
struct sqlite3_stmt;
namespace security::bindiff {
class SqliteStatement;
class SqliteDatabase {
public:
SqliteDatabase(const SqliteDatabase&) = delete;
SqliteDatabase& operator=(const SqliteDatabase&) = delete;
SqliteDatabase(SqliteDatabase&& other);
SqliteDatabase& operator=(SqliteDatabase&& other);
~SqliteDatabase();
static absl::StatusOr<SqliteDatabase> Connect(absl::string_view filename);
void Disconnect();
absl::StatusOr<SqliteStatement> Statement(absl::string_view statement);
SqliteStatement StatementOrThrow(absl::string_view statement);
absl::Status Execute(absl::string_view statement);
absl::Status Begin();
absl::Status Commit();
absl::Status Rollback();
private:
friend class SqliteStatement;
SqliteDatabase() = default;
sqlite3* database_ = nullptr;
};
class SqliteStatement {
public:
SqliteStatement(const SqliteStatement&) = delete;
SqliteStatement& operator=(const SqliteStatement&) = delete;
SqliteStatement(SqliteStatement&&);
SqliteStatement& operator=(SqliteStatement&&);
~SqliteStatement();
static absl::StatusOr<SqliteStatement> Prepare(SqliteDatabase& database,
absl::string_view statement);
SqliteStatement& BindInt(int value);
SqliteStatement& BindInt64(int64_t value);
SqliteStatement& BindDouble(double value);
SqliteStatement& BindText(absl::string_view value);
SqliteStatement& BindNull();
SqliteStatement& Into(int* value, bool* is_null = nullptr);
SqliteStatement& Into(int64_t* value, bool* is_null = nullptr);
SqliteStatement& Into(Address* value, bool* is_null = nullptr);
SqliteStatement& Into(double* value, bool* is_null = nullptr);
SqliteStatement& Into(std::string* value, bool* is_null = nullptr);
absl::Status Execute();
SqliteStatement& ExecuteOrThrow();
SqliteStatement& Reset();
bool GotData() const;
private:
SqliteStatement() = default;
sqlite3* database_ = nullptr;
sqlite3_stmt* statement_ = nullptr;
int parameter_ = 0;
int column_ = 0;
bool got_data_ = false;
};
} // namespace security::bindiff
#endif // SQLITE_H_