Quoting Andreas Pflug <[EMAIL PROTECTED]>:

An improvement that ignores basics is useless.

That's what we've been trying to tell you...

Anyway, here's a patch that fixes what Andreas broke.

Ed

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.

Index: ctl/ctlSQLResult.cpp
===================================================================
--- ctl/ctlSQLResult.cpp	(revision 5099)
+++ ctl/ctlSQLResult.cpp	(working copy)
@@ -21,22 +21,16 @@
 
 
 ctlSQLResult::ctlSQLResult(wxWindow *parent, pgConn *_conn, wxWindowID id, const wxPoint& pos, const wxSize& size)
-#if USE_LISTVIEW
-: wxListView(parent, id, pos, size, wxLC_VIRTUAL | wxLC_REPORT | wxSUNKEN_BORDER)
-#else
 : ctlSQLGrid(parent, id, pos, size)
-#endif
 {
     conn=_conn;
     thread=0;
 
-#if !USE_LISTVIEW
-    CreateGrid(0, 0);
+    SetTable(new sqlResultTable(), true);
     EnableEditing(false);
     SetSizer(new wxBoxSizer(wxVERTICAL));
 
     Connect(wxID_ANY, wxEVT_GRID_RANGE_SELECT, wxGridRangeSelectEventHandler(ctlSQLResult::OnGridSelect));
-#endif
 }
 
 
@@ -65,57 +59,6 @@
 }
 
 
-#if USE_LISTVIEW
-void ctlSQLResult::SelectAll()
-{
-	for (int i = 0; i < GetItemCount(); i++)
-		Select(i);
-}
-
-
-wxString ctlSQLResult::GetExportLine(int row)
-{
-   if (GetColumnCount() <= 1)
-        return OnGetItemText(row, 1);
-
-    wxString str;
-    int col;
-    for (col=1 ; col < GetColumnCount() ; col++)
-    {
-        if (col > 1)
-            str.Append(settings->GetCopyColSeparator());
-
-        wxString text=OnGetItemText(row, col);
-
-		bool needQuote  = false;
-		if (settings->GetCopyQuoting() == 1)
-		{
-			/* Quote strings only */
-			switch (colTypClasses.Item(col))
-			{
-			case PGTYPCLASS_NUMERIC:
-			case PGTYPCLASS_BOOL:
-				break;
-			default:
-				needQuote=true;
-				break;
-			}
-		}
-		else if (settings->GetCopyQuoting() == 2)
-			/* Quote everything */
-			needQuote = true;
-
-		if (needQuote)
-            str.Append(settings->GetCopyQuoteChar());
-        str.Append(text);
-        if (needQuote)
-            str.Append(settings->GetCopyQuoteChar());
-    }    
-    return str;
-}
-#endif
-
-
 bool ctlSQLResult::IsColText(int col)
 {
 	switch (colTypClasses.Item(col))
@@ -137,20 +80,6 @@
     colHeaders.Empty();
     int i;
 
-#if USE_LISTVIEW
-    wxListItem item;
-    item.SetMask(wxLIST_MASK_TEXT|wxLIST_MASK_WIDTH);
-
-    for (i=0 ; i < GetColumnCount() ; i++)
-    {
-        GetColumn(i, item);
-        colHeaders.Add(item.GetText());
-        colSizes.Add(item.GetWidth());
-    }
-
-    ClearAll();
-
-#else
     for (i=0 ; i < GetNumberCols() ; i++)
     {
         colHeaders.Add(GetColLabelValue(i));
@@ -164,10 +93,7 @@
     num = GetNumberCols();
     if (num)
         DeleteCols(0, num);
-    maxRows = 0;
-#endif
 
-
     colNames.Empty();
     colTypes.Empty();
     colTypClasses.Empty();
@@ -180,6 +106,7 @@
         return -1;
     }
 
+    ((sqlResultTable *)GetTable())->SetThread(thread);
     thread->Run();
     return RunStatus();
 }
