Le mardi 15 septembre 2009 à 18:47:24, Guillaume Lelarge a écrit : > Le mardi 15 septembre 2009 à 09:57:55, Magnus Hagander a écrit : > > On Tue, Sep 15, 2009 at 07:34, Guillaume Lelarge <guilla...@lelarge.info> > > wrote: > > > Le mardi 15 septembre 2009 à 06:54:59, Magnus Hagander a écrit : > > >> On 15 sep 2009, at 00.48, Guillaume Lelarge <guilla...@lelarge.info> > > >> > > >> wrote: > > >> > Le samedi 12 septembre 2009 à 14:49:04, Guillaume Lelarge a écrit : > > >> >> Le mercredi 9 septembre 2009 à 20:46:00, Roger Niederland a écrit : > > >> >>> First of all thanks for PGAdmin I've been using it for years now. > > >> >>> > > >> >> :) > > >> >>> > > >> >>> One small enhancement that would be very useful is: > > >> >>> > > >> >>> When viewing the Statistics tab for the server where the Current > > >> >>> Executing Queries is available (along with the current user, > > >> >>> database > > >> >>> etc..) It would be good to be able to copy the sql of a current > > >> >>> query. > > >> >>> I realize that it is impractical to show the full query sql (and > > >> >>> do not > > >> >>> want this). But I would like to be able to copy the "full sql" of > > >> >>> the > > >> >>> current query. I know that I can log long running queries, but > > >> >>> feel it > > >> >>> would be useful to copy the query from the statistics, so I can > > >> >>> paste it > > >> >>> into a query window for further analysis. > > >> >> > > >> >> It's already possible in 1.10, but it copies the whole line (not > > >> >> only the > > >> >> query). Anyways, that's one item on my todolist. We also want to be > > >> >> able to > > >> >> launch the query tool with this query (see > > >> >> http://code.pgadmin.org/trac/ticket/9). I hope all of these will be > > >> >> in > > >> >> 1.12. > > >> > > > >> > Here is a patch to lauch the query tool with the selected query. The > > >> > icon is > > >> > the copy one. Not great, but I don't really have design skills. I > > >> > wonder if we > > >> > can make the query tool icon smaller enough, so that it will fit in > > >> > the > > >> > toolbar. Anyways, with this patch, when you click on the toolbar > > >> > button, the > > >> > query tool opens a new connection on the selected database of the > > >> > same server, > > >> > displays the query and allows the user to modify/execute it. > > >> > > > >> > Comments? > > >> > > >> For long queries the whole string won't be available. Maybe we should > > >> try to detect that and issue an error? > > > > > > Yeah, sure. This new version checks if the query size is at max size > > > and displays a message if it is. The contents of the message probably > > > need some work. > > > > Should we bother copying at all if it's short? > > Don't understand this one ?!?! > > > If we keep that, how about: > > "The query is longer than the maximum length, and has been truncated. " > > Well, we don't really know if it has been truncated. All we know is that > the query is at the maximum length. >
New version of the patch: * Previously, only the first 250 characters of the query were displayed. * We won't launch the query tool if the selected process is in <IDLE> or <IDLE in transaction> state. -- Guillaume. http://www.postgresqlfr.org http://dalibo.com
Index: pgadmin/include/frm/frmStatus.h =================================================================== --- pgadmin/include/frm/frmStatus.h (révision 8034) +++ pgadmin/include/frm/frmStatus.h (copie de travail) @@ -47,6 +47,7 @@ MNU_TERMINATE, MNU_COMMIT, MNU_ROLLBACK, + MNU_COPY_QUERY, TIMER_REFRESHUI_ID, TIMER_STATUS_ID, TIMER_LOCKS_ID, @@ -138,6 +139,7 @@ void OnExit(wxCommandEvent& event); void OnCopy(wxCommandEvent& ev); + void OnCopyQuery(wxCommandEvent& ev); void OnToggleStatusPane(wxCommandEvent& event); void OnToggleLockPane(wxCommandEvent& event); Index: pgadmin/frm/frmStatus.cpp =================================================================== --- pgadmin/frm/frmStatus.cpp (révision 8034) +++ pgadmin/frm/frmStatus.cpp (copie de travail) @@ -26,6 +26,7 @@ #include "frm/frmStatus.h" #include "frm/frmHint.h" #include "frm/frmMain.h" +#include "frm/frmQuery.h" #include "utils/pgfeatures.h" #include "schema/pgServer.h" #include "ctl/ctlMenuToolbar.h" @@ -44,6 +45,7 @@ EVT_MENU(MNU_EXIT, frmStatus::OnExit) EVT_MENU(MNU_COPY, frmStatus::OnCopy) + EVT_MENU(MNU_COPY_QUERY, frmStatus::OnCopyQuery) EVT_MENU(MNU_HELP, frmStatus::OnHelp) EVT_MENU(MNU_STATUSPAGE, frmStatus::OnToggleStatusPane) @@ -218,6 +220,7 @@ toolBar->AddTool(MNU_REFRESH, _("Refresh"), wxBitmap(readdata_xpm), _("Refresh"), wxITEM_NORMAL); toolBar->AddSeparator(); toolBar->AddTool(MNU_COPY, _("Copy"), wxBitmap(clip_copy_xpm), _("Copy selected text to clipboard"), wxITEM_NORMAL); + toolBar->AddTool(MNU_COPY_QUERY, _("Open query tool"), wxBitmap(clip_copy_xpm), _("Open the query tool with the selected query"), wxITEM_NORMAL); toolBar->AddSeparator(); toolBar->AddTool(MNU_CANCEL, _("Cancel"), wxBitmap(query_cancel_xpm), _("Cancel query"), wxITEM_NORMAL); toolBar->AddTool(MNU_TERMINATE, _("Terminate"), wxBitmap(terminate_backend_xpm), _("Terminate backend"), wxITEM_NORMAL); @@ -702,6 +705,64 @@ } +void frmStatus::OnCopyQuery(wxCommandEvent& ev) +{ + ctlListView *list; + int row, col; + wxString text = wxT(""); + wxString dbname = wxT(""); + int maxlength; + + // Only the status list shows the query + list = statusList; + + // Get the database + row = list->GetFirstSelected(); + col = 1; + dbname.Append(list->GetText(row, col)); + + // Get the actual query + row = list->GetFirstSelected(); + col = list->GetColumnCount() - 1; + text.Append(list->GetText(row, col) + wxT("\t")); + + // Check if we have a query whose length is maximum + if (connection->BackendMinimumVersion(8, 4)) + { + pgSet *set; + set=connection->ExecuteSet(wxT("SELECT setting FROM pg_settings\n") + wxT(" WHERE name='track_activity_query_size'")); + if (set) + { + maxlength = set->GetLong(0); + } + delete set; + } + else + maxlength = 1024; + + if (text.Length() == maxlength) + wxLogError(wxT("The query you copied is at the maximum length.") + wxT("This means it's probably not complete.") + wxT("You should check this before running the query.")); + + // If we have some real query, launch the query tool + if (text.Length() > 0 && dbname.Length() > 0 + && text.Trim() != wxT("<IDLE>") && text.Trim() != wxT("<IDLE in transaction>")) + { + //pgDatabase *db=obj->GetDatabase(); + pgConn *conn = new pgConn(connection->GetHostAddress(), dbname, + connection->GetUser(), connection->GetPassword(), + connection->GetPort(), connection->GetSslMode(), connection->GetDbOid()); + if (conn) + { + frmQuery *fq = new frmQuery(mainForm, wxEmptyString, conn, text); + fq->Go(); + } + } +} + + void frmStatus::OnPaneClose(wxAuiManagerEvent& evt) { if (evt.pane->name == wxT("Activity")) @@ -1023,7 +1084,7 @@ statusList->SetItem(row, colpos++, dataSet1->GetVal(wxT("xact_start"))); statusList->SetItem(row, colpos++, dataSet1->GetVal(wxT("blockedby"))); - statusList->SetItem(row, colpos, qry.Left(250)); + statusList->SetItem(row, colpos, qry); row++; } dataSet1->MoveNext(); @@ -2285,6 +2346,7 @@ btnRotateLog->Enable(false); editMenu->Enable(MNU_COPY, statusList->GetFirstSelected()>=0); + toolBar->EnableTool(MNU_COPY_QUERY, statusList->GetFirstSelected()>=0); } @@ -2319,6 +2381,7 @@ btnRotateLog->Enable(false); editMenu->Enable(MNU_COPY, lockList->GetFirstSelected()>=0); + toolBar->EnableTool(MNU_COPY_QUERY, false); } @@ -2349,6 +2412,7 @@ btnRotateLog->Enable(false); editMenu->Enable(MNU_COPY, xactList->GetFirstSelected()>=0); + toolBar->EnableTool(MNU_COPY_QUERY, false); } @@ -2376,6 +2440,7 @@ } editMenu->Enable(MNU_COPY, logList->GetFirstSelected()>=0); + toolBar->EnableTool(MNU_COPY_QUERY, false); }
-- Sent via pgadmin-support mailing list (pgadmin-support@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgadmin-support