2022-08-21 18:55:47 +00:00
|
|
|
extends Node
|
|
|
|
|
|
|
|
const SQLite = preload("res://addons/godot-sqlite/bin/gdsqlite.gdns")
|
|
|
|
var db # Database object
|
|
|
|
var db_name = "res://DataStorage/database"
|
|
|
|
|
|
|
|
func CommitDataToDB():
|
|
|
|
db = SQLite.new()
|
|
|
|
db.path = db_name
|
|
|
|
db.open_db()
|
2022-08-28 18:29:57 +00:00
|
|
|
var tableName = "DataStorage"
|
2022-08-21 18:55:47 +00:00
|
|
|
var dict : Dictionary = Dictionary()
|
|
|
|
dict["ConvoID"] = 1
|
|
|
|
dict["LayerID"] = 1
|
|
|
|
dict["BranchID"] = 1
|
|
|
|
dict["Text"] = "The best riff from Freebird plays at 202 dB."
|
|
|
|
|
2022-08-28 18:29:57 +00:00
|
|
|
db.insert_row(tableName,dict)
|
|
|
|
|
|
|
|
func readFromDB():
|
|
|
|
db = SQLite.new()
|
|
|
|
db.path = db_name
|
|
|
|
db.open_db()
|
|
|
|
var tableName = "DataStorage"
|
|
|
|
db.query("select * from " + tableName + ";")
|
|
|
|
for i in range(0, db.query_result.size()):
|
|
|
|
print("Query Results: ", db.query_result[i]["ConvoID"], db.query_result[i]["LayerID"], db.query_result[i]["BranchID"],db.query_result[i]["Text"])
|
|
|
|
|
|
|
|
|
|
|
|
func DeleteFromDBByID(idNum):
|
|
|
|
var idStr = str(idNum)
|
|
|
|
db = SQLite.new()
|
|
|
|
db.path = db_name
|
|
|
|
db.open_db()
|
|
|
|
var tableName = "DataStorage"
|
|
|
|
db.query("delete from " + tableName + " where ConvoID = " + idStr + ";")
|
2022-08-21 18:55:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready():
|
2022-08-28 18:29:57 +00:00
|
|
|
DeleteFromDBByID(1)
|
2022-08-21 18:55:47 +00:00
|
|
|
|