@@ -189,6 +116,7 @@
 {
     if (thread)
     {
+        ((sqlResultTable *)GetTable())->SetThread(0);
         thread->Delete();
         delete thread;
     }
@@ -208,8 +136,27 @@
 
 	rowcountSuppressed = single;
     Freeze();
-	SetItemCount(NumRows());
 
+    /*
+     * Resize and repopulate by informing itto delete all the rows and
+     * columns, then append the correct number of them. Probably is a
+     * better way to do this.
+     */
+    wxGridTableMessage *msg;
+    sqlResultTable *table = (sqlResultTable *)GetTable();
+    msg = new wxGridTableMessage(table, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0, GetNumberRows());
+    ProcessTableMessage(*msg);
+    delete msg;
+    msg = new wxGridTableMessage(table, wxGRIDTABLE_NOTIFY_COLS_DELETED, 0, GetNumberCols());
+    ProcessTableMessage(*msg);
+    delete msg;
+    msg = new wxGridTableMessage(table, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, NumRows());
+    ProcessTableMessage(*msg);
+    delete msg;
+    msg = new wxGridTableMessage(table, wxGRIDTABLE_NOTIFY_COLS_APPENDED, thread->DataSet()->NumCols());
+    ProcessTableMessage(*msg);
+    delete msg;
+
 	if (single)
     {
         int w, h;
@@ -221,9 +168,6 @@
         colNames.Add(thread->DataSet()->ColName(0));
         colTypes.Add(wxT(""));
         colTypClasses.Add(0L);
-
-
-        InsertColumn(0, thread->DataSet()->ColName(0), wxLIST_FORMAT_LEFT, w);
     }
 	else
     {
@@ -236,7 +180,6 @@
 		if (rowname.Length() > rowcolsize)
 			rowcolsize = rowname.Length();
 
-        InsertColumn(0, rowname, wxLIST_FORMAT_RIGHT, rowcolsize*8);
         colNames.Add(wxT("Row"));
 
         size_t hdrIndex=0;
@@ -265,163 +208,12 @@
                 else
                     w=-1;
             }
-
-            InsertColumn(col+1, colHeader, wxLIST_FORMAT_LEFT, w);
         }
     }
     Thaw();
 }
 
 
