DescriptionI cannot open SQLite databases inside class member functions.
ReproducibleAlways
What you were doing when the bug happenedN/A
What you think caused the bugI'm too tired to find out right now. Hopefully I'll dig deeper when wake up tomorrow.
Code that can reproduce the error:
// ------------------------------------------------------------------------------------------------
DB <- {
}
// ------------------------------------------------------------------------------------------------
class DB.Database
{
// --------------------------------------------------------------------------------------------
_File = null
// --------------------------------------------------------------------------------------------
_Handle = null
// --------------------------------------------------------------------------------------------
constructor(db)
{
// Is this a path to a database?
if (typeof db == "string") _File = db, _Handle = null;
// Is this a handle to an already opened database?
else if (typeof db == "userdata") _File = null, _Handle = db;
// Invalid arguments were passed to the constructor
else return print(format("Database constructor requires parh or handle as it's first argument. Got: %s", typeof db));
}
function Open()
{
// Make sure the previous handle was closed or that there wasn't one to begin with
if (typeof _Handle == "userdata") return print("Database is already opened. Operation will be aborted.");
// Make sure that a database file was specified and that
else if (typeof _File != "string") return print("Unknown or missing database path. Operation will be aborted.");
// Try to open the file as an SQLite database now
print("member: " + _File + " is of type " + typeof _File);
_Handle = ConnectSQL(_File);
// Check if the previous operation succeeded and notify someone in case of failure
if (_Handle == null) return print(format("Unable to open the SQLite database from: %s", _File));
// The database was opened successfully and the operation is complete
else print(format("Successfully opened SQLite database from: %s", _File));
}
}
function onServerStart()
{
local db1 = ConnectSQL("mydb.db");
if (db1 == null) print("Method 1 failed");
else print("Method 1 succeeded");
local file = "mydb.db";
local db2 = ConnectSQL(file);
if (db2 == null) print("Method 2 failed");
else print("Method 2 succeeded");
// Try method
local db = DB.Database("mydb.db");
db.Open();
print("break point.");
}
Code image including line numbers and console output: