Made some changes to how the SQL connection works, wrote some queries, and documented my changes in the comments.

This commit is contained in:
PersonGuyGit
2023-04-16 12:29:39 -06:00
parent b417690f27
commit 3505214043
218 changed files with 886 additions and 93 deletions

View File

@ -1,6 +1,6 @@
[gd_scene load_steps=2 format=2]
[gd_scene load_steps=2 format=3 uid="uid://bn1k278a3em2j"]
[ext_resource path="res://GenresSubstitution/genre_sub.gd" type="Script" id=1]
[ext_resource type="Script" path="res://GenresSubstitution/genre_sub.gd" id="1"]
[node name="Node2D" type="Node2D"]
script = ExtResource( 1 )
script = ExtResource("1")

View File

@ -3,9 +3,16 @@ extends Node
# initialize the DB connection.
# All Databases will be under res/databases/{Desired Database}
const SQLite = preload("res://addons/godot-sqlite/bin/gdsqlite.gdns")
var db
#How to init the connection with Godot 3.5+
#const SQLite = preload("res://addons/godot-sqlite/bin/gdsqlite.gdns")
#var db
#How to init the connection with godot 4+
var db : SQLite = null
const verbosity_level : int = SQLite.VERBOSE
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
@ -37,7 +44,7 @@ func createCollection(ItemID, collectionName, aliasName):
print(dict)
# This will r all records under a genreName.
# This will return all records under a genreName.
# Examples of how to use
# readCollectionByGenreName("SciFi")
# readCollectionByGenreName("ModernDay")
@ -51,43 +58,17 @@ func readCollectionByGenreName(feedName):
print("Query results ", db.query_result[i]["itemAlias"], db.query_result[i]["primaryKey"])
return db.query_result
#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)
#
# This will return all Item records under an Item ID.
# Example of how to use
# read(3)
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
# 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")
@ -109,8 +90,59 @@ func readItems():
for i in range(0, db.query_result.size()):
print("Query results ", db.query_result[i]["baseName"], db.query_result[i]["primaryKey"])
# This will update an Item record under your desired ID.
# Example of how to use updateItemByID
# updateItemByID(1, "Stringed Instrument")
func updateItemByID(id, feedName):
db.open_db()
var tableName = "item"
db.query("update " + str(tableName) + " set baseName = " + "\"" + str(feedName) + "\"" + " where primaryKey = " + str(id) + ";")
return db.query_result
# This will update an Collection's Item Alias record under your desired ID.
# Example of how to use updateCollectionAliasByID
# updateItemByID(1, "Electric Guitar")
func updateCollectionAliasByID(id, feedName):
db.open_db()
var tableName = "collection"
db.query("update " + str(tableName) + " set itemAlias = " + "\"" + str(feedName) + "\"" + " where primaryKey = " + str(id) + ";")
return db.query_result
# This will update an Collection's Genre Name record under your desired ID.
# Example of how to use updateCollectionGenreByID
# updateCollectionGenreByID(1, "Cowboys VS Aliens")
func updateCollectionGenreByID(id, genreName):
db.open_db()
var tableName = "collection"
db.query("update " + str(tableName) + " set genreName = " + "\"" + str(genreName) + "\"" + " where primaryKey = " + str(id) + ";")
return db.query_result
# 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) + ".")
# Called when the node enters the scene tree for the first time.
func _ready():
db = SQLite.new()
db.path = db_name
updateCollectionGenreByID(1, "Cowboys VS Aliens")
pass # Replace with function body.