khairul169 / gdsqlite-native

SQLite module for Godot 3.x
MIT License
219 stars 41 forks source link

DB Location is limited to user:\\ #9

Open MarianoGnu opened 6 years ago

MarianoGnu commented 6 years ago

Current implementation forces you to have the DataBase located on the user:\\ folder, this is fine for saving player profile, but no straightforward when you want to use the database to store information like the item database (not inventory, but every item information and description)

My current workaround is copy my database to user's folder while i'm developing, but i'll need to pack it on the pck file when i release it.

khairul169 commented 6 years ago

I've pushed a commit that enable res:// access from open_db in 4772e9d6296e89a11f58702980b107cf3d638cdc. Still, you cannot open database packed in pck file. I don't know how packed files works in godot :(

MarianoGnu commented 6 years ago

Great, i'll try to build the module once again, i've been unable to build anything myself since my linux distro broke up. once i check this i'll open an issue on Godot to ask karrofel how can we access to pck file from native script

yeah826 commented 6 years ago

Do you think there will be a way to specify the exact folder we want to open our database in?

fire commented 6 years ago

Notes from the internet.

Frank Lesser [LSW] - Today at 01:39 Hi @iFire , just looking in my sqlite module in my build ( derived from the version found in the internet ) it is 193 lines so fairly small ( it implements SQLite::open using sqlite3_open which is

SQLITE_API int sqlite3_open(
  const char *zFilename, 
  sqlite3 **ppDb 
){
  return openDatabase(zFilename, ppDb,
                      SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0);
}

so if you want to use a read only db I would add a SQLite::open_read_only which uses SQLITE_OPEN_READONLY

iFire - Today at 07:22

The gdnative sqlite needs to be able to open pck files.

And presumably they're readonly. So I have to open the user writable database and then "attach" the read only db.

https://www.sqlite.org/lang_attach.html

quasar-kyle-2 commented 6 years ago

This doesn't seem to work. I can't open res://mydb.sqlite, but if i copy mydb.sqlite to user:// area on disk, then call open_db("mydb.sqlite") it works.

fire commented 6 years ago

https://github.com/fire/gdsqlite-native/commit/df915b3b5b7143a0108ddae961c98347fcb264ef

I was able to read the sqlite file into memory and allow pck file usage.

If you want to test it, export your game with pck. Remember to force include *.db.

Another thing you want to do is use the original code to write to user://.

Although I haven't tried it, I assume using globalize_path and a sql dump / write will work to write out the in-memory data.

Another thing to try is to attach the user:// writeable database as an external database.

fire commented 6 years ago

Moved https://github.com/fire/gdsqlite-native/commit/c8adbf7af705c43032c7eff3d1952e8acf52155e gdsqlite into two sets of functions.

One set of functions for sqlite and another for in memory buffer SQLite loads.

There is still a limitation of only one of each of file and buffer databases can be loaded.

khairul169 commented 6 years ago

Great work! 🎉 I think we should make an optional argument that tell the class to use normal file read or buffered memory read, rather than make more function that will confuse users. Anyway, thanks for your contribution! You can also open a pull request if you want to :)

fire commented 6 years ago

Do you mind if I move this to gdnative C++? Coding a SQLite class in C++ has less custom written code.

The interface in gdscript would be:

For the regular mode.

khairul169 commented 6 years ago

Yes that should work 👍

MarianoGnu commented 6 years ago

reduz mentioned that if you could pass a pointer to the oppened file to a function then you should be able to use the files from the pck without a lot of work

torohaifisch commented 6 years ago

did this get solved? i cant open my db from res://

fire commented 6 years ago

I did not get time to work on it, you are free to modify the code.

khairul169 commented 6 years ago

Hi guys! From commit 086894c7d5c6f251ca49a2c935e24483fdcccc41, now you can open database from both normal access and from the exported pck file.. And yeah, you will need at least godot 3.1 alpha1 because it's using nativescript 1.1.

So far you need to supply the buffers manually for now.. I can't automate it because it will crash if i instantiate File reference (GodotNativeTools/godot-cpp#184).

:smiley:

clayheaton commented 6 years ago

@khairul169 I was unable to get the latest download version to work in 3.0.6 (on MacOS). Does it also require 3.1? Anything I can do to help with this particular issue? I'm keep to have a read-only database of reference data in a Godot game and would prefer not to copy the SQLite database to the user directory, but rather, read it from the pck file.

Re-reading the info, I see it's not Mac compatible. What is needed to help make it Mac compatible?