Hab ein totales Anfängerproblem und mir fehlt mittlerweile der totale Durchblick für das Wesentliche. Ich habe 4 QCombos welche mit mit Daten aus der DB gefüttert werden:
(Hier nur eine dargestellt)
Code: Alles auswählen
// EP Term Combos füllen
QSqlQuery myEPTermQuery;
myEPTermQuery.exec("SELECT * FROM `tx_submission_epterm`");
while (myEPTermQuery.next())
{
EPTerm += myEPTermQuery.value(1).toString();
}
comboBox_printEpTerm->addItems(EPTerm);
So, falls mir noch jemand folgen kann, hier meine Frage:
1.) Gibts für diese Art der Abfrage eine bessere Art der Schleifenbildung?
2.) Jede ComboBox hat als Item0 eine Art WildCard (sprich die Combo wird ignoriert indem das Element im SQL String nicht eingefügt wird ). Das Funktioniert jedoch nur sollangeg man die Combos in richtiger Reihenfolge aktiviert(Indexwerte: 1234 z.B.). In der MySQL Db beginnen die Einträge mit Index == 1 ). Somit liefert eine Abfrage mit ComboItem==0 nichts zurück! Wie könnte man dies lösen?
Code: Alles auswählen
// Combos abfragen und Query erstellen und DB abfragen
if (comboBox_printEpTerm->currentIndex() == 0 && comboBox_PrintGender->currentIndex() == 0 && comboBox_printEpSf->currentIndex() == 0 && comboBox_printEpStatus->currentIndex() == 0)
{
myQuery.exec("SELECT * FROM `tx_submission_data` "+ sorting +" ");
}
else
{
for( int z = 1; z < comboBox_printEpTerm->count(); z++)
{
QString epTerm;
epTerm.setNum(z);
if (comboBox_printEpTerm->currentIndex() == z && comboBox_PrintGender->currentIndex() == 0 && comboBox_printEpSf->currentIndex() == 0 && comboBox_printEpStatus->currentIndex() == 0)
{
myQuery.exec("SELECT * FROM `tx_submission_data` WHERE `ep_date` = CONVERT( _utf8 '"+ epTerm +"' USING latin1 ) COLLATE latin1_general_ci "+ sorting +"");
qDebug() << ("SELECT * FROM `tx_submission_data` WHERE `ep_date` = CONVERT( _utf8 '"+ epTerm +"' USING latin1 ) COLLATE latin1_general_ci "+ sorting +"");
}
else
{
for( int y = 1; y < comboBox_PrintGender->count(); y++)
{
if (comboBox_printEpTerm->currentIndex() == z && comboBox_PrintGender->currentIndex() == y && comboBox_printEpSf->currentIndex() == 0 && comboBox_printEpStatus->currentIndex() == 0)
{
myQuery.exec("SELECT * FROM `tx_submission_data` WHERE `gender` = CONVERT( _utf8 '"+ comboBox_PrintGender->currentText() +"' USING latin1 ) COLLATE latin1_general_ci AND `ep_date` = CONVERT( _utf8 '"+ comboBox_printEpTerm->currentText() +"' USING latin1 ) COLLATE latin1_general_ci "+ sorting +"");
qDebug() << ("SELECT * FROM `tx_submission_data` WHERE `gender` = CONVERT( _utf8 '"+ comboBox_PrintGender->currentText() +"' USING latin1 ) COLLATE latin1_general_ci AND `ep_date` = CONVERT( _utf8 '"+ comboBox_printEpTerm->currentText() +"' USING latin1 ) COLLATE latin1_general_ci "+ sorting +"");
}
else
{
for( int x = 1; x < comboBox_printEpSf->count(); x++)
{
QString sf;
sf.setNum(x);
if (comboBox_printEpTerm->currentIndex() == z && comboBox_PrintGender->currentIndex() == y && comboBox_printEpSf->currentIndex() == x && comboBox_printEpStatus->currentIndex() == 0)
{
myQuery.exec("SELECT * FROM `tx_submission_data` WHERE `gender` = CONVERT( _utf8 '"+ comboBox_PrintGender->currentText() +"' USING latin1 ) COLLATE latin1_general_ci AND `ep_date` = CONVERT( _utf8 '"+ comboBox_printEpTerm->currentText() +"' USING latin1 ) COLLATE latin1_general_ci AND `sf`="+ sf + " " + sorting +" ");
qDebug() << ("SELECT * FROM `tx_submission_data` WHERE `gender` = CONVERT( _utf8 '"+ comboBox_PrintGender->currentText() +"' USING latin1 ) COLLATE latin1_general_ci AND `ep_date` = CONVERT( _utf8 '"+ comboBox_printEpTerm->currentText() +"' USING latin1 ) COLLATE latin1_general_ci AND `sf`="+ sf + " " + sorting +" ");
}
else
{
for( int w = 1; w < comboBox_printEpStatus->count(); w++)
{
if (comboBox_printEpTerm->currentIndex() == z && comboBox_PrintGender->currentIndex() == y && comboBox_printEpSf->currentIndex() == x && comboBox_printEpStatus->currentIndex() == w)
{
QString status;
status.setNum(w);
myQuery.exec("SELECT * FROM `tx_submission_data` WHERE `gender` = CONVERT( _utf8 '"+ comboBox_PrintGender->currentText() +"' USING latin1 ) COLLATE latin1_general_ci AND `ep_date` = CONVERT( _utf8 '"+ comboBox_printEpTerm->currentText() +"' USING latin1 ) COLLATE latin1_general_ci AND `sf`="+ sf +" AND `status`="+ status + " " + sorting +"");
qDebug() << ("SELECT * FROM `tx_submission_data` WHERE `gender` = CONVERT( _utf8 '"+ comboBox_PrintGender->currentText() +"' USING latin1 ) COLLATE latin1_general_ci AND `ep_date` = CONVERT( _utf8 '"+ comboBox_printEpTerm->currentText() +"' USING latin1 ) COLLATE latin1_general_ci AND `sf`="+ sf +" AND `status`="+ status + " " + sorting +"");
}
}
}
}
}
}
}
}
}