Commit fee860f2 authored by Pavel Vainerman's avatar Pavel Vainerman

(SQLite): первая версия реализации uniset-sqlite-dbserver

parent 5b23e1a6
......@@ -27,7 +27,7 @@
<RouteList>
</RouteList>
</LocalInfoServer>
<LocalDBServer dbname="UNISET_PLC" dbpass="dbadmin" dbuser="dbadmin" name="DBServer" pingTime="60000" reconnectTime="30000"/>
<LocalDBServer dbfile="test.db" dbname="UNISET_PLC" dbpass="dbadmin" dbuser="dbadmin" name="DBServer" pingTime="60000" reconnectTime="30000"/>
<LocalPrintServer checkTime="5000" device="/dev/lp0"/>
</Services>
</UniSet>
......
......@@ -239,22 +239,11 @@ void DBServer_SQLite::flushBuffer()
// Сперва пробуем очистить всё что накопилось в очереди до этого...
while( !qbuf.empty() )
{
#if 0
db->query( qbuf.front() );
// Дело в том что на INSERT И UPDATE запросы
// db->query() может возвращать false и надо самому
// отдельно проверять действительно ли произошла ошибка
// см. SQLiteInterface::query.
string err(db->error());
if( err.empty() )
db->freeResult();
else if( unideb.debugging(Debug::CRIT) )
if( !db->insert(qbuf.front()) && unideb.debugging(Debug::CRIT) )
{
unideb[Debug::CRIT] << myname << "(writeToBase): error: " << err <<
unideb[Debug::CRIT] << myname << "(writeToBase): error: " << db->error() <<
" lost query: " << qbuf.front() << endl;
}
#endif
qbuf.pop();
}
}
......@@ -331,10 +320,7 @@ void DBServer_SQLite::init_dbserver()
UniXML::iterator it(node);
unideb[DBLogInfoLevel] << myname << "(init): init connection.." << endl;
string dbname(conf->getProp(node,"dbname"));
string dbnode(conf->getProp(node,"dbnode"));
string user(conf->getProp(node,"dbuser"));
string password(conf->getProp(node,"dbpass"));
string dbfile(conf->getProp(node,"dbfile"));
tblMap[UniSetTypes::Message::SensorInfo] = "main_history";
tblMap[UniSetTypes::Message::Confirm] = "main_history";
......@@ -350,17 +336,12 @@ void DBServer_SQLite::init_dbserver()
else
lastRemove = false;
if( dbnode.empty() )
dbnode = "localhost";
if( unideb.debugging(DBLogInfoLevel) )
unideb[DBLogInfoLevel] << myname << "(init): connect dbnode=" << dbnode
<< "\tdbname=" << dbname
unideb[DBLogInfoLevel] << myname << "(init): connect dbfile=" << dbfile
<< " pingTime=" << PingTime
<< " ReconnectTime=" << ReconnectTime << endl;
#if 0
if( !db->connect(dbnode, user, password, dbname) )
if( !db->connect(dbfile,false) )
{
// ostringstream err;
if( unideb.debugging(Debug::CRIT) )
......@@ -382,8 +363,6 @@ void DBServer_SQLite::init_dbserver()
initDBTableMap(tblMap);
flushBuffer();
}
#endif
}
//--------------------------------------------------------------------------------------------
void DBServer_SQLite::createTables( SQLiteInterface *db )
......@@ -416,7 +395,6 @@ void DBServer_SQLite::timerInfo( UniSetTypes::TimerMessage* tm )
{
case DBServer_SQLite::PingTimer:
{
#if 0
if( !db->ping() )
{
if( unideb.debugging(Debug::WARN) )
......@@ -431,7 +409,6 @@ void DBServer_SQLite::timerInfo( UniSetTypes::TimerMessage* tm )
if( unideb.debugging(DBLogInfoLevel) )
unideb[DBLogInfoLevel] << myname << "(timerInfo): DB ping ok" << endl;
}
#endif
}
break;
......@@ -441,14 +418,12 @@ void DBServer_SQLite::timerInfo( UniSetTypes::TimerMessage* tm )
unideb[DBLogInfoLevel] << myname << "(timerInfo): reconnect timer" << endl;
if( db->isConnection() )
{
#if 0
if( db->ping() )
{
connect_ok = true;
askTimer(DBServer_SQLite::ReconnectTimer,0);
askTimer(DBServer_SQLite::PingTimer,PingTime);
}
#endif
connect_ok = false;
if( unideb.debugging(Debug::WARN) )
unideb[Debug::WARN] << myname << "(timerInfo): DB no connection.." << endl;
......
......@@ -49,6 +49,11 @@ SQLiteInterface::~SQLiteInterface()
}
// -----------------------------------------------------------------------------------------
bool SQLiteInterface::ping()
{
return db && ( sqlite3_db_status(db,0,NULL,NULL,0) == SQLITE_OK );
}
// -----------------------------------------------------------------------------------------
bool SQLiteInterface::connect( const string dbfile, bool create )
{
// т.к. sqlite3 по умолчанию, создаёт файл при открытии, то проверим "сами"
......
......@@ -43,6 +43,7 @@ class SQLiteInterface
bool connect( const std::string dbfile, bool create = false );
bool close();
bool isConnection();
bool ping(); // проверка доступности БД
inline void setOperationTimeout( timeout_t msec ){ opTimeout = msec; }
inline timeout_t getOperationTimeout(){ return opTimeout; }
......
#!/bin/sh
ulimit -Sc 1000000
uniset-start.sh -f ./uniset-sqlite-dbserver --confile test.xml --name DBServer1 \
--unideb-add-levels info,crit,warn,level9,system \
--dbserver-buffer-size 100
/usr/bin/uniset-stop.sh
\ No newline at end of file
../../conf/test.xml
\ No newline at end of file
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