Docs/Prog/Manual/ApplicationLibraries/lib825mssql: appdatabase.h

File appdatabase.h, 1.9 KB (added by Don Wilson, 3 days ago)
Line 
1/*
2 * appmysql.h
3 *
4 * Created on: Oct 14, 2025
5 * Author: user
6 */
7
8#ifndef SRC_APPMYSQL_H_
9#define SRC_APPMYSQL_H_
10
11#include <mysql.h>
12#include "jsonobject.h"
13
14
15const uint32 appSQLCfgVer = 1;
16
17
18class CAppDatabaseCfg : public CJSONRootObject
19{
20public:
21 enum AppDbType { appDataSQLite, appDataMySQL, appDataMSSQL };
22
23private:
24 AppDbType dbType_;
25
26 std::string server_;
27 std::string server2_; // 2nd line for config screen in case one line input is not long enough
28 std::string user_;
29 std::string password_;
30 std::string database_;
31
32 bool chg_;
33
34public:
35 CAppDatabaseCfg(void) :
36 dbType_(appDataSQLite),
37 server_("127.0.0.1"),
38 server2_(""),
39 user_(MYSQL_DEFAULT_DBUSER),
40 password_(""),
41 database_(MYSQL_DEFAULT_DB),
42 chg_(false)
43 {
44 // Setup JSON tags
45
46 // Associate string "sqlite" equals enum value appDataSQLite and "mysql" equals enum value appDataMySQL
47 std::string jsonEnum =
48 "sqlite=" + std::to_string(appDataSQLite) +
49 ",mysql=" + std::to_string(appDataMySQL) +
50 ",mssql=" + std::to_string(appDataMSSQL);
51
52 SetTagEnum(&dbType_, "dbtype", jsonEnum);
53
54 SetTag(server_, "server");
55 SetTag(server2_, "server2");
56 SetTag(user_, "user");
57 SetTag(password_, "passw");
58 SetTag(database_, "database");
59
60 }
61
62 AppDbType GetDBType(void) { return dbType_; }
63
64 // std::string& GetServer(void) { return server_; }
65 // std::string& GetServer2(void) { return server2_; }
66 std::string GetServer(void) { return server_ + server2_; }
67
68 std::string& GetUser(void) { return user_; }
69 std::string& GetPassword(void) { return password_; }
70 std::string& GetDatabase(void) { return database_; }
71
72 void UpdateConfigForm(CForm *pForm);
73
74 int Config(void);
75
76 int FirstTimePrompt(void);
77
78 bool GetChanged(void) { return chg_; }
79
80 const char* GetDBTypeLabel(void) {
81 switch(dbType_)
82 {
83 case appDataMySQL:
84 return "MySQL";
85 case appDataMSSQL:
86 return "SQL Server";
87 default:
88 return "SQLite";
89 }
90 }
91};
92
93#endif /* SRC_APPMYSQL_H_ */