ah grazie! però guarda una parte del mio sorgente:
void comandi::rice7(connessione* conn)
{
double max;
Query query=conn->conness.query();
stringacom="SELECT max(contatore) FROM citazioni";
query<<SQLString(stringacom);
Result res=query.store();
if(res.size()==0)
{
system("cls");
cout<<"Impossibile fornire la citazione più acceduta\n"<<endl;
system("pause");
return;
}
Result::iterator i;
Row row;
i=res.begin();
row= *i;
max=double(row[0]);
stringacom="SELECT C.testo, C.id FROM citazioni C WHERE C. contatore="+perversa(max);
query<<SQLString(stringacom);
res=query.store();
if(res.size()==1)
{
system("cls");
cout << " Testo Citazione | ID " << endl;
cout << "°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° °°°°°" << endl;
for (i = res.begin(); i != res.end(); i++) {
row = *i;
cout << setw(26) << string(row[0])<< " |";
cout << setw(4) << string(row[1]) << " |" << endl;
}
cout << "|________________________________________________ ____|" <<endl<<endl;
string id = string(row[1]);
system("pause");
stringacom="SELECT C.testo, C.lingua, A.nome, A.nazionalità, O.titolo, O.data_pubblicazione, C.id FROM citazioni C, cutori A, scritto S, opera O WHERE C.ID ="+id+" and S.ID_autore=A.ID and S.ID_opera=C.ID_opera and O.ID=C.ID_opera";
query<<SQLString(stringacom);
res=query.store();
system("cls");
cout << " INFORMAZIONI RELATIVE ALLA CITAZIONE PIU' ACCEDUTA: "<< endl;
for (i = res.begin(); i != res.end(); i++)
{
row = *i;
cout << "Testo Citazione: "<< string(row[0]) << endl;
cout << "Lingua: " << string(row[1]) << endl;
cout << "Nome dell'autore: "<< string(row[2]) << endl;
cout << "Nazionalita': "<< string(row[3]) << endl;
cout << "Opera da cui e' tratta: "<< string(row[4]) << endl;
cout << "Pubblicata il: "<< string(row[5]) << endl;
}
stringacom="UPDATE citazioni SET contatore=contatore+1 WHERE ID="+int(row[6]);
query<<SQLString(stringacom);
res=query.store();
system("pause");
return;
}
else system("cls");
cout << " Testo Citazione | ID " << endl;
cout << "°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° °°°°°" << endl;
for (i = res.begin(); i != res.end(); i++)
{
row = *i;
cout << setw(26) << string(row[0])<< " |";
cout << setw(4) << string(row[1]) << " |" << endl;
}
cout << "|________________________________________________ _____|" <<endl<<endl;
system("pause");
}
void comandi::rice8(connessione* conn)
{
double caso;
int idmax;
Query query=conn->conness.query();
stringacom="SELECT max(ID) FROM citazioni";
query<<SQLString(stringacom);
Result res=query.store();
if(res.size()==0)
{
system("cls");
cout<<"Impossibile fornire una citazione casuale.\n"<<endl;
system("pause");
return;
}
else system("cls");
cout << "Record trovato:\n" << res.size()<<endl<<endl;
Result::iterator i;
Row row;
i=res.begin();
row=*i;
idmax=int(row[0]);
caso=double(1+rand()%idmax);
stringacom="SELECT C.testo, C.lingua, A.nome, A.nazionalità, O.titolo, O.data_pubblicazione, C.id FROM citazioni C, autori A, scritto S, opera O WHERE C.ID="+ perversa(caso)+" and S.ID_autore=A.ID and S.ID_opera=C.ID_opera and O.ID=C.ID_opera";
query<<SQLString(stringacom);
res=query.store();
cout << " INFORMAZIONI RELATIVE ALL'OPERA RICERCATA CASUALMENTE:"<< endl;
for (i = res.begin(); i != res.end(); i++)
{
row = *i;
cout << "Testo Citazione: "<< string(row[0]) << endl;
cout << "Lingua: " << string(row[1]) << endl;
cout << "Nome dell'autore: "<< string(row[2]) << endl;
cout << "Nazionalita': "<< string(row[3]) << endl;
cout << "Opera da cui e' tratta: "<< string(row[4]) << endl;
cout << "Pubblicata il: "<< string(row[5]) << endl;
}
system("pause");
}
come vedi la funzione rice7 si occupa di fornire la citazione più acceduta mentre la funzione rice8 si occupa di fornire una citazione a caso. la funzione che compare nel sorgente che un mio amico ha chiamata "perversa" è quello di cui ho bisogno. se hai bisogno di chiarimenti sulla struttura che ho usato dillo!
![]()