Skip to content

Commit

Permalink
Databases and user input stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
jmsv committed Mar 12, 2017
1 parent 31839b8 commit 9227cec
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
30 changes: 10 additions & 20 deletions src/dbstore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,6 @@
#include <string>
using namespace std;

int database_test()
{
sqlite3* db;
char* zErrMsg = 0;
int rc;

rc = sqlite3_open("database/test.db", &db);

if (rc) {
return (0);
} else {
return 1;
}
sqlite3_close(db);

return 0;
}

static int callback(void* NotUsed, int argc, char** argv, char** azColName)
{
int i;
Expand Down Expand Up @@ -58,10 +40,18 @@ int create_user_database(string player_name)

// Execute SQL statement
rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg);

if (rc != SQLITE_OK) {
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
string zErrMsg_str = zErrMsg;
string tableExists = "table INVENTORY already exists";
if (tableExists == zErrMsg_str) {
print("Loaded " + databaseName);
} else {
print(zErrMsg_str);
sqlite3_free(zErrMsg);
}
}

sqlite3_close(db);
return 0;
}
Expand Down
18 changes: 17 additions & 1 deletion src/userin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,26 @@ bool valid_name(string test_name)
return true;
}

bool valid_text(string text)
{
if (text.length() < 1){
return false;
}
return true;
}

string get_text()
{
string textIn = "";
cin >> textIn;
bool validIn = false;
while(!validIn){
getline(cin, textIn);
if (!valid_text(textIn)){
print("Invalid input - please try again", "red");
} else {
validIn = true;
}
}
return textIn;
}

Expand Down

1 comment on commit 9227cec

@jmsv
Copy link
Owner Author

@jmsv jmsv commented on 9227cec Mar 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#2

Please sign in to comment.