polserver/pol-core/pol/module/sqlitemod.cpp

40 lines
1 KiB
C++
Raw Permalink Normal View History

2024-07-19 09:45:17 +02:00
#include "sqlitemod.h"
2024-07-20 03:20:28 +02:00
#include "../sqlscrobj.h"
2024-07-19 10:38:42 +02:00
#include "bscript/berror.h"
2024-07-19 09:45:17 +02:00
#include "bscript/executor.h"
2024-07-20 03:20:28 +02:00
#include "bscript/impstr.h"
2024-07-19 10:38:42 +02:00
#include "clib/logfacility.h"
2024-07-20 03:20:28 +02:00
#include "sqlmod.h"
#include "sqlmod.inl.h"
2024-07-19 10:38:42 +02:00
#include <SQLiteCpp/SQLiteCpp.h>
#include <SQLiteCpp/VariadicBind.h>
2024-07-19 09:45:17 +02:00
#include <module_defs/sqlite.h>
using namespace Pol::Bscript;
namespace Pol::Module
{
SQLiteExecutorModule::SQLiteExecutorModule( Bscript::Executor& exec )
2024-07-19 23:13:37 +02:00
: Bscript::TmplExecutorModule<SQLiteExecutorModule, Core::PolModule>( exec )
2024-07-19 09:45:17 +02:00
{
}
2024-07-20 03:20:28 +02:00
BObjectImp* SQLiteExecutorModule::mf_sqlite_open()
2024-07-19 09:45:17 +02:00
{
2024-07-20 03:20:28 +02:00
const String* filename = getStringParam( 0 );
if ( !filename )
2024-07-19 10:38:42 +02:00
{
2024-07-20 03:20:28 +02:00
return new BError( "Invalid parameters" );
}
2024-07-19 10:38:42 +02:00
2024-07-20 03:20:28 +02:00
auto connector = [filename = filename->getStringRep()]( Core::BSQLiteDatabase* conn )
{ return conn->open( filename ); };
2024-07-19 10:38:42 +02:00
2024-07-20 03:20:28 +02:00
return SQLExecutorModule::background_connect<Core::BSQLiteDatabase>( uoexec().weakptr,
connector );
2024-07-19 09:45:17 +02:00
}
} // namespace Pol::Module