Reputation: 1
im using godot SQLite for my project there is to many invalid. here is my code
and im using godot 3.6 `extends Node
#onready var db = preload("res://addons/sqlite/godot-sqlite.gd").new() const db = preload("res://addons/godot-sqlite/bin/gdsqlite.gdns")
const DB_PATH = "res://random_words.db"
var words = [] # List of words loaded from the database var special_characters = [".", "!", "?"]
func _ready(): load_words_from_database()
func load_words_from_database(): # Open the database if not db.connect(DB_PATH): print("Failed to open the database at: ", DB_PATH) return
# Execute the query
var query = "SELECT word FROM words;"
if not db.query(query):
print("Failed to execute query: ", query)
db.close()
return
# Fetch rows and populate the words array
words.clear()
while db.next_row():
words.append(db.get_column_text(0)) # First column is 'word'
print("Loaded words: ", words.size())
db.close()
func get_prompt() -> String: if words.empty(): return "No words available in the database!"
var word_index = randi() % words.size()
var special_index = randi() % special_characters.size()
var word = words[word_index]
var special_character = special_characters[special_index]
var formatted_word = word.substr(0, 1).to_upper() + word.substr(1).to_lower()
return formatted_word + special_character
i have you guys can help for future study. thank you
Upvotes: 0
Views: 20
Reputation: 945
The issue is at:
if not db.connect(DB_PATH): print("Failed to open the database at: ", DB_PATH)
I don't think db.connect
does what you assume it does. db.connect
attempts to register a handler for a signal emitted by the db node. However, db
is not a node that emits a signal, it is a reference to the SQLite instance. That SQLite instance does not emit any signals, it simply provides functions to interact with the database.
To open the db file, you need to call db.open_db()
, however, the code that you have at the moment is probably not fit for purpose.
I strongly recommend that you start by replicating the minimal example provided by godot-sqlite in their demo application: https://github.com/2shady4u/godot-sqlite/releases/download/v3.0/demo.zip
Upvotes: 0