Skip to content

Commit

Permalink
fix: error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
huaruoji committed Nov 26, 2024
1 parent 69704fd commit 72e2604
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,28 @@ int main(int argc, char *argv[]) {
if (parsed_statement->type == SQLStatementType::CREATE_DATABASE) {
if (databases.find(parsed_statement->getDatabaseName()) !=
databases.end()) {
throw DatabaseError("Database already exists");
throw DatabaseError("Database already exists",
parsed_statement->line_number);
}
databases[parsed_statement->getDatabaseName()] =
std::make_unique<Database>(parsed_statement->getDatabaseName());
} else if (parsed_statement->type == SQLStatementType::USE_DATABASE) {
if (databases.find(parsed_statement->getDatabaseName()) ==
databases.end()) {
throw DatabaseError("Database does not exist");
throw DatabaseError("Database does not exist",
parsed_statement->line_number);
}
current_database = databases[parsed_statement->getDatabaseName()].get();
} else {
if (!current_database) {
throw DatabaseError("No database selected",
parsed_statement->line_number);
}
current_database->executeStatement(parsed_statement.get());
}
#ifdef DEBUG
std::cerr << "Successfully parsed statement\n";
#endif
}
} catch (const ArgumentError &e) {
std::cerr << "ArgumentError: " << e.what() << "\n"
Expand Down

0 comments on commit 72e2604

Please sign in to comment.