diff --git a/demo/addons/godot-sqlite/bin/osx/libgdsqlite.dylib b/demo/addons/godot-sqlite/bin/osx/libgdsqlite.dylib old mode 100644 new mode 100755 index 054e57e..0411d53 Binary files a/demo/addons/godot-sqlite/bin/osx/libgdsqlite.dylib and b/demo/addons/godot-sqlite/bin/osx/libgdsqlite.dylib differ diff --git a/demo/addons/godot-sqlite/bin/win64/libgdsqlite.dll b/demo/addons/godot-sqlite/bin/win64/libgdsqlite.dll index 1d4c436..0cf8817 100644 Binary files a/demo/addons/godot-sqlite/bin/win64/libgdsqlite.dll and b/demo/addons/godot-sqlite/bin/win64/libgdsqlite.dll differ diff --git a/demo/addons/godot-sqlite/bin/x11/libgdsqlite.so b/demo/addons/godot-sqlite/bin/x11/libgdsqlite.so index f857285..942e7df 100755 Binary files a/demo/addons/godot-sqlite/bin/x11/libgdsqlite.so and b/demo/addons/godot-sqlite/bin/x11/libgdsqlite.so differ diff --git a/demo/database.gd b/demo/database.gd index fe0ef75..5b49c85 100644 --- a/demo/database.gd +++ b/demo/database.gd @@ -16,15 +16,22 @@ var addresses : Array = ["California","Texas","Baltimore","Richmond","Texas","At var salaries : Array = [20000.00,15000.00,20000.00,65000.00,65000.00,65000.00,65000.00] func _ready(): - + example_of_basic_database_querying() + example_of_in_memory_and_foreign_key_support() + +# Basic example that goes over all the basic features available in the addon, such +# as creating and dropping tables, inserting and deleting rows and doing more elementary +# PRAGMA queries. +func example_of_basic_database_querying(): + + # Make a big table containing the variable types. var table_dict : Dictionary = Dictionary() table_dict["id"] = {"data_type":"int", "primary_key": true, "not_null": true} table_dict["name"] = {"data_type":"text", "not_null": true} table_dict["age"] = {"data_type":"int", "not_null": true} table_dict["address"] = {"data_type":"char(50)"} table_dict["salary"] = {"data_type":"real"} - #print(table_dict) - + db = SQLite.new() db.path = db_name db.verbose_mode = true @@ -34,7 +41,7 @@ func _ready(): db.drop_table(table_name) # Create a table with the structure found in table_dict and add it to the database db.create_table(table_name, table_dict) - + var row_array : Array = [] var row_dict : Dictionary = Dictionary() for i in range(0,ids.size()): @@ -44,7 +51,7 @@ func _ready(): row_dict["address"] = addresses[i] row_dict["salary"] = salaries[i] row_array.append(row_dict.duplicate()) - + # Insert a new row in the table db.insert_row(table_name, row_dict) row_dict.clear() @@ -88,20 +95,20 @@ func _ready(): # Do a normal query db.query("SELECT COUNT(*) AS 'number_of_employees' FROM " + table_name + ";") print("There are ", db.query_result[0]["number_of_employees"], " employees in the company") - + db.query("PRAGMA encoding;") 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(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(json_name + "_old") - + # Check which employees were present in this old json-file select_condition = "" selected_array = db.select_rows(table_name, select_condition, ["*"]) @@ -112,67 +119,66 @@ func _ready(): print("salary: ", typeof(selected_array[0]["salary"])) print("age: ", typeof(selected_array[0]["age"])) print("name: ", typeof(selected_array[0]["name"])) - + # 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(json_name + "_new") - + # Try to delete a non-existant table from the database. if not db.delete_rows(other_table_name, "*"): print("SQL error: " + db.error_message) - + # Close the imported database db.close_db() - - # Invoke example demonstrating in-memory and foreign key support. - example_of_in_memory_and_foreign_key_support() - # This example demonstrates the in-memory and foreign key support. It's # rather contrived, but it gets the point across. func example_of_in_memory_and_foreign_key_support(): - - # Create the database as usual, and turn on verbose mode. - db = SQLite.new() - db.verbose_mode = true - # Enable in-memory storage. - db.path = ":memory:" - # Enable foreign keys. - db.foreign_keys = true - # Open the database as usual. - db.open_db() - - # Create a table for all your friends. - db.create_table("friends", { - "id": {"data_type": "int", "primary_key": true, "not_null": true}, - "name": {"data_type": "text", "not_null": true, "unique": true}, - "hobby": {"data_type": "int", "foreign_key": "hobbies.id", "not_null": true} - }) - - # Create a table for all your friends' hobbies. - db.create_table("hobbies", { - "id": {"data_type": "int", "primary_key": true, "not_null": true}, - "description": {"data_type": "text", "not_null": true, "unique": true} - }) - - # ATTENTION: The important thing to note about the "friends" table is the - # definition of the foreign key "hobbies.id". This tells SQLITE to enforce - # the foreign key constraint, and that the field "friends.hobby" is now - # tied to the field "hobbies.id". Consequently, you are now required to - # specify a valid hobby when adding a friend to the database, which in - # turn means you first need to add some hobbies to the database before - # you can add any of your friends and assign them a hobby. - - # This won't work! There is no valid hobby with id 23 yet! - db.insert_rows("friends", [ - {"id": 1, "name": "John", "hobby": 23} - ]) - - # This will work! You create the hobby with id 23 first, then you can - # create your friend referencing that hobby. - db.insert_rows("hobbies", [ - {"id": 23, "description": "Extreme Relaxing"} - ]) - db.insert_rows("friends", [ - {"id": 1, "name": "John", "hobby": 23} - ]) + + # Create the database as usual. + db = SQLite.new() + # Enable in-memory storage. + db.path = ":memory:" + db.verbose_mode = true + # Enable foreign keys. + db.foreign_keys = true + # Open the database as usual. + db.open_db() + + # Create a table for all your friends. + db.create_table("friends", { + "id": {"data_type": "int", "primary_key": true, "not_null": true}, + "name": {"data_type": "text", "not_null": true, "unique": true}, + "hobby": {"data_type": "int", "foreign_key": "hobbies.id", "not_null": true} + }) + + # Create a table for all your friends' hobbies. + db.create_table("hobbies", { + "id": {"data_type": "int", "primary_key": true, "not_null": true}, + "description": {"data_type": "text", "not_null": true, "unique": true} + }) + + # ATTENTION: The important thing to note about the "friends" table is the + # definition of the foreign key "hobbies.id". This tells SQLITE to enforce + # the foreign key constraint, and that the field "friends.hobby" is now + # tied to the field "hobbies.id". Consequently, you are now required to + # specify a valid hobby when adding a friend to the database, which in + # turn means you first need to add some hobbies to the database before + # you can add any of your friends and assign them a hobby. + + # This won't work! There is no valid hobby with id 23 yet! + db.insert_rows("friends", [ + {"id": 1, "name": "John", "hobby": 23} + ]) + + # This will work! You create the hobby with id 23 first, then you can + # create your friend referencing that hobby. + db.insert_rows("hobbies", [ + {"id": 23, "description": "Extreme Relaxing"} + ]) + db.insert_rows("friends", [ + {"id": 1, "name": "John", "hobby": 23} + ]) + + # Close the database. + db.close_db() diff --git a/godot-cpp b/godot-cpp index 123d9f0..aba8766 160000 --- a/godot-cpp +++ b/godot-cpp @@ -1 +1 @@ -Subproject commit 123d9f0e9264dcc7206888fc96419b32feef00c8 +Subproject commit aba8766618c6aa40c6f7b40b513e8e47cfa807f4