1
//////////////////////////////////////////////////////////////////////////
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
8
// ctlResultGrid.cpp - debugger
10
//////////////////////////////////////////////////////////////////////////
18
#include "debugger/ctlResultGrid.h"
20
IMPLEMENT_CLASS( ctlResultGrid, wxGrid )
22
////////////////////////////////////////////////////////////////////////////////
23
// ctlResultGrid constructor
25
// We use a ctlResultGrid to display the result set from a query. This class
26
// is a minor extension of the wxGrid class.
28
ctlResultGrid::ctlResultGrid( wxWindow * parent, wxWindowID id )
29
: wxGrid( parent, id )
31
wxWindowBase::SetFont(settings->GetSystemFont());
36
////////////////////////////////////////////////////////////////////////////////
39
// Given a result set handle, this function copies the values in that result
42
void ctlResultGrid::fillGrid( PGresult * result )
44
int rowCount = PQntuples( result );
45
int colCount = PQnfields( result );
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
54
// Disable repaints to we don't flicker too much
58
// Clear out the old results (if any) and resize
59
// grid to match the result set
62
DeleteRows( 0, GetNumberRows());
64
DeleteCols( 0, GetNumberCols());
66
AppendRows( rowCount );
67
AppendCols( colCount );
69
EnableEditing( false );
71
// Copy the column names from the result set into the column headers
73
for( int col = 0; col < colCount; ++col )
74
SetColLabelValue( col, wxString( PQfname( result, col ), wxConvUTF8 ));
76
// Now copy each value from the result set into the grid
78
for( int row = 0; row < rowCount; ++row )
80
for( int col = 0; col < colCount; ++col )
82
if( PQgetisnull( result, row, col ))
83
SetCellValue( row, col, wxT( "" ));
85
SetCellValue( row, col, wxString( PQgetvalue( result, row, col ), wxConvUTF8 ));
89
// Resize each column to fit its content
91
AutoSizeColumns( false );