Skip to content

add get_table_info function #204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion doc_classes/SQLite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@
[/codeblock]
</description>
</method>
<method name="get_table_info">
<return type="bool" />
<description>
Gets the the info (specified using [method create_table]) of the table with name [code]table_name[/code]. This method is equivalent to the following query:
[codeblock]
db.query("PRAGMA table_info("+ table_name + ");")
[/codeblock]
</description>
</method>
<method name="insert_row">
<return type="bool" />
<description>
Expand Down Expand Up @@ -276,4 +285,4 @@
Same as [constant VERBOSE].
</constant>
</constants>
</class>
</class>
11 changes: 10 additions & 1 deletion src/gdsqlite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ void SQLite::_bind_methods() {

ClassDB::bind_method(D_METHOD("create_table", "table_name", "table_data"), &SQLite::create_table);
ClassDB::bind_method(D_METHOD("drop_table", "table_name"), &SQLite::drop_table);
ClassDB::bind_method(D_METHOD("get_table_info", "table_name"), &SQLite::get_table_info);

ClassDB::bind_method(D_METHOD("backup_to", "destination"), &SQLite::backup_to);
ClassDB::bind_method(D_METHOD("restore_from", "source"), &SQLite::restore_from);
Expand Down Expand Up @@ -487,6 +488,14 @@ bool SQLite::drop_table(const String &p_name) {
return query(query_string);
}

bool SQLite::get_table_info(const String &p_name) {
String query_string;
/* Create SQL statement */
query_string = "PRAGMA table_info(" + p_name + ");";

return query(query_string);
}

bool SQLite::backup_to(String destination_path) {
destination_path = ProjectSettings::get_singleton()->globalize_path(destination_path.strip_edges());
CharString dummy_path = destination_path.utf8();
Expand Down Expand Up @@ -1197,4 +1206,4 @@ int SQLite::load_extension(const String &p_path, const String &entrypoint) {
}

return rc;
}
}
1 change: 1 addition & 0 deletions src/gdsqlite.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class SQLite : public RefCounted {

bool create_table(const String &p_name, const Dictionary &p_table_dict);
bool drop_table(const String &p_name);
bool get_table_info(const String &p_name);

bool backup_to(String destination_path);
bool restore_from(String source_path);
Expand Down