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"
|
|
|
|
|
2022-09-04 18:44:57 +00:00
|
|
|
onready var only_once : bool = true
|
|
|
|
|
|
|
|
onready var textEntry = get_node("VBoxContainer/LineEdit")
|
|
|
|
onready var convoID = get_node("VBoxContainer/HBoxContainer/labelConvoID/LineEdit")
|
|
|
|
onready var layerID = get_node("VBoxContainer/HBoxContainer/labelLayerID/LineEdit")
|
|
|
|
onready var branchID = get_node("VBoxContainer/HBoxContainer/labelBranchID/LineEdit")
|
|
|
|
|
|
|
|
onready var saveButton = get_node("saveButton")
|
|
|
|
|
2022-08-21 18:55:47 +00:00
|
|
|
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()
|
2022-09-04 18:44:57 +00:00
|
|
|
dict["ConvoID"] = int(convoID.text)
|
|
|
|
dict["LayerID"] = int(layerID.text)
|
|
|
|
dict["BranchID"] = int(branchID.text)
|
|
|
|
dict["Text"] = textEntry.text
|
2022-08-21 18:55:47 +00:00
|
|
|
|
2022-08-28 18:29:57 +00:00
|
|
|
db.insert_row(tableName,dict)
|
2022-09-04 18:44:57 +00:00
|
|
|
|
|
|
|
print("Done with SQL commit")
|
2022-08-28 18:29:57 +00:00
|
|
|
|
|
|
|
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-09-04 18:44:57 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
func _process(delta):
|
|
|
|
if saveButton.pressed == true && only_once == true:
|
|
|
|
only_once = false
|
|
|
|
CommitDataToDB()
|
|
|
|
|
2022-08-21 18:55:47 +00:00
|
|
|
|