// get user prompts for table fields and add a new row // to a table, with an auto-incremented id. void CreateInTable(TableDefinition Def, char* Table, char* key){ string name, val; DB.UseTableDefinition(Def); //cout << "key: " << key; TableRow Columns = DB.GetColumnsForTable(Table); // get all the columns TableDataSet NewDataSet; for(unsigned int i=0; i<Columns.size(); i++){ if(Columns[i] == key){ int maxID = DB.GetMaxField(Table, key); int newID = maxID+1; stringstream ID(""); ID << newID; NewDataSet.push_back(make_pair(key, (char*)ID.str().c_str())); } else{ cout << Columns[i] << ": "; getline(cin, val); FieldDefinition WorkingFieldDefinition = DB.GetFieldDefinition((char*)Columns[i].c_str()); if((WorkingFieldDefinition.getLength() > 0) && (WorkingFieldDefinition.Validate((char*)val.c_str()))){ NewDataSet.push_back(make_pair(Columns[i],val)); } else{ cout << "validation failed for the field " << WorkingFieldDefinition.getName(); return; } } } DB.Create(Table, NewDataSet); DB.ShowTable(Table, NewDataSet); return; }
void ViewAccounts(){ DB.ShowTable(ACCOUNT_TABLE, DB.GetColumnsForTable(ACCOUNT_TABLE)); cout << endl; }
void ViewProfiles(){ DB.ShowTable(USER_TABLE, DB.GetColumnsForTable(USER_TABLE)); cout << endl; }