From bcf8a84f2be6b3092341f9e22963d1ee07ea49f5 Mon Sep 17 00:00:00 2001 From: PersonGuyGit Date: Sun, 2 Apr 2023 12:52:39 -0600 Subject: [PATCH] created quite a few query functions to create a better CRUD usecase for the Genre selection function --- .../GenresSubstitution/genre_sub.gd | 88 ++++++++++++------ .../databases/genre_sub.db | Bin 32768 -> 40960 bytes 2 files changed, 57 insertions(+), 31 deletions(-) diff --git a/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/GenresSubstitution/genre_sub.gd b/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/GenresSubstitution/genre_sub.gd index 40deb4d..7826a1c 100644 --- a/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/GenresSubstitution/genre_sub.gd +++ b/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/GenresSubstitution/genre_sub.gd @@ -7,14 +7,11 @@ const SQLite = preload("res://addons/godot-sqlite/bin/gdsqlite.gdns") var db var db_name = "res://databases/genre_sub" - - # An item will contain the ID of the item in question, followed by the genre name, and the alias provided. # Examples of how to use createItem # createItem("Melee-Weapon") -# createCollection("Dessert Ration Item") -# createCollection("Single Rider Vehicle") - +# createItem("Dessert Ration Item") +# createItem("Single Rider Vehicle") func createItem(inputNameString): db.open_db() var tableName = "Item" @@ -29,7 +26,6 @@ func createItem(inputNameString): # createCollection(3, "SciFi", "Plasma Pistol") # createCollection(3, "ModernDay", "9MM Handgun") # createCollection(3, "Fantasy", "Shortbow") - func createCollection(ItemID, collectionName, aliasName): db.open_db() var tableName = "Collection" @@ -41,36 +37,72 @@ func createCollection(ItemID, collectionName, aliasName): print(dict) - -#Not to sure about this one. We may need to talk about a refactor here -func createGenreSubstitutionLayer(collectionID): +# This will r all records under a genreName. +# Examples of how to use +# readCollectionByGenreName("SciFi") +# readCollectionByGenreName("ModernDay") +# readCollectionByGenreName("Fantasy") +func readCollectionByGenreName(feedName): db.open_db() - var tableName = "Genre_Substitution_Layer" - var dict : Dictionary = Dictionary() - dict["collectionID"] = collectionID - db.insert_row(tableName,dict) - print(dict) + var tableName = "Collection" + db.query("select * from " + tableName + " where genreName = \"" + str(feedName) + "\"") + for i in range(0, db.query_result.size()): + print("TEST") + print("Query results ", db.query_result[i]["itemAlias"], db.query_result[i]["primaryKey"]) + return db.query_result -func getItemsByID(id): +#Not to sure about this one. We may need to talk about a refactor here +#func createGenreSubstitutionLayer(collectionID): +# db.open_db() +# var tableName = "Genre_Substitution_Layer" +# var dict : Dictionary = Dictionary() +# dict["collectionID"] = collectionID +# db.insert_row(tableName,dict) +# print(dict) +# + +func readItemsByID(id): db.open_db() db.query("select Item.baseName as baseName, Collection.collectionName as genreName from Item left join Collection on Item.primaryKey = Collection.itemID where Item.primaryKey = " + str(id)) for i in range(0, db.query_result.size()): print("Query results ", db.query_result[i]["baseName"], db.query_result[i]["genreName"]) return db.query_result - -# TO DO: Modify this query to provide a list of all items, that use the refer to the same base item; using item.baseName as the query item +# This will delete an Item record under your desired ID. +# Examples of how to use deleteItemByID +# deleteItemByID(2) +func deleteItemByID(id): + db.open_db() + var tableName = "Item" + db.query("delete from " + tableName + " where primaryKey = " + str(id)) + print("Deleted Item by ID " + str(id) + ".") + + +# This will delete a Collection record under your desired ID. +# Examples of how to use deleteCollectionByID +# deleteCollectionByID(2) +func deleteCollectionByID(id): + db.open_db() + var tableName = "Collection" + db.query("delete from " + tableName + " where primaryKey = " + str(id)) + print("Deleted Collection by ID " + str(id) + ".") + +# This will read an Item record under your desired baseName. +# Examples of how to use readItemByBaseName +# readItemByBaseName("sword") +func readIDByBaseName(feedName): + db.open_db() + var tableName = "Item" + db.query("select primaryKey as itemIDKey from " + tableName + " where baseName = \"" + str(feedName) + "\""); + for i in range(0, db.query_result.size()): + print("ID = ", db.query_result[i]["itemIDKey"]) + return db.query_result -#func getItemsByBaseName(feedName): -# db.open_db() -# db.query("select Item.baseName as baseName, Collection.collectionName as genreName from Item left join Collection on Item.primaryKey = Collection.itemID where Item.primaryKey = " + str(feedName)) -# for i in range(0, db.query_result.size()): -# print("Query results ", db.query_result[i]["baseName"], db.query_result[i]["genreName"]) -# return db.query_result - -func readItem(): +#This will read all items in the entire database. +#Just call this function to return them. +func readItems(): db.open_db() var tableName = "Item" db.query("select * from " + tableName) @@ -81,10 +113,4 @@ func readItem(): func _ready(): db = SQLite.new() db.path = db_name - getItemsByID(3) pass # Replace with function body. - - -# Called every frame. 'delta' is the elapsed time since the previous frame. -#func _process(delta): -# pass diff --git a/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/databases/genre_sub.db b/Phase2/Godot_Toolset/CodeSandboxes/ToolsetProjectTemplate/databases/genre_sub.db index 21dba53629b2143f7ebf8a69ff36515df976c421..490eda4548516ed6502912601eef5501e461ae8e 100644 GIT binary patch delta 469 zcmYL_yGz4R6vpq(O>C1UIW1D_18rK7E>giD=wyoz6s!t9aMNgm7GeTzRJyhJ2iTaY ztCOo_b8-;GA~?A?DPo6$4-nMB!J9!GzI!j6?|$cZPNl+BE|^+RL`Db+R6#0+D&!2R zaT%qzuq0iffLKQ`0=M#$SeN!?EZvB!;_6xTQDABH%c*|&_k>d&_v&IA2jClVNDaBy z((r&#T^9neL;@f3wzg^L6P977krDardTH!F>JPjVjy_(B942wvb08qn|};d2P_EJ0m6y0NR0DXF#R6zBAGXE7P;dMR$zS0CWZ89)+vm}pr==z)=XO~ zm6vv`qP=MybTb@+c)yyn@_Nyn)XHPIoHC=C`RzTk6VqBOrMj&)3V-FT~Z| zHAunFKSaSV)W=7Mi&H5%KPM+Oxg;|`&o41IRf!Xun#_{aT*sWu#A3MgWG`Nw&5!xy z7H2@pi7t+ zIVenOVBuos-^{@OjQW?&#J<+m1PW@TWMmSuKJ%qvMOt_;q|FDgmOFPCBh3d<`q s`{t*l7Uj7lR$BV{DtIL3rKFeUNiYKC#MPN6zv~wRnup>_0d!Xa01Gi@^#A|>