~ubuntu-branches/debian/squeeze/pgadmin3/squeeze

« back to all changes in this revision

Viewing changes to pgadmin/debugger/ctlResultGrid.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Lionel Porcheron
  • Date: 2008-02-07 00:56:22 UTC
  • mto: (2.1.6 hardy) (6.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20080207005622-c2ail8p4d0sk3dnw
Tags: upstream-1.8.2
ImportĀ upstreamĀ versionĀ 1.8.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//////////////////////////////////////////////////////////////////////////
 
2
//
 
3
// pgAdmin III - PostgreSQL Tools
 
4
// RCS-ID:      $Id: ctlResultGrid.cpp 6200 2007-04-18 10:00:20Z dpage $
 
5
// Copyright (C) 2002 - 2008, The pgAdmin Development Team
 
6
// This software is released under the Artistic Licence
 
7
//
 
8
// ctlResultGrid.cpp - debugger 
 
9
//
 
10
//////////////////////////////////////////////////////////////////////////
 
11
 
 
12
#include "pgAdmin3.h"
 
13
 
 
14
// wxWindows headers
 
15
#include <wx/wx.h>
 
16
 
 
17
// App headers
 
18
#include "debugger/ctlResultGrid.h"
 
19
 
 
20
IMPLEMENT_CLASS( ctlResultGrid, wxGrid )
 
21
 
 
22
////////////////////////////////////////////////////////////////////////////////
 
23
// ctlResultGrid constructor
 
24
//
 
25
//    We use a ctlResultGrid to display the result set from a query.  This class 
 
26
//  is a minor extension of the wxGrid class.
 
27
 
 
28
ctlResultGrid::ctlResultGrid( wxWindow * parent, wxWindowID id )
 
29
    : wxGrid( parent, id )
 
30
{
 
31
    wxWindowBase::SetFont(settings->GetSystemFont());
 
32
 
 
33
    CreateGrid( 0, 0 );
 
34
}
 
35
 
 
36
////////////////////////////////////////////////////////////////////////////////
 
37
// fillGrid()
 
38
//
 
39
//    Given a result set handle, this function copies the values in that result 
 
40
//  set into the grid.
 
41
 
 
42
void ctlResultGrid::fillGrid( PGresult * result )
 
43
{
 
44
    int    rowCount = PQntuples( result );
 
45
    int    colCount = PQnfields( result );
 
46
 
 
47
    // If this PGresult represents a non-query command 
 
48
    // (like an INSERT), there won't be any columns in 
 
49
    // the result set - just return
 
50
 
 
51
    if( colCount == 0 )
 
52
        return;
 
53
 
 
54
    // Disable repaints to we don't flicker too much
 
55
 
 
56
    BeginBatch();
 
57
 
 
58
    // Clear out the old results (if any) and resize 
 
59
    // grid to match the result set
 
60
 
 
61
    if( GetNumberRows())
 
62
        DeleteRows( 0, GetNumberRows());
 
63
    if( GetNumberCols())
 
64
        DeleteCols( 0, GetNumberCols());
 
65
 
 
66
    AppendRows( rowCount );
 
67
    AppendCols( colCount );
 
68
 
 
69
    EnableEditing( false );
 
70
 
 
71
    // Copy the column names from the result set into the column headers
 
72
 
 
73
    for( int col = 0; col < colCount; ++col )
 
74
        SetColLabelValue( col, wxString( PQfname( result, col ), wxConvUTF8 ));
 
75
 
 
76
    // Now copy each value from the result set into the grid
 
77
 
 
78
    for( int row = 0; row < rowCount; ++row )
 
79
    {
 
80
        for( int col = 0; col < colCount; ++col )
 
81
        {
 
82
            if( PQgetisnull( result, row, col ))
 
83
                SetCellValue( row, col, wxT( "" ));
 
84
            else
 
85
                SetCellValue( row, col, wxString( PQgetvalue( result, row, col ), wxConvUTF8 ));
 
86
        }
 
87
    }
 
88
 
 
89
    // Resize each column to fit its content
 
90
 
 
91
    AutoSizeColumns( false );
 
92
 
 
93
    // Enable repaints
 
94
 
 
95
    EndBatch();
 
96
}