603206f7

Less-Than-Comparable


SSQLS могут также быть сделаны less-than-comparable. Это означает, что структуры могут сортироваться и сохраняться в наборах результатов как показывается в следующем примере. Имя файла: custom4.cc. #include <iostream> #include <iomanip> #include <vector> #include <sqlplus.hh> #include <custom.hh>

sql_create_5(stock, 1, 5, string,item, int,num, double,weight, double,price, Date,sdate)

int main() { try { // its in one big try block Connection con(use_exceptions); con.connect("mysql_cpp_data"); Query query = con.query(); query << "select * from stock"; set <stock> res; query.storein(res); // here we are storing the elements in a set not a vector. cout.setf (ios::left); cout << setw (17) << "Item" << setw (4) << "Num" << setw (7) << "Weight" << setw (7) << "Price" << "Date" << endl << endl; // Now we we iterate through the set. // Since it is a set the list will // naturally be in order. set <stock>::iterator i; cout.precision(3); for (i = res.begin (); i != res.end (); i++) { cout << setw (17) << i->item.c_str () << setw (4) << i->num << setw (7) << i->weight << setw (7) << i->price << i->sdate << endl; } i = res.find(stock("Hamburger Buns")); if (i != res.end()) cout << "Hamburger Buns found. Currently " << i->num << " in stock.\n"; else cout << "Sorry no Hamburger Buns found in stock\n"; // Now we are using the set's find method to find out how many // Hamburger Buns are in stock. return 0; } catch (BadQuery er) { cerr << "Error: " << er.error << endl; return -1; } catch (BadConversion er) { cerr << "Error: Tried to convert \"" << er.data << "\" to a \"" << er.type_name << "\"." << endl; return -1; } }



Содержание раздела