Skip to content

Commit

Permalink
Rebuild with import and export functionalities
Browse files Browse the repository at this point in the history
  • Loading branch information
2shady4u committed May 7, 2019
1 parent 631febb commit eb7997d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
Binary file modified demo/bin/osx/libgdsqlite.dylib
Binary file not shown.
Binary file modified demo/bin/win64/libgdsqlite.dll
Binary file not shown.
Binary file modified demo/bin/x11/libgdsqlite.so
Binary file not shown.
10 changes: 5 additions & 5 deletions demo/database.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ extends Node
const SQLite = preload("res://bin/gdsqlite.gdns")
var db
#var db_name = "user://test"
var db_name = "res://test"
var db_name = "res://data/test"
#var db_name = "test"
var json_name = "test_backup"
var json_name = "data/test_backup"
var table_name = "company"

var ids = [1,2,3,4,5,6,7]
Expand Down Expand Up @@ -92,14 +92,14 @@ func _ready():
print("Current database encoding is: ", db.query_result[0]["encoding"])

# Export the table to a json-file with a specified name
db.export_to_json("data/" + json_name + "_new")
db.export_to_json(json_name + "_new")

# Close the current database
db.close_db()

# Import (and, consequently, open) a database from an old backup json-file
print("Overwriting database content with old backup...")
db.import_from_json("data/" + json_name + "_old")
db.import_from_json(json_name + "_old")

# Check which employees were present in this old json-file
select_condition = ""
Expand All @@ -114,7 +114,7 @@ func _ready():

# Import the data (in a destructive manner) from the new backup json-file
print("Overwriting database content again with latest backup...")
db.import_from_json("data/" + json_name + "_new")
db.import_from_json(json_name + "_new")

# Close the imported database
db.close_db()
Expand Down
10 changes: 5 additions & 5 deletions src/gdsqlite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ bool SQLite::import_from_json(String import_path)
for (int i = 0; i <= old_number_of_tables - 1; i++)
{
Dictionary table_dict = query_result[i];
old_table_names.append(String(table_dict["name"]));
old_table_names.append((const String &)table_dict["name"]);
}

std::vector<table_struct> tables_to_import;
Expand Down Expand Up @@ -191,7 +191,7 @@ bool SQLite::export_to_json(String export_path)
Dictionary table_dict = database_dict[i];
String json_string, query_string;

query_string = "SELECT * FROM " + String(table_dict["name"]) + ";";
query_string = "SELECT * FROM " + (const String &)table_dict["name"] + ";";
query(query_string);
table_dict["row_array"] = query_result;

Expand All @@ -217,7 +217,7 @@ void SQLite::close_db()
// Cannot close database!
if (sqlite3_close_v2(db) != SQLITE_OK)
{
Godot::print("Cannot close database!");
Godot::print("GDSQLite Error: Cannot close database!");
}
else
{
Expand Down Expand Up @@ -394,7 +394,7 @@ bool SQLite::insert_rows(String p_name, Array p_row_array)
{
if (p_row_array[i].get_type() != Variant::DICTIONARY)
{
Godot::print("All elements of the Array should be of type Dictionary");
Godot::print("GDSQLite Error: All elements of the Array should be of type Dictionary");
return false;
}
if (!insert_row(p_name, p_row_array[i]))
Expand All @@ -417,7 +417,7 @@ Array SQLite::select_rows(String p_name, String p_conditions, Array p_columns_ar
{
if (p_columns_array[i].get_type() != Variant::STRING)
{
Godot::print("All elements of the Array should be of type String");
Godot::print("GDSQLite Error: All elements of the Array should be of type String");
return query_result;
}
query_string += (const String &)p_columns_array[i];
Expand Down

0 comments on commit eb7997d

Please sign in to comment.