|
7 | 7 | #include <godot_cpp/core/class_db.hpp>
|
8 | 8 |
|
9 | 9 | #include <godot_cpp/classes/global_constants.hpp>
|
10 |
| -#include <godot_cpp/classes/project_settings.hpp> |
11 |
| -#include <godot_cpp/classes/marshalls.hpp> |
12 | 10 | #include <godot_cpp/classes/json.hpp>
|
| 11 | +#include <godot_cpp/classes/marshalls.hpp> |
| 12 | +#include <godot_cpp/classes/project_settings.hpp> |
13 | 13 |
|
14 |
| -#include <fstream> |
15 |
| -#include <vector> |
16 |
| -#include <sstream> |
17 |
| -#include <cstring> |
18 |
| -#include <memory> |
19 | 14 | #include <sqlite/sqlite3.h>
|
20 | 15 | #include <vfs/gdsqlite_vfs.h>
|
| 16 | +#include <cstring> |
| 17 | +#include <fstream> |
| 18 | +#include <memory> |
| 19 | +#include <sstream> |
| 20 | +#include <vector> |
| 21 | + |
| 22 | +namespace godot { |
| 23 | +enum OBJECT_TYPE { |
| 24 | + TABLE, |
| 25 | + TRIGGER |
| 26 | +}; |
| 27 | +struct object_struct { |
| 28 | + String name, sql; |
| 29 | + OBJECT_TYPE type; |
| 30 | + Array base64_columns, row_array; |
| 31 | +}; |
21 | 32 |
|
22 |
| -namespace godot |
23 |
| -{ |
24 |
| - enum OBJECT_TYPE |
25 |
| - { |
26 |
| - TABLE, |
27 |
| - TRIGGER |
28 |
| - }; |
29 |
| - struct object_struct |
30 |
| - { |
31 |
| - String name, sql; |
32 |
| - OBJECT_TYPE type; |
33 |
| - Array base64_columns, row_array; |
34 |
| - }; |
| 33 | +class SQLite : public RefCounted { |
| 34 | + GDCLASS(SQLite, RefCounted) |
35 | 35 |
|
36 |
| - class SQLite : public RefCounted |
37 |
| - { |
38 |
| - GDCLASS(SQLite, RefCounted) |
| 36 | +private: |
| 37 | + bool validate_json(const Array &import_json, std::vector<object_struct> &tables_to_import); |
| 38 | + bool validate_table_dict(const Dictionary &p_table_dict); |
| 39 | + int backup_database(sqlite3 *source_db, sqlite3 *destination_db); |
39 | 40 |
|
40 |
| - private: |
41 |
| - bool validate_json(const Array &import_json, std::vector<object_struct> &tables_to_import); |
42 |
| - bool validate_table_dict(const Dictionary &p_table_dict); |
43 |
| - int backup_database(sqlite3 *source_db, sqlite3 *destination_db); |
| 41 | + sqlite3 *db; |
| 42 | + std::vector<std::unique_ptr<Callable>> function_registry; |
44 | 43 |
|
45 |
| - sqlite3 *db; |
46 |
| - std::vector<std::unique_ptr<Callable>> function_registry; |
| 44 | + int64_t verbosity_level = 1; |
| 45 | + bool foreign_keys = false; |
| 46 | + bool read_only = false; |
| 47 | + String path = "default"; |
| 48 | + String error_message = ""; |
| 49 | + String default_extension = "db"; |
| 50 | + TypedArray<Dictionary> query_result = TypedArray<Dictionary>(); |
47 | 51 |
|
48 |
| - int64_t verbosity_level = 1; |
49 |
| - bool foreign_keys = false; |
50 |
| - bool read_only = false; |
51 |
| - String path = "default"; |
52 |
| - String error_message = ""; |
53 |
| - String default_extension = "db"; |
54 |
| - TypedArray<Dictionary> query_result = TypedArray<Dictionary>(); |
| 52 | +protected: |
| 53 | + static void _bind_methods(); |
55 | 54 |
|
56 |
| - protected: |
57 |
| - static void _bind_methods(); |
| 55 | +public: |
| 56 | + // Constants. |
| 57 | + enum VerbosityLevel { |
| 58 | + QUIET = 0, |
| 59 | + NORMAL = 1, |
| 60 | + VERBOSE = 2, |
| 61 | + VERY_VERBOSE = 3 |
| 62 | + }; |
58 | 63 |
|
59 |
| - public: |
60 |
| - // Constants. |
61 |
| - enum VerbosityLevel |
62 |
| - { |
63 |
| - QUIET = 0, |
64 |
| - NORMAL = 1, |
65 |
| - VERBOSE = 2, |
66 |
| - VERY_VERBOSE = 3 |
67 |
| - }; |
| 64 | + SQLite(); |
| 65 | + ~SQLite(); |
68 | 66 |
|
69 |
| - SQLite(); |
70 |
| - ~SQLite(); |
| 67 | + // Functions. |
| 68 | + bool open_db(); |
| 69 | + bool close_db(); |
| 70 | + bool query(const String &p_query); |
| 71 | + bool query_with_bindings(const String &p_query, Array param_bindings); |
71 | 72 |
|
72 |
| - // Functions. |
73 |
| - bool open_db(); |
74 |
| - bool close_db(); |
75 |
| - bool query(const String &p_query); |
76 |
| - bool query_with_bindings(const String &p_query, Array param_bindings); |
| 73 | + bool create_table(const String &p_name, const Dictionary &p_table_dict); |
| 74 | + bool drop_table(const String &p_name); |
77 | 75 |
|
78 |
| - bool create_table(const String &p_name, const Dictionary &p_table_dict); |
79 |
| - bool drop_table(const String &p_name); |
| 76 | + bool backup_to(String destination_path); |
| 77 | + bool restore_from(String source_path); |
80 | 78 |
|
81 |
| - bool backup_to(String destination_path); |
82 |
| - bool restore_from(String source_path); |
| 79 | + bool insert_row(const String &p_name, const Dictionary &p_row_dict); |
| 80 | + bool insert_rows(const String &p_name, const Array &p_row_array); |
83 | 81 |
|
84 |
| - bool insert_row(const String &p_name, const Dictionary &p_row_dict); |
85 |
| - bool insert_rows(const String &p_name, const Array &p_row_array); |
| 82 | + Array select_rows(const String &p_name, const String &p_conditions, const Array &p_columns_array); |
| 83 | + bool update_rows(const String &p_name, const String &p_conditions, const Dictionary &p_updated_row_dict); |
| 84 | + bool delete_rows(const String &p_name, const String &p_conditions); |
86 | 85 |
|
87 |
| - Array select_rows(const String &p_name, const String &p_conditions, const Array &p_columns_array); |
88 |
| - bool update_rows(const String &p_name, const String &p_conditions, const Dictionary &p_updated_row_dict); |
89 |
| - bool delete_rows(const String &p_name, const String &p_conditions); |
| 86 | + bool create_function(const String &p_name, const Callable &p_callable, int p_argc); |
90 | 87 |
|
91 |
| - bool create_function(const String &p_name, const Callable &p_callable, int p_argc); |
| 88 | + bool import_from_json(String import_path); |
| 89 | + bool export_to_json(String export_path); |
92 | 90 |
|
93 |
| - bool import_from_json(String import_path); |
94 |
| - bool export_to_json(String export_path); |
| 91 | + int get_autocommit() const; |
95 | 92 |
|
96 |
| - int get_autocommit() const; |
| 93 | + // Properties. |
| 94 | + void set_last_insert_rowid(const int64_t &p_last_insert_rowid); |
| 95 | + int64_t get_last_insert_rowid() const; |
97 | 96 |
|
98 |
| - // Properties. |
99 |
| - void set_last_insert_rowid(const int64_t &p_last_insert_rowid); |
100 |
| - int64_t get_last_insert_rowid() const; |
| 97 | + void set_verbosity_level(const int64_t &p_verbosity_level); |
| 98 | + int64_t get_verbosity_level() const; |
101 | 99 |
|
102 |
| - void set_verbosity_level(const int64_t &p_verbosity_level); |
103 |
| - int64_t get_verbosity_level() const; |
| 100 | + void set_foreign_keys(const bool &p_foreign_keys); |
| 101 | + bool get_foreign_keys() const; |
104 | 102 |
|
105 |
| - void set_foreign_keys(const bool &p_foreign_keys); |
106 |
| - bool get_foreign_keys() const; |
| 103 | + void set_read_only(const bool &p_read_only); |
| 104 | + bool get_read_only() const; |
107 | 105 |
|
108 |
| - void set_read_only(const bool &p_read_only); |
109 |
| - bool get_read_only() const; |
| 106 | + void set_path(const String &p_path); |
| 107 | + String get_path() const; |
110 | 108 |
|
111 |
| - void set_path(const String &p_path); |
112 |
| - String get_path() const; |
| 109 | + void set_error_message(const String &p_error_message); |
| 110 | + String get_error_message() const; |
113 | 111 |
|
114 |
| - void set_error_message(const String &p_error_message); |
115 |
| - String get_error_message() const; |
| 112 | + void set_default_extension(const String &p_default_extension); |
| 113 | + String get_default_extension() const; |
116 | 114 |
|
117 |
| - void set_default_extension(const String &p_default_extension); |
118 |
| - String get_default_extension() const; |
| 115 | + void set_query_result(const TypedArray<Dictionary> &p_query_result); |
| 116 | + TypedArray<Dictionary> get_query_result() const; |
119 | 117 |
|
120 |
| - void set_query_result(const TypedArray<Dictionary> &p_query_result); |
121 |
| - TypedArray<Dictionary> get_query_result() const; |
122 |
| - |
123 |
| - TypedArray<Dictionary> get_query_result_by_reference() const; |
124 |
| - }; |
| 118 | + TypedArray<Dictionary> get_query_result_by_reference() const; |
| 119 | +}; |
125 | 120 |
|
126 |
| -} |
| 121 | +} //namespace godot |
127 | 122 |
|
128 | 123 | VARIANT_ENUM_CAST(SQLite::VerbosityLevel);
|
129 | 124 |
|
|
0 commit comments