![]() |
Fotobot
Get data from your photovoltaic plant
|
Class for communication with database. More...
#include <database.h>
Public Slots | |
void | insertData (DBT_DATA) |
Writes data to database table DATA. More... | |
void | execMaintenance () |
Database maintenance. More... | |
void | deleteLine (QSqlDatabase &, int) |
Delete line in database. | |
void | deleteLine (int) |
void | deleteInvertor (QSqlDatabase &, int) |
Delete invertor in database. | |
void | deleteInvertor (int) |
void | deleteInterfacebox (QSqlDatabase &, int) |
Delete interfacebox in database. | |
void | deleteInterfacebox (int) |
void | deleteUser (QSqlDatabase &, QString userid) |
void | deleteUser (QString userid) |
QString | changePassword (QSqlDatabase &, DBT_USERS) |
Updates user's info (actually only password is changed) More... | |
QString | changePassword (DBT_USERS) |
void | saveUser (QSqlDatabase &, DBT_USERS) |
Updates user's info. | |
void | saveUser (DBT_USERS) |
int | saveLine (QSqlDatabase &, DBT_LINES) |
Insert or update LINE. More... | |
int | saveLine (DBT_LINES) |
int | saveInvertor (QSqlDatabase &, DBT_INVERTORS) |
Insert or update INVERTOR. More... | |
int | saveInvertor (DBT_INVERTORS) |
int | saveInterfacebox (QSqlDatabase &, DBT_INTERFACEBOXES) |
Insert or update Interfacebox. More... | |
int | saveInterfacebox (DBT_INTERFACEBOXES) |
void | saveMaintenance (QSqlDatabase &, DBT_MAINTENANCE) |
Updates maintenace record in database. | |
void | saveMaintenance (DBT_MAINTENANCE) |
void | setGeocoordinates (QSqlDatabase &, DBT_GEOCOORDINATES) |
update geocoordinates | |
void | setGeocoordinates (DBT_GEOCOORDINATES) |
void | commit () |
Commit transactions. More... | |
Signals | |
void | databaseChanged () |
Signals when information about lines or invertors changed. More... | |
Public Member Functions | |
DATABASE (QSettings *settings, QObject *parent=NULL) | |
QList< DBT_LINES > | lines (int line=0) |
Returns list of communications lines. More... | |
QList< DBT_INVERTORS > | invertors (int line=0) |
Returns list of invertors filtered by line number. | |
QList< DBT_INVERTORS > | invertors (const QList< int > &invertors) |
Returns list of invertors filtered by invertors numbers. More... | |
QList< DBT_INTERFACEBOXES > | interfaceboxes (int line=0) |
Returns list of interfaceboxes filtered by line number. | |
QList< DBT_INTERFACEBOXES > | interfaceboxes (const QList< int > &interfaceboxes) |
Returns list of interfaceboxes filtered by interfaceboxes numbers. More... | |
DBT_GEOCOORDINATES | geocoordinates () |
Returns geocoordinates. | |
QList< DBT_DATA_VW > | data (const QDateTime &from=QDateTime(), const QDateTime &to=QDateTime(), bool limit=true) |
Returns data for all invertors. More... | |
QList< DBT_USERS > | users (const QString &user=QString()) |
Returs list of users or selected user. | |
QList< DBT_MAINTENANCE > | maintenance () |
Returns list of DBT_MAINTENANCE. | |
QList< DBT_LINES_STATUS > | linesStatus () |
Returns status of lines. More... | |
Private Member Functions | |
void | create (QSqlDatabase &db) |
Creates new database structure in opened file. | |
void | upgrade (QSqlDatabase &db) |
QSqlDatabase | open (const QString &dbname) |
Opens or creates new database file. | |
QString | nulld (const QDateTime &x) |
Formats QDateTime for database store. More... | |
QString | nulli (const QVariant &x) |
Formats QVariant - integer for database store. More... | |
QString | nullf (const QVariant &x) |
Formats QVariant - double for database store. More... | |
QString | nulls (const QString &x) |
Formats QString for database store. More... | |
QString | nullb (bool x) |
Formats bool for database store. More... | |
Private Attributes | |
bool | m_in_transaction |
QTimer * | m_timerCommit |
QSqlDatabase | m_db |
QSqlDatabase | m_dbc |
QMutex | m_mutex |
Mutex for locking between threads. | |
QString | m_synchronous |
Class for communication with database.
The only object that can read and write to the database files. Contains all access methods needed for data storing in the rest of application.
Database engine SQLite is single-thread only. When using in multi-thread application there must be only single thread accessing object DATABASE at the same time and only one object can exist in application.
All functions in the DATABASE object are locked using QMutex.
Reading from database:
You can freely read data from database since the mutex locks object and no other thread can access the database at the same time.
Writing to database:
You can freely write data to your database since the mutex locks object and no other thread can acces the database at the same time. All insert/update functions are implemented as slots so if your thread cannot wait for database, you can use queued SIGNAL/SLOT mechanism from different threads:
Definition at line 47 of file database.h.
|
slot |
Updates user's info (actually only password is changed)
This method can only change existing record, no insert is possible.
Definition at line 308 of file database.cpp.
|
slot |
Commit transactions.
Since the database is as a default in "autocommit" state, when every standalone query is commited, then the database can be very slow when more lines are connected. For this reason are all inserts grouped in 5 secs block and the commit is requested every 5 secons by the m_timerCommit timer.
Definition at line 101 of file database.cpp.
QList< DBT_DATA_VW > DATABASE::data | ( | const QDateTime & | from = QDateTime() , |
const QDateTime & | to = QDateTime() , |
||
bool | limit = true |
||
) |
Returns data for all invertors.
from | - Date & Time from |
to | - Date & Time to |
limit | - Limit number of records |
When no parameter was given then last known state of all invertors is returned. When just one parameter was given then all records from this time till last know state is returned. Parameter limit is used to limit the number of records. There is a problem to compress big ammount of data (fbhw is low memory device).
Definition at line 611 of file database.cpp.
|
signal |
Signals when information about lines or invertors changed.
This signal is be connected to INVERTORS object where list of lines and invertors is stored. When the signal is received then all invertors should be re-read from database and recreated.
|
slot |
Database maintenance.
Deletes old records from "data" database table The age for deleting is taken from database table "maintenance".
Definition at line 1158 of file database.cpp.
|
slot |
Writes data to database table DATA.
This slot should be connected to signal INVERTOR::data(DBT_DATA); Data are passed by value let the queueing is possible - this is because data source and DATABASE object run in different thread.
Definition at line 734 of file database.cpp.
QList< DBT_INTERFACEBOXES > DATABASE::interfaceboxes | ( | const QList< int > & | interfaceboxes | ) |
Returns list of interfaceboxes filtered by interfaceboxes numbers.
interfaceboxes | - list of interfaceboxes to select |
Using:
Definition at line 554 of file database.cpp.
QList< DBT_INVERTORS > DATABASE::invertors | ( | const QList< int > & | invertors | ) |
Returns list of invertors filtered by invertors numbers.
invertors | - list of invertors to select |
Using:
Definition at line 470 of file database.cpp.
QList< DBT_LINES > DATABASE::lines | ( | int | line = 0 | ) |
Returns list of communications lines.
line | - number of requested line or 0 for all lines in database |
Definition at line 380 of file database.cpp.
QList< DBT_LINES_STATUS > DATABASE::linesStatus | ( | ) |
Returns status of lines.
Status consists from two basic information:
Working invertor is invertor which int last 10 minutes has at least one record in database without error.
Status is returned as a list of DBT_LINES_STATUS structures.
Definition at line 1186 of file database.cpp.
|
private |
Formats bool for database store.
Returns string "null" when string is not valid else returns string include apostrophs.
Definition at line 1327 of file database.cpp.
|
private |
Formats QDateTime for database store.
Returns string "null" when date is not valid. Returns datetime formated in: 'yyyy-MM-dd hh:mm:ss' include apostrophs.
Definition at line 1262 of file database.cpp.
|
private |
Formats QVariant - double for database store.
Returns string "null" when QVariant is not valid else returns double as a string.
Definition at line 1294 of file database.cpp.
|
private |
Formats QVariant - integer for database store.
Returns string "null" when QVariant is not valid else returns integer as a string.
Definition at line 1276 of file database.cpp.
|
private |
Formats QString for database store.
Returns string "null" when string is not valid else returns string include apostrophs.
Definition at line 1312 of file database.cpp.
|
slot |
Insert or update Interfacebox.
Definition at line 1038 of file database.cpp.
|
slot |
Insert or update INVERTOR.
Definition at line 922 of file database.cpp.
|
slot |
Insert or update LINE.
Definition at line 857 of file database.cpp.