Le vendredi 7 août 2009 à 18:12:00, Guillaume Lelarge a écrit : > Le vendredi 7 août 2009 à 17:58:54, Magnus Hagander a écrit : > > On Fri, Aug 7, 2009 at 17:09, Guillaume Lelarge<guilla...@lelarge.info> > > wrote: > > > Le vendredi 7 août 2009 à 09:56:34, Rainer Bauer a écrit : > > >> Hello, > > >> > > >> this is no bug, but a little bit annoying: I sometimes accidently hit > > >> the tab "Graphical Query Builder" in the Query window. No big deal, I > > >> just click on "SQL Editor" to get back, but then a dialog pops up: "No > > >> SQL query was generated.". > > >> > > >> Wouldn't it be possible to suppress that dialog? > > > > > > I looked a bit at this. We could at least avoid the dialog when no > > > tables are put on the graphical query builder. I suppose it means we > > > need to change the definition of gqbController::generateSQL() method. > > > There's good chance it will be seen as a "new feature", rather than a > > > debug. > > > > > > I'll record a ticket for this. > > > > While not a critical one, I'd qualify this as a bug. It seems like > > quite useless behaviour :-) > > OK, I've changed the ticket.
Here is a patch that should fix this. Magnus, care to check it? I'm not ready to commit it without proper review. It plays with pointers, and that scares me a bit :) -- Guillaume. http://www.postgresqlfr.org http://dalibo.com
Index: pgadmin/include/gqb/gqbViewController.h =================================================================== --- pgadmin/include/gqb/gqbViewController.h (révision 8008) +++ pgadmin/include/gqb/gqbViewController.h (copie de travail) @@ -77,7 +77,7 @@ gqbView* getView(){return view;}; void nullView() {view=NULL;}; gqbObject* getModelSelected(wxPoint &pt, gqbQueryObject *lastSelected, gqbQueryJoin *lastJoinSelected, bool mark); - wxString generateSQL(); + bool generateSQL(wxString* query); wxSplitterWindow* getViewContainer(){return gqbMainContainer;}; wxSplitterWindow* getDialogParent(){return (wxSplitterWindow*) gqbContainer;}; void setSashVertPosition(int pos); Index: pgadmin/frm/frmQuery.cpp =================================================================== --- pgadmin/frm/frmQuery.cpp (révision 8008) +++ pgadmin/frm/frmQuery.cpp (copie de travail) @@ -1809,12 +1809,14 @@ // Execute Generation of SQL sentence from GQB bool canGenerate=false; - wxString newQuery = controller->generateSQL(); + wxString newQuery; + bool tablesInGQB= controller->generateSQL(&newQuery); // If the new query is empty, don't do anything if (newQuery.IsEmpty()) { - wxMessageBox(_("No SQL query was generated."), wxT("Graphical Query Builder"), wxICON_INFORMATION); + if (tablesInGQB) // no query but tables on graphical query builder + wxMessageBox(_("No SQL query was generated."), wxT("Graphical Query Builder"), wxICON_INFORMATION); gqbUpdateRunning = false; return false; } Index: pgadmin/gqb/gqbController.cpp =================================================================== --- pgadmin/gqb/gqbController.cpp (révision 8008) +++ pgadmin/gqb/gqbController.cpp (copie de travail) @@ -243,12 +243,11 @@ // GQB-TODO: Create a less complex & simpler generation function // Generate the SQL Sentence from the model -wxString gqbController::generateSQL() +bool gqbController::generateSQL(wxString* query) { - wxString sentence=wxT(""); if(model->tablesCount()>0) { - sentence+=wxT("SELECT \n"); + *query=wxT("SELECT \n"); // Add selected columns for Query gqbQueryObject *sel=NULL; @@ -269,7 +268,7 @@ { if(((gqbQueryObject*)tables->Item(i))->getAlias().length()>0) { - sentence += wxT(" ") + + *query += wxT(" ") + qtIdent(((gqbQueryObject*)tables->Item(i))->getAlias()) + wxT(".") + qtIdent(((gqbColumn*)cols->Item(i))->getName()) + @@ -279,7 +278,7 @@ } else { - sentence += wxT(" ") + + *query += wxT(" ") + qtIdent(((gqbQueryObject*)tables->Item(i))->getName()) + wxT(".") + qtIdent(((gqbColumn*)cols->Item(i))->getName()) + @@ -292,7 +291,7 @@ { if(((gqbQueryObject*)tables->Item(i))->getAlias().length()>0) { - sentence += wxT(" ") + + *query += wxT(" ") + qtIdent(((gqbQueryObject*)tables->Item(i))->getAlias()) + wxT(".") + qtIdent(((gqbColumn*)cols->Item(i))->getName()) + @@ -300,7 +299,7 @@ } else { - sentence += wxT(" ") + + *query += wxT(" ") + qtIdent(((gqbQueryObject*)tables->Item(i))->getName()) + wxT(".") + qtIdent(((gqbColumn*)cols->Item(i))->getName()) + @@ -310,15 +309,15 @@ } if(!size) - sentence+=wxT(" * \n"); + *query+=wxT(" * \n"); else { // remove last ", " - sentence.Truncate(sentence.Length()-3); - sentence+=wxT("\n"); + query->Truncate(query->Length()-3); + *query+=wxT("\n"); } - sentence+=wxT("FROM \n"); + *query+=wxT("FROM \n"); iteratorModel=model->createQueryIterator(); while(iteratorModel->HasNext()) @@ -327,7 +326,7 @@ gqbSchema *schema = (gqbSchema *)sel->parent->getOwner(); if(sel->getAlias().length()>0) { - sentence += wxT(" ") + + *query += wxT(" ") + qtIdent(schema->getName()) + wxT(".") + qtIdent(sel->getName()) + @@ -337,7 +336,7 @@ } else { - sentence += wxT(" ") + + *query += wxT(" ") + qtIdent(schema->getName()) + wxT(".") + qtIdent(sel->getName()) + @@ -345,7 +344,7 @@ } } - sentence.Truncate(sentence.Length()-3); // remove last ", " + query->Truncate(query->Length()-3); // remove last ", " // WHERE PART // [Joins] @@ -364,17 +363,17 @@ if(first) { first=false; - sentence+= wxT("\nWHERE \n"); + *query+= wxT("\nWHERE \n"); } tmp = (gqbQueryJoin *)iteratorJoins->Next(); if(tmp->getSourceQTable()->getAlias().length()>0) - sentence+= wxT(" ") + + *query+= wxT(" ") + qtIdent(tmp->getSourceQTable()->getAlias()) + wxT(".") + qtIdent(tmp->getSourceCol()); else - sentence+= wxT(" ") + + *query+= wxT(" ") + qtIdent(tmp->getSourceQTable()->getName()) + wxT(".") + qtIdent(tmp->getSourceCol()); @@ -382,30 +381,30 @@ switch(tmp->getKindofJoin()) { case _equally: - sentence+= wxT(" = "); + *query+= wxT(" = "); break; case _greater: - sentence+= wxT(" > "); + *query+= wxT(" > "); break; case _lesser: - sentence+= wxT(" < "); + *query+= wxT(" < "); break; case _equgreater: - sentence+= wxT(" >= "); + *query+= wxT(" >= "); break; case _equlesser: - sentence+= wxT(" <= "); + *query+= wxT(" <= "); break; } if(tmp->getDestQTable()->getAlias().length()>0) - sentence += qtIdent(tmp->getDestQTable()->getAlias()) + + *query += qtIdent(tmp->getDestQTable()->getAlias()) + wxT(".") + qtIdent(tmp->getDestCol()) + wxT(" AND\n"); else - sentence += qtIdent(tmp->getDestQTable()->getName()) + + *query += qtIdent(tmp->getDestQTable()->getName()) + wxT(".") + qtIdent(tmp->getDestCol()) + wxT(" AND\n"); @@ -419,11 +418,11 @@ // Remove last " AND " from joins if there isn't restrictions, only left white space if(truncAnd && (restrictions->restrictionsCount()<=0)) - sentence.Truncate(sentence.Length()-5); + query->Truncate(query->Length()-5); // Never found a join if (!truncAnd && (restrictions->restrictionsCount()>0)) - sentence+= wxT("\nWHERE \n"); + *query+= wxT("\nWHERE \n"); //GQB-TODO: VALIDATE RESTRICTIONS iteratorRestrictions=restrictions->createRestrictionsIterator(); @@ -432,7 +431,7 @@ while(iteratorRestrictions->HasNext()) { r=(gqbQueryRestriction *)iteratorRestrictions->Next(); - sentence += wxT(" ") + + *query += wxT(" ") + r->getLeft() + wxT(" ") + r->getRestriction() + @@ -448,11 +447,11 @@ { if(r->getConnector().Contains(wxT("AND"))) { - sentence.Truncate(sentence.Length()-6); + query->Truncate(query->Length()-6); } else { - sentence.Truncate(sentence.Length()-5); + query->Truncate(query->Length()-5); } } // ORDER BY PART @@ -463,7 +462,7 @@ size=orderByColumns->GetCount(); if(size>0) { - sentence+=wxT("\nORDER BY\n"); + *query+=wxT("\nORDER BY\n"); } wxString typeOrder=wxT(""); for(i=0;i<size;i++) @@ -478,14 +477,14 @@ break; }; if(((gqbQueryObject*)orderByParents->Item(i))->getAlias().length()>0) - sentence += wxT(" ") + + *query += wxT(" ") + qtIdent(((gqbQueryObject*)orderByParents->Item(i))->getAlias()) + wxT(".") + qtIdent(((gqbColumn*)orderByColumns->Item(i))->getName()) + typeOrder + wxT(", \n"); else - sentence += wxT(" ") + + *query += wxT(" ") + qtIdent(((gqbQueryObject*)orderByParents->Item(i))->getName()) + wxT(".") + qtIdent(((gqbColumn*)orderByColumns->Item(i))->getName()) + @@ -494,11 +493,11 @@ } if(size>0) - sentence.Truncate(sentence.Length()-3); + query->Truncate(query->Length()-3); - sentence+=wxT(";"); + *query+=wxT(";"); } // Close Tables Count > 0 on model - return sentence; + return model->tablesCount()>0; }
-- Sent via pgadmin-support mailing list (pgadmin-support@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgadmin-support