Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check return values when connecting to/creating a database #2

Merged
merged 6 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions convert.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int main(int argc, char* argv[]){
{"src", required_argument, NULL, 's'},
{"lmdb", no_argument, NULL, 'l'},
{"help", no_argument, NULL, 'h'},
{0}
{0, 0, 0, 0}
};
int option_index = 0;
while (1) {
Expand Down Expand Up @@ -54,18 +54,29 @@ int main(int argc, char* argv[]){


DB_ * x = new Libdb();
x->connect_database(src);
if (!x->connect_database(src)) {
// error is printed in the connect_database function
delete x;
return 1;
matejmatuska marked this conversation as resolved.
Show resolved Hide resolved
}
DB_ *b;
if (lmdb)
b = new LMDB_();
else
b = new GDBM_();
b->create_database(dst);
if (!b->create_database(dst)) {
std::cerr<<"Failed to create destination database\n";
delete x;
delete b;
return 1;
}
if (!b->fill_database(x)){
std::cerr<<"database filling failed\n";
delete x;
delete b;
matejmatuska marked this conversation as resolved.
Show resolved Hide resolved
return 1;
}
b->close_db();
b->close_db();
delete x;
delete b;
return 0;
Expand Down
1 change: 1 addition & 0 deletions convert_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class DB_ {
virtual bool fill_database(DB_ * old_database);
virtual void close_db();
virtual DBC * get_database();
virtual ~DB_();
};
/*
* Libdb class needs only open and read data from libdb database
Expand Down
4 changes: 4 additions & 0 deletions db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ DBC * DB_::get_database() {
return NULL;
}
void DB_::close_db(){}

DB_::~DB_() {
}

bool Libdb::connect_database(std::string path){
DB * db;
int status;
Expand Down