PDA

View Full Version : Migrated from "old school Pawn" to sampctl and having trouble finding database location


GRiMMREAPER
26/07/2018, 10:53 PM
I am using SQLite. This is my folder structure:

https://i.imgur.com/arwcPJu.png

My gamemode files are in the modules folder I have searched the database file there but to no avail. I can establish connection to the database.

GRiMMREAPER
26/07/2018, 11:59 PM
Might aswell show my code.

database_init.pwn

#include <a_samp>
#include "defines.pwn"

new DB:Database;

DatabaseConnection() {
Database = db_open(DB_NAME);

if (Database == DB:0) {
printf("SQLite: Failed to establish connection to \"%s\".", DB_NAME);
return SendRconCommand("exit");
} else {
printf("SQLite: Established connection to \"%s\".", DB_NAME);

db_query(Database, "CREATE TABLE IF NOT EXISTS `users` (`id` INTEGER AUTOINCREMENT PRIMARY KEY, `name` VARCHAR(24) UNIQUE, `password` TEXT NOT NULL, `password_hash` TEXT NOT NULL, `online` INTEGER)");
}
return 1;
}


main.pwn
#include "modules\general.pwn" // Imports the code above.
main(){
DatabaseConnection();
}

https://i.imgur.com/aGb8DZ5.png

---

Update: I created a "Scriptfiles" folder and the database is created, but for some reason the tables are not being created.

GRiMMREAPER
27/07/2018, 08:56 AM
My query was a bit redundant. After a few searches, I came across this statement in SQLite's FAQ:

A column declared INTEGER PRIMARY KEY will autoincrement.

I used SQLite before (in Python), but (weirdly) I never used a column of the type INTEGER, therefore never running across this problem. Despite that, I still cannot find the database file. Should I create a scriptfiles folder?

EDIT: If I (re)create the "scriptfiles" folder, the database file is created, but I must run powershell/cmd as administrator (or set sampctl.exe to always run as administrator).

--

defines.pwn is inside a folder named accounts[B] (renamed from [B]core), in which all things regarding authentication and account management are part of. So defines.pwn will have the necessary definitions used in the whole accounts folder. Say I have another folder called vehicles I'd also have a defines.pwn in there. This seems like a good way to organize my workspace because I'm working alone and this structure was adopted from an older project I started with another guy who is fairly experienced, so I believe it works. Despite this, you can count on me taking a look at the project you linked because I'm sure it's worth the look and something will be learnt.

Cheers. I changed modules to gamemodes.

GRiMMREAPER
27/07/2018, 06:59 PM
Southclaw;4040088']Do you have `local` set to true in your `pawn.json`?

That seems to have fixed my issue. Cheers.