void update(DictionaryList<T> params, NameValuePair<TT> qualifier) { for(size_t i=0;i<params.size();i++) { update<T,TT>(params[i],qualifier); } }
void print(DictionaryList& dl) { if (dl.size() == 0) cout << " List is EMPTY.\n"; for (dl.go_to_first(); dl.cursor_ok(); dl.step_fwd()) { cout << " " << dl.cursor_key(); cout << " " << dl.cursor_datum().c_str() << '\n'; } }
void insert(DictionaryList<T> params) { string query = "INSERT INTO "+table+" ("; ostringstream endquery; endquery<<" VALUES ( "; for(size_t i=0; i< params.size(); i++) { query+=" `"+fixInvalids(params[i].name)+"`"; ostringstream tempval; tempval<<params[i].value; endquery<<"'"<<fixInvalids(tempval.str())<<"'"; if(i < params.size()-1) { query+=","; endquery<<","; } } endquery<<" )"; query+=" )"+endquery.str(); DebugOut()<<"BaseDB: "<<query<<endl; q->execute(query); }
DictionaryList dictionary_tests() { DictionaryList dl; assert(dl.size() == 0); cout << "\nPrinting list just after its creation ...\n"; print(dl); // Insert using new keys. dl.insert(8001,"Dilbert"); dl.insert(8002,"Alice"); dl.insert(8003,"Wally"); assert(dl.size() == 3); cout << "\nPrinting list after inserting 3 new keys ...\n"; print(dl); dl.remove(8002); dl.remove(8001); dl.insert(8004,"PointyHair"); assert(dl.size() == 2); cout << "\nPrinting list after removing two keys and inserting PointyHair ...\n"; print(dl); // Insert using existing key. dl.insert(8003,"Sam"); assert(dl.size() == 2); cout << "\nPrinting list after changing data for one of the keys ...\n"; print(dl); dl.insert(8001,"Allen"); dl.insert(8002,"Peter"); assert(dl.size() == 4); cout << "\nPrinting list after inserting 2 more keys ...\n"; print(dl); cout << "***----Finished dictionary tests---------------------------***\n\n"; return dl; }
void test_copying() { DictionaryList one; // Copy an empty list. DictionaryList two; assert(two.size() == 0); // Copy a list with three entries and a valid cursor. one.insert(319,"Randomness"); one.insert(315,"Shocks"); one.insert(335,"ParseErrors"); one.go_to_first(); one.step_fwd(); DictionaryList three(one); assert(three.cursor_datum().isEqual("Randomness")); one.remove(335); cout << "Printing list--keys should be 315, 319\n"; print(one); cout << "Printing list--keys should be 315, 319, 335\n"; print(three); // Assignment operator check. one = two = three = three; one.remove(319); two.remove(315); cout << "Printing list--keys should be 315, 335\n"; print(one); cout << "Printing list--keys should be 319, 335\n"; print(two); cout << "Printing list--keys should be 315, 319, 335\n"; print(three); cout << "***----Finished tests of copying----------------------***\n\n"; }