-#if !USE_LISTVIEW
-
-int ctlSQLResult::RetrieveOne()
-{
-    if (!thread || !thread->DataValid())
-        return -1;
-
-    if (thread->ReturnCode() != PGRES_TUPLES_OK)
-        return -1;
-
-    if (!rowsRetrieved)
-    {
-        wxString colName, colType;
-        colTypes.Add(wxT(""));
-        colTypClasses.Add(0L);
-
-        Freeze();
-			
-		colName = thread->DataSet()->ColName(0);
-		colType = thread->DataSet()->ColType(0);
-		colNames.Add(colName);
-		colTypes.Add(colType);
-		colTypClasses.Add(thread->DataSet()->ColTypClass(0));
-
-	    wxString colHeader = colName + wxT("\n") + colType;
-			
-        GetTable()->AppendCols(1);
-
-        SetColLabelValue(0, colHeader);
-
-        while (!thread->DataSet()->Eof())
-        {
-            GetTable()->AppendRows(1);
-            GetTable()->SetValue(rowsRetrieved, 0, thread->DataSet()->GetVal(0));
-            rowsRetrieved++;
-            thread->DataSet()->MoveNext();
-        }
-		
-		Thaw();
-		
-        return rowsRetrieved;
-    }
-    return 0;
-}
-
-
-int ctlSQLResult::Retrieve(long chunk)
-{
-    if (!thread || !thread->DataValid())
-        return 0;
-
-    if (chunk<0)
-        chunk=thread->DataSet()->NumRows();
-    wxLogInfo(wxT("retrieve %ld: did %ld of %ld"), chunk, rowsRetrieved, NumRows());
-
-    long col, nCols=thread->DataSet()->NumCols();
-    if (!rowsRetrieved)
-    {
-        wxString colName, colType;
-        colTypes.Add(wxT(""));
-        colTypClasses.Add(0L);
-
-        Freeze();
-        
-        GetTable()->AppendCols(nCols);
-        if (maxRows)
-            GetTable()->AppendRows(maxRows);
-        else
-            GetTable()->AppendRows(NumRows());
-
-        size_t hdrIndex=0;
-
-        for (col=0 ; col < nCols ; col++)
-        {
-            colName = thread->DataSet()->ColName(col);
-            colType = thread->DataSet()->ColType(col);
-            colNames.Add(colName);
-            colTypes.Add(colType);
-            colTypClasses.Add(thread->DataSet()->ColTypClass(col));
-
-            wxString colHeader = colName + wxT("\n") + colType;
-
-            int w;
-            if (hdrIndex < colHeaders.GetCount() && colHeaders.Item(hdrIndex) == colHeader)
-                w = colSizes.Item(hdrIndex++);
-            else
-            {
-                if (hdrIndex+1 < colHeaders.GetCount() && colHeaders.Item(hdrIndex+1) == colHeader)
-                {
-                    hdrIndex++;
-                    w = colSizes.Item(hdrIndex++);
-                }
-                else
-                    w=-1;
-            }
-
-            SetColLabelValue(col, colHeader);
-            SetColSize(col, w);
-        }
-        Thaw();
-    }
-
-    long count=0;
-    long maxColSize=settings->GetMaxColSize();
-
-    while (chunk-- && !thread->DataSet()->Eof())
-    {
-        for (col=0 ; col < nCols ; col++)
-        {
-            wxString value = thread->DataSet()->GetVal(col);
-            if (maxColSize > 0)
-            {
-                if ((int)value.Length() > maxColSize)
-                    value = value.Left(maxColSize) + wxT(" (..)");
-            }
-            GetTable()->SetValue(rowsRetrieved, col, value);
-        }
-        
-        thread->DataSet()->MoveNext();
-        rowsRetrieved++;
-        count++;
-    }
-    wxLogInfo(wxT("retrieve done %ld: did %ld of %ld"), count, rowsRetrieved, NumRows());
-
-    return (count);
-}
-
-
-wxString ctlSQLResult::GetItemText(int row, int col)
-{
-    if (GetNumberCols() == 0)
-	{
-        wxString t;
-        return t;
-    }
-
-    if (col < 0) {
-        if (GetNumberCols() > 1)
-            return GetExportLine(row);
-        else
-            return GetCellValue(row, 0);
-    }
-    else
-        return GetCellValue(row, col);
-}
-
-#endif
-
-
 wxString ctlSQLResult::GetMessagesAndClear()
 {
     if (thread)
@@ -496,20 +288,50 @@
 }
 
 
-#if !USE_LISTVIEW
+void ctlSQLResult::OnGridSelect(wxGridRangeSelectEvent& event)
+{
+    SetFocus();
+}
 
 
-void ctlSQLResult::ResultsFinished()
+wxString sqlResultTable::GetValue(int row, int col)
 {
-    int rows = GetTable()->GetNumberRows();
+    if (thread && thread->DataValid())
+	{
+		if (col >= 0)
+		{
+			thread->DataSet()->Locate(row+1);
+			return thread->DataSet()->GetVal(col);
+		}
+		else
+			return thread->DataSet()->ColName(col);
+	}
+	return wxEmptyString;
+}
 
-    if (rowsRetrieved < rows)
-        GetTable()->DeleteRows(rowsRetrieved, rows - rowsRetrieved);
+sqlResultTable::sqlResultTable()
+{
+    thread = 0;
 }
 
-void ctlSQLResult::OnGridSelect(wxGridRangeSelectEvent& event)
+int sqlResultTable::GetNumberRows()
 {
-    SetFocus();
+    if (thread && thread->DataValid())
+        return thread->DataSet()->NumRows();
+    return 0;
 }
-#endif
 
