WIP: remove the old database abstraction layer
remove such classes: - DbBase - DbConn - DbTextStream - Db while here: - remove: TextStream, SLog, TexTextStream
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2011-2014, Tomasz Sowa
|
||||
* Copyright (c) 2011-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -35,203 +35,63 @@
|
||||
#include "edb.h"
|
||||
#include "core/log.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
namespace Export
|
||||
{
|
||||
|
||||
|
||||
void EDb::SetDirs(Dirs * pdirs)
|
||||
{
|
||||
dirs = pdirs;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void EDb::SetExportCols(PGresult * r)
|
||||
void EDb::GetExport(morm::ModelConnector * model_connector, long user_id, std::vector<Export> & export_tab)
|
||||
{
|
||||
cid = AssertColumn(r, "id");
|
||||
cuser_id = AssertColumn(r, "user_id");
|
||||
cdir = AssertColumn(r, "dir");
|
||||
cftp_id = AssertColumn(r, "ftp_id");
|
||||
cftp_dir = AssertColumn(r, "ftp_dir");
|
||||
cname = AssertColumn(r, "name");
|
||||
cserver = AssertColumn(r, "server");
|
||||
clogin = AssertColumn(r, "login");
|
||||
cpass = AssertColumn(r, "pass");
|
||||
cpass_type = AssertColumn(r, "pass_type");
|
||||
morm::Finder<Export> finder(model_connector);
|
||||
|
||||
ccan_change_ftp_params = AssertColumn(r, "can_change_ftp_params");
|
||||
ccan_change_dir = AssertColumn(r, "can_change_dir");
|
||||
chttp_server = AssertColumn(r, "http_server");
|
||||
finder.select().where().eq(L"user_id", user_id).get_vector(export_tab);
|
||||
}
|
||||
|
||||
|
||||
void EDb::SetExportValues(PGresult * r, int row, Export & exp)
|
||||
void EDb::GetExport(morm::ModelConnector * model_connector, long id, Export & exp)
|
||||
{
|
||||
exp.Clear();
|
||||
morm::Finder<Export> finder(model_connector);
|
||||
|
||||
exp.id = AssertValueLong(r, row, cid);
|
||||
exp.user_id = AssertValueLong(r, row, cuser_id);
|
||||
exp.ftp_id = AssertValueLong(r, row, cftp_id);
|
||||
exp.ftp_pass_type = AssertValueInt(r, row, cpass_type);
|
||||
|
||||
AssertValueWide(r, row, cdir, exp.dir);
|
||||
AssertValueWide(r, row, cftp_dir, exp.ftp_dir);
|
||||
AssertValueWide(r, row, cname, exp.ftp_name);
|
||||
AssertValueWide(r, row, cserver, exp.ftp_server);
|
||||
AssertValueWide(r, row, clogin, exp.ftp_login);
|
||||
AssertValueWide(r, row, chttp_server, exp.http_server);
|
||||
AssertValueWide(r, row, cpass, exp.ftp_pass);
|
||||
|
||||
exp.can_change_ftp_params = AssertValueBool(r, row, ccan_change_ftp_params);
|
||||
exp.can_change_dir = AssertValueBool(r, row, ccan_change_dir);
|
||||
finder.select().where().eq(L"id", id).get(exp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool EDb::GetExport(long user_id, std::vector<Export> & export_tab, bool clear_tab)
|
||||
void EDb::GetExportDirs(morm::ModelConnector * model_connector, std::vector<ExportDir> & export_tab, bool clear_tab)
|
||||
{
|
||||
if( clear_tab )
|
||||
export_tab.clear();
|
||||
|
||||
PGresult * r = 0;
|
||||
bool result = true;
|
||||
std::vector<Export> exports;
|
||||
morm::Finder<Export> finder(model_connector);
|
||||
finder.select().get_vector(exports);
|
||||
|
||||
try
|
||||
for(size_t i=0 ; i < exports.size() ; ++i)
|
||||
{
|
||||
query.Clear();
|
||||
query << R( "select export.id, user_id, dir, ftp_id, ftp_dir, can_change_ftp_params, can_change_dir, "
|
||||
"http_server, name, server, login, pass, pass_type from plugins.export "
|
||||
"left join plugins.export_ftp on ftp_id = export_ftp.id where user_id = ")
|
||||
<< user_id
|
||||
<< R(";");
|
||||
|
||||
r = AssertQuery(query);
|
||||
AssertResult(r, PGRES_TUPLES_OK);
|
||||
Item * pdir = dirs->GetDir(exports[i].dir);
|
||||
|
||||
SetExportCols(r);
|
||||
int rows = Rows(r);
|
||||
|
||||
for(int i=0 ; i<rows ; ++i)
|
||||
if( pdir )
|
||||
{
|
||||
SetExportValues(r, i, exp);
|
||||
export_tab.push_back(exp);
|
||||
exp_dir.id = exports[i].id;
|
||||
exp_dir.dir_id = pdir->id;
|
||||
export_tab.push_back(exp_dir);
|
||||
}
|
||||
else
|
||||
{
|
||||
//slog << "There is not such a directory: " << dir_temp << " (skipping)" << logend;
|
||||
}
|
||||
}
|
||||
catch(const Error &)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
ClearResult(r);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool EDb::GetExport(long id, Export & exp)
|
||||
{
|
||||
exp.Clear();
|
||||
PGresult * r = 0;
|
||||
bool result = false;
|
||||
|
||||
try
|
||||
{
|
||||
query.Clear();
|
||||
query << R( "select export.id, user_id, dir, ftp_id, ftp_dir, can_change_ftp_params, can_change_dir, "
|
||||
"http_server, name, server, login, pass, pass_type from plugins.export "
|
||||
"left join plugins.export_ftp on ftp_id = export_ftp.id where export.id = ")
|
||||
<< id
|
||||
<< R(";");
|
||||
|
||||
r = AssertQuery(query);
|
||||
AssertResult(r, PGRES_TUPLES_OK);
|
||||
SetExportCols(r);
|
||||
|
||||
if( Rows(r) == 1 )
|
||||
{
|
||||
SetExportValues(r, 0, exp);
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
catch(const Error &)
|
||||
{
|
||||
}
|
||||
|
||||
ClearResult(r);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool EDb::GetExportDirs(std::vector<ExportDir> & export_tab, bool clear_tab)
|
||||
{
|
||||
if( clear_tab )
|
||||
export_tab.clear();
|
||||
|
||||
PGresult * r = 0;
|
||||
bool result = true;
|
||||
|
||||
try
|
||||
{
|
||||
query.Clear();
|
||||
query << R( "select export.id, dir from plugins.export;");
|
||||
|
||||
r = AssertQuery(query);
|
||||
AssertResult(r, PGRES_TUPLES_OK);
|
||||
|
||||
int rows = Rows(r);
|
||||
cid = AssertColumn(r, "id");
|
||||
cdir = AssertColumn(r, "dir");
|
||||
|
||||
for(int i=0 ; i<rows ; ++i)
|
||||
{
|
||||
exp_dir.id = AssertValueLong(r, i, cid);
|
||||
AssertValueWide(r, i, cdir, dir_temp);
|
||||
|
||||
Item * pdir = dirs->GetDir(dir_temp);
|
||||
|
||||
if( pdir )
|
||||
{
|
||||
exp_dir.dir_id = pdir->id;
|
||||
export_tab.push_back(exp_dir);
|
||||
}
|
||||
else
|
||||
{
|
||||
//slog << "There is not such a directory: " << dir_temp << " (skipping)" << logend;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(const Error &)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
ClearResult(r);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
} // namespace Winix
|
||||
|
Reference in New Issue
Block a user