2shady4u / godot-sqlite

GDExtension wrapper for SQLite (Godot 4.x+)
MIT License
956 stars 82 forks source link

Can't open database: unable to open database file FROM ANDROID DEVICE #80

Closed lcatoni72 closed 2 years ago

lcatoni72 commented 2 years ago
E 0:00:03.110   bool godot::SQLite::open_db(): GDSQLite **Error: Can't open database: unable to open database file**
  <Sorgente C++>./src/gdsqlite.cpp:126 @ bool godot::SQLite::open_db()()
  <Analisi dello stack>Main.gd:27 @ run()
                Main.gd:21 @ _ready()

E 0:00:03.110   bool godot::SQLite::query_with_bindings(godot::String, godot::Array):  --> SQL error: unable to open database file
  <Sorgente C++>./src/gdsqlite.cpp:192 @ bool godot::SQLite::query_with_bindings(godot::String, godot::Array)()
  <Analisi dello stack>Main.gd:27 @ run()
                Main.gd:21 @ _ready()

Hi, I'm having this issue executing code on my phisical android device form godot v 3.4.4.4 No issues playing on windows from Godot environment, all it works perfectly Can someone help me ? Thanks.

extends Node2D

const SQLite = preload ("res://addons/godot-sqlite/bin/gdsqlite.gdns")
var db
var db_name = "res://databases/thedb"
#var db_name = "user://thedb"

var STT

# Called when the node enters the scene tree for the first time.
func _ready():
    OS.request_permission("RECORD_AUDIO")
    if Engine.has_singleton("SpeechToText"):
        STT = Engine.get_singleton("SpeechToText")
        STT.setLanguage("en")
        STT.connect("error",self,"_on_error")
        STT.connect("listening_completed",self,"_on_listening_completed")       
    db = SQLite.new()
    db.path = db_name
    run()
    pass # Replace with function body.

func run():
    db.open_db()
    db.query("select * from sentence order by random() limit 1;")
2shady4u commented 2 years ago

Hi @lcatoni72!

You can't create nor edit databases in the res://-folder on Android. This is restriction of Android and not something fixable by this plugin, as discussed here: https://github.com/2shady4u/godot-sqlite#4-my-androidioshtml5-application-cannot-access-the-database

Your options are:

Note that in the second option, you won't be able to write anything to the database as the database will be packaged into your application's .PCK-file which is read-only by design.

lcatoni72 commented 2 years ago

Great, I used first solution with copy_data_to_user() function !! It works, thanks !!!

2shady4u commented 2 years ago

Closing this as the issue is resolved!