2018-06-07 Fred Gleason <fredg@paravelsystems.com>

* Implemented show database status in rddbmgr(8).
This commit is contained in:
Fred Gleason
2018-06-07 14:01:38 +00:00
parent f8b0970b7b
commit b791ca8a04
7 changed files with 212 additions and 79 deletions

View File

@@ -18,37 +18,17 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#include <stdlib.h>
#include <dbversion.h>
#include <rddb.h>
#include "rddbmgr.h"
bool MainObject::Modify(QString *err_msg,int set_schema,
const QString &set_version) const
bool MainObject::Modify(QString *err_msg,int set_schema) const
{
*err_msg="ok";
//
// Determine Target Schema
//
if(set_schema>0) {
if((set_schema<242)||(set_schema>RD_VERSION_DATABASE)) {
*err_msg="unsupported schema";
return false;
}
}
else {
if(set_version.isEmpty()) {
set_schema=RD_VERSION_DATABASE;
}
else {
if((set_schema=GetVersionSchema(set_version))==0) {
*err_msg="invalid/unsupported Rivendell version";
return false;
}
}
}
//
// Update/Revert
//
@@ -76,7 +56,7 @@ int MainObject::GetCurrentSchema() const
int ret=0;
QString sql=QString("select DB from VERSION");
RDSqlQuery *q=new RDSqlQuery(sql);
QSqlQuery *q=new QSqlQuery(sql);
if(q->first()) {
ret=q->value(0).toInt();
}
@@ -86,50 +66,3 @@ int MainObject::GetCurrentSchema() const
}
int MainObject::GetVersionSchema(const QString &ver) const
{
QString version=ver;
bool ok=false;
//
// Version -> Schema Map
//
std::map<QString,int> version_map;
version_map["2.10"]=242;
version_map["2.11"]=245;
version_map["2.12"]=254;
version_map["2.13"]=255;
version_map["2.14"]=258;
version_map["2.15"]=259;
version_map["2.16"]=263;
version_map["2.17"]=268;
version_map["2.18"]=272;
version_map["2.19"]=275;
version_map["2.20"]=286;
//
// Normalize String
//
if(version.left(1).lower()=="v") {
version=version.right(version.length()-1);
}
QStringList f0=f0.split(".",version);
if(f0.size()!=3) {
return 0;
}
for(int i=0;i<3;i++) {
f0[i].toInt(&ok);
if(!ok) {
return 0;
}
}
//
// Lookup Schema
//
if(version_map.count(f0[0]+"."+f0[1])==0) {
return 0;
}
return version_map[f0[0]+"."+f0[1]];
}