AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Database.Connect callback is not invoked until i unload plugin? (https://forums.alliedmods.net/showthread.php?t=340555)

gromit190 11-24-2022 15:00

Database.Connect callback is not invoked until i unload plugin?
 
Hello,

I am following the example from the docs:

Code:

Database hDatabase = null;
 
void StartSQL()
{
    Database.Connect(GotDatabase);
}
 
public void GotDatabase(Database db, const char[] error, any data)
{
    PrintToServer("Got database2"); // <--- this won't actually happen until I do: sm plugins unload myplugin
    if (db == null)
    {
        LogError("Database failure: %s", error);
    }
    else
    {
        hDatabase = db;
    }
}

But, for some odd reason, the "GotDatabase" is not invoked unless I unload the plugin.

In the GotDatabase function I am calling "PrintToServer", and also I am inserting a row to the db. I monitor both the server console, and the table in the db and nothing happens UNLESS I unload the plugin.

What am I doing wrong?

Bacardi 11-24-2022 16:42

Re: Database.Connect callback is not invoked until i unload plugin?
 
Close connection by deleting Handle.
Code:

delete hDatabase ;

asherkin 11-25-2022 14:50

Re: Database.Connect callback is not invoked until i unload plugin?
 
This sounds like there is something wrong with the DB thread on your server.

When you unload the plugin SM shifts all the pending threaded operations to happen on the main game thread in order to block the plugin unloading until they're complete.


All times are GMT -4. The time now is 11:07.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.