2shady4u / godot-sqlite

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

Update 4. My Android/iOS/HTML5 application cannot access the database! #149

Closed acgc99 closed 9 months ago

acgc99 commented 1 year ago

I'm using Godot v4.1.stable.official [970459615] and I faced the problem mentioned on the README.md file: "4. My Android/iOS/HTML5 application cannot access the database!".

I'm using a read-only database, I achieved access from res:// folder more easily than it is said. Steps:

  1. Add *.db to Project > Export... > Android (Runnable)> Resources > Filters to export non-resource files/folder.
  2. Set the database to be read-only before openning: mydb.set_read_only(true).

Following this two steps I'm able to access the database from Android. I suggest testing this on other Android devices and add this instructions to the README.md file.

Not tested on iOS/HTML5

2shady4u commented 1 year ago

Hello @acgc99

What platform are developing your games on? (Linux, Windows, MacOSX?) Did you have to do any modifications to the plugin files or did everything work out of the box?

I'll see if I can update the README.md :)

acgc99 commented 1 year ago

I use Windows 11.

I didn't do any modification to the plugin files.

I think that the key point is to include .db files in the export settings.

grymjack commented 1 year ago

Expoting for Linux with 'embed .PCK' option turned on to include all the project assets in the executable. In the export settings I included the filetype and even the directory the database is stored in:

'.db,/Assets/Data/'

(there is a wildcard asterix at the beginning and end)

When executing the binary, it throws the 'SQL error: unable to open database file' error. However, if I include the assets directory from the project in the folder with the executable, it works fine. The database file is the only project asset in that directory that has trouble loading. Any thoughts on what I am doing wrong?

note: I'm pretty sure the database is being included in the executable based on the size. below is the code I am using:


func executesqlstring(sql_string, data=[]):
    # testing for data binding
    if (data.empty() == false):
        db.query_with_bindings(sql_string, data)
    else:
        # executing sql command
        db.query(sql_string)

    #returning result
    return db.query_result
2shady4u commented 1 year ago

Hello @grymjack Did you open the database in read_only mode?

grymjack commented 1 year ago

No I am in R/W mode. I checked that upon on seeing earlier posts. I can test that as the app does write to the database as well. It did write successfully once I moved the original projects assets directory into the app directory. Below is the code I use to open the database. Sorry I should have included that in the earlier post.

# external modules
const SQLite = preload("res://addons/godot-sqlite/bin/gdsqlite.gdns")

func dbinit():
    db = SQLite.new()
    db_name = "res://Assets/Data/ClientData.db"  # path to database

    # opening the database
    db.path = db_name
    db.open_db(db_name)
2shady4u commented 1 year ago

Hello @grymjack

When you embed the database into the .pck or into the .exe you cannot write new stuff to this database. The .pck-file is read-only by design.

As a result, you'll have to set your SQLite object to read_only otherwise Godot won't be able to open the database.

grymjack commented 1 year ago

Thank you for that info, I did not know! I however need to read/write to the database. I assume that there is a way to pass login credentials to sqllite through your addon? BTW: do you have a donation link I can send you a good cup of coffee? I really appreciate you making this addon, what I am working on would not be possible without it.

2shady4u commented 9 months ago

Thank you for that info, I did not know! I however need to read/write to the database. I assume that there is a way to pass login credentials to sqllite through your addon? BTW: do you have a donation link I can send you a good cup of coffee? I really appreciate you making this addon, what I am working on would not be possible without it.

Hello! Apologies for the immense delay... 😞 If you need read/write access on a mobile platform, you will have to copy or create the database in the user://-folder. See this section: https://github.com/2shady4u/godot-sqlite?tab=readme-ov-file#read-and-write-databases

Closing this issue as the original issue/problem has been solved.