Commit 1c4a19d4 authored by Pavel Vainerman's avatar Pavel Vainerman

(LogDB): добавил флаг для безопасного многопоточного доступа к БД.

parent 8faecd39
......@@ -73,7 +73,7 @@ bool SQLiteInterface::connect( const std::string& param )
return connect( dbfile, false );
}
// -----------------------------------------------------------------------------------------
bool SQLiteInterface::connect( const string& dbfile, bool create )
bool SQLiteInterface::connect( const string& dbfile, bool create, int extra_sqlite_flags )
{
// т.к. sqlite3 по умолчанию, создаёт файл при открытии, то проверим "сами"
// if( !create && !uniset::file_exist(dbfile) )
......@@ -81,6 +81,9 @@ bool SQLiteInterface::connect( const string& dbfile, bool create )
int flags = create ? 0 : SQLITE_OPEN_READWRITE;
if( extra_sqlite_flags )
flags |= extra_sqlite_flags;
int rc = sqlite3_open_v2(dbfile.c_str(), &db, flags, NULL);
if( rc != SQLITE_OK )
......
......@@ -91,7 +91,7 @@ namespace uniset
~SQLiteInterface();
virtual bool connect( const std::string& param ) override;
bool connect( const std::string& dbfile, bool create );
bool connect(const std::string& dbfile, bool create, int extra_sqlite_flags = 0 );
virtual bool close() override;
virtual bool isConnection() const override;
virtual bool ping() const override;
......
......@@ -141,7 +141,7 @@ LogDB::LogDB( const string& name , const string& prefix ):
db = unisetstd::make_unique<SQLiteInterface>();
if( !db->connect(dbfile, false) )
if( !db->connect(dbfile, false, SQLITE_OPEN_FULLMUTEX) )
{
ostringstream err;
err << myname
......
......@@ -89,6 +89,7 @@ namespace uniset
\todo Добавить ротацию БД
\todo REST API: продумать команды и реализовать
\todo Сделать настройку, для формата даты и времени при выгрузке из БД (при формировании json).
\todo Возможно в /logs стоит в ответе сразу возвращать и общее количество в БД (это один лишний запрос, каждый раз).
\todo Продумать поддержку websocket
\todo Возможно в последствии оптимизировать таблицы (нормализовать) если будет тормозить. Сейчас пока прототип.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment