Le mercredi 16 septembre 2009 à 09:53:26, Magnus Hagander a écrit :
> On Wed, Sep 16, 2009 at 07:09, Guillaume Lelarge <[email protected]>
wrote:
> > 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
> >> > <[email protected]>
> >>[...]
> >> > 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.
>
> Quick comment:
> The logic around getting the max length is wrong. If the query to get
> it fails, the value of maxlength will be unspecified (the else
> statement only comes in effect if the version is <8.4). How about just
> initializing it to 1024 at the start of the function? Also, the
> "delete set" should be inside the check for NULL value - with a NULL
> returned you'll attempt to delete NULL.
>
/me ashamed.
This is fixed.
> >> Should we bother copying at all if it's short?
> >
> > Don't understand this one ?!?!
>
> I mean if it's cut off, should we actually start a query tool with it,
> or should we just say "hey, this has been truncated" and *not* start
> the query tool.
>
I think we should start it anyway because there is a chance that the query is
complete.
> >> 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.
>
> We don't, but it's pretty likely. So change it to "it may have been
> truncated"? :-)
>
Done.
See the new version of this patch.
--
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,63 @@
}
+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
+ maxlength = 1024;
+ 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;
+ }
+ }
+
+ if (text.Length() == maxlength)
+ wxLogError(wxT("The query you copied is at the maximum length.")
+ wxT("It may have been truncated.")
+ 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 +1083,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 +2345,7 @@
btnRotateLog->Enable(false);
editMenu->Enable(MNU_COPY, statusList->GetFirstSelected()>=0);
+ toolBar->EnableTool(MNU_COPY_QUERY, statusList->GetFirstSelected()>=0);
}
@@ -2319,6 +2380,7 @@
btnRotateLog->Enable(false);
editMenu->Enable(MNU_COPY, lockList->GetFirstSelected()>=0);
+ toolBar->EnableTool(MNU_COPY_QUERY, false);
}
@@ -2349,6 +2411,7 @@
btnRotateLog->Enable(false);
editMenu->Enable(MNU_COPY, xactList->GetFirstSelected()>=0);
+ toolBar->EnableTool(MNU_COPY_QUERY, false);
}
@@ -2376,6 +2439,7 @@
}
editMenu->Enable(MNU_COPY, logList->GetFirstSelected()>=0);
+ toolBar->EnableTool(MNU_COPY_QUERY, false);
}
--
Sent via pgadmin-support mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-support