Added detailed view

develop
tastytea 2018-08-30 14:30:44 +02:00
parent c67f973227
commit 05c601021d
No known key found for this signature in database
GPG Key ID: CFC39497F1B26E07
2 changed files with 72 additions and 64 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.7) cmake_minimum_required (VERSION 3.7)
project (whyblocked project (whyblocked
VERSION 0.1.0 VERSION 0.2.0
LANGUAGES CXX LANGUAGES CXX
) )

View File

@ -46,83 +46,91 @@ int main(int argc, char *argv[])
{ {
sqlite::connection con(get_filepath()); sqlite::connection con(get_filepath());
string answer; string answer;
bool keeprunning = true;
cout << "Would you like to add, remove or view records?\n"; cout << "This is whyblock " << global::version << ".\n";
cout << "Or do you want to get the details of a record?\n"; cout << "Type add, remove, view or details. Or just the first letter.\n";
cout << "Type add, remove, view or details. Or just the first letter\n"; cout << "Type quit or q to quit the program.\n";
cout << ": "; while (keeprunning)
cin >> answer;
switch (answer[0])
{ {
case 'a': cout << ": ";
case 'A': cin >> answer;
switch (answer[0])
{ {
cout << "ADD\n"; case 'a':
break; case 'A':
}
case 'r':
case 'R':
{
cout << "REMOVE\n";
break;
}
case 'v':
case 'V':
{
sqlite::query q(con, "SELECT * FROM blocks;");
boost::shared_ptr<sqlite::result> result = q.get_result();
while(result->next_row())
{ {
if (result->get_int(1) == 1) cout << "ADD\n";
{ break;
cout << " Blocked: ";
}
else
{
cout << "Silenced: ";
}
cout << result->get_string(0) << " because: ";
cout << result->get_string(2) << '\n';
} }
break; case 'r':
} case 'R':
case 'd':
case 'D':
{
cout << "Which user?\n";
cin >> answer;
{ {
sqlite::query q(con, "SELECT * FROM blocks WHERE user = \'" + answer + "\';"); cout << "REMOVE\n";
boost::shared_ptr<sqlite::result> result = q.get_result(); break;
result->next_row();
cout << answer << " is ";
if (result->get_row_count() == 0)
{
cout << "not in the database.\n";
break;
}
if (result->get_int(1) == 1)
{
cout << "blocked, because: ";
}
else if (result->get_int(1) == 0)
{
cout << "silenced, because: ";
}
cout << result->get_string(2) << '\n';
} }
case 'v':
case 'V':
{ {
sqlite::query q(con, "SELECT * FROM urls WHERE user = \'" + answer + "\';"); sqlite::query q(con, "SELECT * FROM blocks;");
boost::shared_ptr<sqlite::result> result = q.get_result(); boost::shared_ptr<sqlite::result> result = q.get_result();
while(result->next_row()) while(result->next_row())
{ {
cout << result->get_string(1) << '\n'; if (result->get_int(1) == 1)
{
cout << " Blocked: ";
}
else
{
cout << "Silenced: ";
}
cout << result->get_string(0) << " because: ";
cout << result->get_string(2) << '\n';
} }
break;
} }
break; case 'd':
case 'D':
{
cout << "Which user?\n";
cin >> answer;
{
sqlite::query q(con, "SELECT * FROM blocks WHERE user = \'" + answer + "\';");
boost::shared_ptr<sqlite::result> result = q.get_result();
cout << answer << " is ";
if (!result->next_row())
{
cout << "not in the database.\n";
break;
}
if (result->get_int(1) == 1)
{
cout << "blocked, because: ";
}
else if (result->get_int(1) == 0)
{
cout << "silenced, because: ";
}
cout << result->get_string(2) << '\n';
}
{
cout << "Receipts:\n";
sqlite::query q(con, "SELECT * FROM urls WHERE user = \'" + answer + "\';");
boost::shared_ptr<sqlite::result> result = q.get_result();
while(result->next_row())
{
cout << " " << result->get_string(1) << '\n';
}
}
break;
case 'q':
case 'Q':
keeprunning = false;
break;
}
default:
cout << "Response not understood.\n";
} }
default:
cout << "Response not understood.\n";
} }
// sqlite::execute ins(con, "INSERT INTO TEST VALUES(?, ?, ?);"); // sqlite::execute ins(con, "INSERT INTO TEST VALUES(?, ?, ?);");
// ins % sqlite::nil % "Hello"; // ins % sqlite::nil % "Hello";