You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/infoLoggerAdminDB.cxx
+102-3Lines changed: 102 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -23,13 +23,14 @@
23
23
#include<iomanip>
24
24
#include<ctime>
25
25
#include<sstream>
26
+
#include<vector>
26
27
27
28
voidprintUsage()
28
29
{
29
30
printf("Usage: infoLoggerAdminDB ...\n");
30
-
printf(" -c command : action to execute. One of archive (archive main table and create new one), create (create main table), clear (delete main table content), destroy (destroy all tables, including archives), list (show existing message tables)\n");
31
+
printf(" -c command : action to execute. One of archive (archive main table and create new one), create (create main table), clear (delete main table content), destroy (destroy all tables, including archives), list (show existing message tables), status (show database content info)\n");
31
32
printf(" [-z pathToConfigurationFile] : sets which configuration to use. By default %s\n", INFOLOGGER_DEFAULT_CONFIG_PATH);
32
-
printf(" [-o optionName] : enable options not set by default. Possible values: partitioning (create new tables with partition by day)\n");
33
+
printf(" [-o optionName] : enable options not set by default. Possible values: partitioning (create new tables with partition by day), noWarning (disable interactive confirmation in delete operations).\n");
33
34
printf(" [-h] : print this help\n");
34
35
}
35
36
@@ -49,6 +50,9 @@ int main(int argc, char* argv[])
49
50
bool optList = 0; // list current tables
50
51
bool optNone = 0; // no command specified - test DB access only
51
52
bool optShowCreate = 0; // print command used to create table
53
+
bool optStatus = 0; // get a summary of database content
54
+
bool optStatusMore = 0; // print a summary of database content
55
+
bool optNoWarning = 0; // when set, there is no warning/interactive confirmation when data to be deleted
@@ -78,8 +82,11 @@ int main(int argc, char* argv[])
78
82
std::string optString = optarg;
79
83
if (optString == "partitioning") {
80
84
optPartitioning = 1;
85
+
} elseif (optString == "noWarning") {
86
+
optNoWarning = 1;
81
87
} else {
82
88
log.error("Wrong option %s", optString.c_str());
89
+
return -1;
83
90
}
84
91
} break;
85
92
@@ -95,12 +102,17 @@ int main(int argc, char* argv[])
95
102
optCreate = 1;
96
103
} elseif (command == "clear") {
97
104
optDelete = 1;
105
+
optStatus = 1;
98
106
} elseif (command == "destroy") {
99
107
optDestroy = 1;
108
+
optStatus = 1;
100
109
} elseif (command == "list") {
101
110
optList = 1;
102
111
} elseif (command == "showCreate") {
103
112
optShowCreate = 1;
113
+
} elseif (command == "status") {
114
+
optStatus = 1;
115
+
optStatusMore = 1;
104
116
} elseif (command == "") {
105
117
optNone = 1;
106
118
} else {
@@ -144,7 +156,70 @@ int main(int argc, char* argv[])
144
156
return0;
145
157
}
146
158
159
+
// info on current database content
160
+
structinfoTable {
161
+
std::string name;
162
+
unsignedlong rows;
163
+
unsignedlong size;
164
+
};
165
+
std::vector<infoTable> tables;
166
+
unsignedlonglong totalTables = 0; // number of tables
167
+
unsignedlonglong totalRows = 0; // number of rows
168
+
unsignedlonglong totalBytes = 0; // number of bytes
169
+
unsignedlonglong mainRows = 0; // number of messages in main table
170
+
unsignedlonglong mainBytes = 0; // number of bytes in main table
171
+
147
172
// execute command(s)
173
+
if (optStatus) {
174
+
std::string sqlQuery = "select TABLE_NAME,TABLE_ROWS,DATA_LENGTH from information_schema.TABLES where table_name like '" INFOLOGGER_TABLE_MESSAGES "%' order by table_name";
175
+
if (mysql_query(&db, sqlQuery.c_str())) {
176
+
log.error("Failed to execute %s\n%s", sqlQuery.c_str(), mysql_error(&db));
177
+
return -1;
178
+
}
179
+
MYSQL_RES* res;
180
+
res = mysql_store_result(&db);
181
+
if (res == NULL) {
182
+
log.error("Failed to retrieve results from query %s", sqlQuery.c_str());
183
+
return -1;
184
+
}
185
+
constint numFields = 3;
186
+
if (mysql_num_fields(res) != numFields) {
187
+
log.error("Failed to retrieve %d fields from query %s", numFields, sqlQuery.c_str());
188
+
return -1;
189
+
}
190
+
MYSQL_ROW row;
191
+
for (int n=0;;n++) {
192
+
row = mysql_fetch_row(res);
193
+
if (row == NULL) {
194
+
break;
195
+
}
196
+
for (int i=0; i<numFields; i++) {
197
+
if (row[i] == NULL) {
198
+
log.error("No field[%d] in row %d returned for query %s", i, n, sqlQuery.c_str());
0 commit comments