Migrated from "old school Pawn" to sampctl and having trouble finding database location
#1

I am using SQLite. This is my folder structure:



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.
Reply
#2

Might aswell show my code.

database_init.pwn

pawn Код:
#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
pawn Код:
#include "modules\general.pwn" // Imports the code above.
main(){
    DatabaseConnection();
}


---

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

My query was a bit redundant. After a few searches, I came across this statement in SQLite's FAQ:

Quote:

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 [B]accounts[B] (renamed from 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.
Reply
#4

Quote:
Originally Posted by [HLF]Southclaw
Посмотреть сообщение
Do you have `local` set to true in your `pawn.json`?
That seems to have fixed my issue. Cheers.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)