+
+wxString sqlResultTable::GetColLabelValue(int col)
+{
+    if (thread && thread->DataValid())
+        return thread->DataSet()->ColName(col);
+    return wxEmptyString;
+}
+
+int sqlResultTable::GetNumberCols()
+{
+    if (thread && thread->DataValid())
+        return thread->DataSet()->NumCols();
+    return 0;
+}
Index: frm/frmQuery.cpp
===================================================================
--- frm/frmQuery.cpp	(revision 5099)
+++ frm/frmQuery.cpp	(working copy)
@@ -613,29 +613,6 @@
         msgResult->Copy();
     else if (wnd == msgHistory)
         msgHistory->Copy();
-#if USE_LISTVIEW
-    else if (wnd == sqlResult && sqlResult->GetSelectedItemCount() > 0)
-    {
-        wxString str;
-        int row=-1;
-        while (true)
-        {
-            row = sqlResult->GetNextItem(row, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
-            if (row < 0)
-                break;
-            
-            str.Append(sqlResult->GetExportLine(row));
-            if (sqlResult->GetSelectedItemCount() > 1)
-                str.Append(END_OF_LINE);
-        }
-
-        if (wxTheClipboard->Open())
-        {
-            wxTheClipboard->SetData(new wxTextDataObject(str));
-            wxTheClipboard->Close();
-        }
-    }
-#else
     else 
 	{
         wxWindow *obj = wnd;
@@ -648,7 +625,6 @@
             obj = obj->GetParent();
         }
     }
-#endif
     updateMenu();
 }
 
@@ -1035,7 +1011,7 @@
     rep->StartReportTable();
 
     // Get the column headers
-    int cols = sqlResult->GetItemCount();
+    int cols = sqlResult->GetNumberCols();
 
     wxString row;
 
Index: include/ctl/ctlSQLResult.h
===================================================================
--- include/ctl/ctlSQLResult.h	(revision 5099)
+++ include/ctl/ctlSQLResult.h	(working copy)
@@ -12,29 +12,18 @@
 #ifndef CTLSQLRESULT_H
 #define CTLSQLRESULT_H
 
-#define USE_LISTVIEW 1
-
 // wxWindows headers
 #include <wx/thread.h>
 
 #include "pgSet.h"
 #include "pgConn.h"
-
-#if USE_LISTVIEW
-#include <wx/listctrl.h>
-#else
 #include "ctlSQLGrid.h"
-#endif
 
 
 
 #define CTLSQL_RUNNING 100  // must be greater than ExecStatusType PGRES_xxx values
 
-#if USE_LISTVIEW
-class ctlSQLResult : public wxListView
-#else
 class ctlSQLResult : public ctlSQLGrid
-#endif
 {
 public:
     ctlSQLResult(wxWindow *parent, pgConn *conn, wxWindowID id, const wxPoint& pos=wxDefaultPosition, const wxSize& size=wxDefaultSize);
@@ -63,14 +52,10 @@
 	void DisplayData(bool single=false);
 
 
-#if USE_LISTVIEW
-	void SelectAll();
-	wxString GetExportLine(int row);
-#else
     void SetMaxRows(int rows);
     void ResultsFinished();
     void OnGridSelect(wxGridRangeSelectEvent& event);
-#endif
+
     wxArrayString colNames;
     wxArrayString colTypes;
     wxArrayLong colTypClasses;
@@ -84,4 +69,22 @@
 	bool rowcountSuppressed;
 };
 
+class sqlResultTable : public wxGridTableBase
+{
+public:
+    sqlResultTable();
+    wxString GetValue(int row, int col);
+    int GetNumberRows();
+    int GetNumberCols();
+    bool IsEmptyCell(int row, int col) { return false; }
+    wxString GetColLabelValue(int col);
+    void SetValue(int row, int col, const wxString& value) { return; }
+    void SetThread(pgQueryThread *t) { thread = t; }
+    bool DeleteRows(size_t pos = 0, size_t numRows = 1) { return true; }
+    bool DeleteCols(size_t pos = 0, size_t numCols = 1) { return true; }
+
+private:
+    pgQueryThread *thread;
+};
+
 #endif
---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

               http://archives.postgresql.org

Reply via email to