Skip to content

Commit

Permalink
Make various database function local to database.cpp (#7727)
Browse files Browse the repository at this point in the history
These don't belong in the plugin class.
  • Loading branch information
manup authored Apr 25, 2024
1 parent 6c8014b commit b12dc46
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
32 changes: 20 additions & 12 deletions database.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2021 dresden elektronik ingenieurtechnik gmbh.
* Copyright (c) 2016-2024 dresden elektronik ingenieurtechnik gmbh.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -32,7 +32,7 @@ static const char *pragmaPageCount = "PRAGMA page_count";
static const char *pragmaPageSize = "PRAGMA page_size";
static const char *pragmaFreeListCount = "PRAGMA freelist_count";

static sqlite3 *db = nullptr; // TODO should be member of Database class
static sqlite3 *db = nullptr;
static char sqlBuf[MAX_SQL_LEN];

static StaticJsonDocument<1024 * 1024 * 2> dbJson; /* 2 mega bytes*/
Expand All @@ -48,6 +48,14 @@ struct DB_Callback {
******************************************************************************/
static bool initAlarmSystemsTable();
static bool initSecretsTable();
static bool setDbUserVersion(int userVersion);
static int getDbPragmaInteger(const char *sql);
static bool upgradeDbToUserVersion1();
static bool upgradeDbToUserVersion2();
static bool upgradeDbToUserVersion6();
static bool upgradeDbToUserVersion7();
static bool upgradeDbToUserVersion8();
static bool upgradeDbToUserVersion9();
static int sqliteLoadAuthCallback(void *user, int ncols, char **colval , char **colname);
static int sqliteLoadConfigCallback(void *user, int ncols, char **colval , char **colname);
static int sqliteLoadUserparameterCallback(void *user, int ncols, char **colval , char **colname);
Expand Down Expand Up @@ -430,7 +438,7 @@ void DeRestPluginPrivate::createTempViews()

/*! Returns SQLite pragma parameters specified by \p sql.
*/
int DeRestPluginPrivate::getDbPragmaInteger(const char *sql)
static int getDbPragmaInteger(const char *sql)
{
int rc;
int val = -1;
Expand All @@ -457,7 +465,7 @@ int DeRestPluginPrivate::getDbPragmaInteger(const char *sql)
}

/*! Writes database user_version to \p userVersion. */
bool DeRestPluginPrivate::setDbUserVersion(int userVersion)
static bool setDbUserVersion(int userVersion)
{
int rc;
char *errmsg;
Expand All @@ -482,7 +490,7 @@ bool DeRestPluginPrivate::setDbUserVersion(int userVersion)
}

/*! Upgrades database to user_version 1. */
bool DeRestPluginPrivate::upgradeDbToUserVersion1()
static bool upgradeDbToUserVersion1()
{
int rc;
char *errmsg;
Expand Down Expand Up @@ -549,7 +557,7 @@ bool DeRestPluginPrivate::upgradeDbToUserVersion1()
}

/*! Upgrades database to user_version 2. */
bool DeRestPluginPrivate::upgradeDbToUserVersion2()
static bool upgradeDbToUserVersion2()
{
int rc;
char *errmsg;
Expand Down Expand Up @@ -587,7 +595,7 @@ bool DeRestPluginPrivate::upgradeDbToUserVersion2()
}

/*! Upgrades database to user_version 6. */
bool DeRestPluginPrivate::upgradeDbToUserVersion6()
static bool upgradeDbToUserVersion6()
{
DBG_Printf(DBG_INFO, "DB upgrade to user_version 6\n");

Expand Down Expand Up @@ -650,7 +658,7 @@ bool DeRestPluginPrivate::upgradeDbToUserVersion6()
}

/*! Upgrades database to user_version 7. */
bool DeRestPluginPrivate::upgradeDbToUserVersion7()
static bool upgradeDbToUserVersion7()
{
DBG_Printf(DBG_INFO, "DB upgrade to user_version 7\n");

Expand Down Expand Up @@ -701,7 +709,7 @@ bool DeRestPluginPrivate::upgradeDbToUserVersion7()
}

/*! Upgrades database to user_version 8. */
bool DeRestPluginPrivate::upgradeDbToUserVersion8()
static bool upgradeDbToUserVersion8()
{
DBG_Printf(DBG_INFO, "DB upgrade to user_version 8\n");

Expand Down Expand Up @@ -731,7 +739,7 @@ bool DeRestPluginPrivate::upgradeDbToUserVersion8()
}

/*! Upgrades database to user_version 9. */
bool DeRestPluginPrivate::upgradeDbToUserVersion9()
static bool upgradeDbToUserVersion9()
{
DBG_Printf(DBG_INFO, "DB upgrade to user_version 9\n");

Expand Down Expand Up @@ -5759,7 +5767,7 @@ void DeRestPluginPrivate::saveDb()

if (rc == SQLITE_OK)
{
DBG_Printf(DBG_INFO_L2, "DB saved in %ld ms\n", measTimer.elapsed());
DBG_Printf(DBG_INFO_L2, "DB saved in %ld ms\n", (long)measTimer.elapsed());

if (saveDatabaseItems & DB_SYNC)
{
Expand Down Expand Up @@ -7020,7 +7028,7 @@ std::vector<DB_ResourceItem> DB_LoadSubDeviceItems(QLatin1String uniqueId)
if (size_t(ret) < sizeof(sqlBuf))
{
char *errmsg = nullptr;
int rc = sqlite3_exec(db, qPrintable(sqlBuf), DB_LoadSubDeviceItemsCallback, &result, &errmsg);
int rc = sqlite3_exec(db, sqlBuf, DB_LoadSubDeviceItemsCallback, &result, &errmsg);

if (errmsg)
{
Expand Down
8 changes: 0 additions & 8 deletions de_web_plugin_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -1517,14 +1517,6 @@ public Q_SLOTS:
void checkDbUserVersion();
void cleanUpDb();
void createTempViews();
int getDbPragmaInteger(const char *sql);
bool setDbUserVersion(int userVersion);
bool upgradeDbToUserVersion1();
bool upgradeDbToUserVersion2();
bool upgradeDbToUserVersion6();
bool upgradeDbToUserVersion7();
bool upgradeDbToUserVersion8();
bool upgradeDbToUserVersion9();
void pushZdpDescriptorDb(quint64 extAddress, quint8 endpoint, quint16 type, const QByteArray &data);
void pushZclValueDb(quint64 extAddress, quint8 endpoint, quint16 clusterId, quint16 attributeId, qint64 data);
bool dbIsOpen() const;
Expand Down

0 comments on commit b12dc46

Please sign in to comment.