-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteractive_mode.cpp
More file actions
29 lines (27 loc) · 963 Bytes
/
Copy pathinteractive_mode.cpp
File metadata and controls
29 lines (27 loc) · 963 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "interactive_mode.h"
#include <iostream>
void interactiveMode(Database& db) {
std::string input;
std::cout << "Interactive mode. Enter SQL queries (type 'exit' to quit):" << std::endl;
while (true) {
std::cout << "> ";
std::getline(std::cin, input);
if (input == "exit") break;
try {
if (input.find("SELECT") == 0) {
auto rows = db.fetchQuery(input);
for (const auto& row : rows) {
for (const auto& col : row) {
std::cout << col << " ";
}
std::cout << std::endl;
}
} else {
db.executeQuery(input);
std::cout << "Query executed successfully." << std::endl;
}
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
}
}
}