~ubuntu-branches/debian/sid/unixodbc-gui-qt/sid

1 by Steve Langasek
Import upstream version 2.3.0
1
/*********************************************************************
2
 *
3
 * Written by Nick Gorham
4
 * (nick@lurcher.org).
5
 *
6
 * copyright (c) 1999 Nick Gorham
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21
 *
22
 **********************************************************************
23
 *
24
 * 2008-12-10   Code adopted by unixODBC-GUI-Qt project. Heavily altered
25
 * pharvey      to be Qt4 only code.
26
 * 
27
 **********************************************************************/
28
29
#include "DlgEnvAllocHandle.h"
30
#include "OdbcTest.h"
31
32
void DlgEnvAllocHandle::slotDone()
33
{
34
	SQLHANDLE 	out_handle, in_handle = SQL_NULL_HANDLE;
35
	SQLRETURN 	ret;
36
	SQLINTEGER 	type;
37
	const char *handle;
38
39
	switch( types->currentIndex() )
40
	{
41
		case 0:
42
			type = SQL_HANDLE_ENV;
43
			handle = "SQL_HANDLE_ENV=1";
44
			break;
45
46
		case 1:
47
			type = SQL_HANDLE_DBC;
48
			handle = "SQL_HANDLE_DBC=2";
49
			break;
50
51
		case 2:
52
			type = SQL_HANDLE_STMT;
53
			handle = "SQL_HANDLE_STMT=3";
54
			break;
55
56
		case 3:
57
			type = SQL_HANDLE_DESC;
58
			handle = "SQL_HANDLE_DESC=4";
59
			break;
60
	}
61
62
	/*
63
	 * get input handle
64
	 */
65
66
    OdbcHandle *hand = pOdbcTest->extract_handle_list( -1, handles );
67
68
	if ( hand )
69
		in_handle = hand->getHandle();
70
71
	/*
72
	 * set output handle to something
73
	 */
74
	out_handle = 0;
75
76
	if ( valid->isChecked() )
77
		ret = SQLAllocHandle( type, in_handle, SQL_NULL_HANDLE );
78
	else
79
		ret = SQLAllocHandle( type, in_handle, &out_handle );
80
81
	pOdbcTest->out_win->append( "SQLAllocHandle():" );
82
	pOdbcTest->out_win->append( "  In:" );
83
	txt.sprintf( "    Handle Type: %s", handle );
84
	pOdbcTest->out_win->append( txt );
85
	if ( in_handle )
86
	    txt.sprintf( "    InputHandle: %p", in_handle );
87
	else
88
	    txt.sprintf( "    InputHandle: SQL_NULL_HANDLE" );
89
	pOdbcTest->out_win->append( txt );
90
	if ( valid->isChecked() )
91
		txt.sprintf( "    OutputHandle: SQL_NULL_HANDLE" );
92
	else
93
		txt.sprintf( "    OutputHandle: %p", &out_handle );
94
	pOdbcTest->out_win->append( txt );
95
96
	pOdbcTest->out_win->append( "  Return:" );
97
	txt.sprintf( "    %s=%d", pOdbcTest->return_as_text( ret ), ret );
98
	pOdbcTest->out_win->append( txt );
99
100
	pOdbcTest->out_win->append( "  Out:" );
101
	if ( out_handle )
102
		txt.sprintf( "    *OutputHandle: %p", out_handle );
103
	else
104
		txt.sprintf( "    *OutputHandle: <unmodified>" );
105
	pOdbcTest->out_win->append( txt );
106
	pOdbcTest->out_win->append( "" );
107
108
	if ( SQL_SUCCEEDED( ret ))
109
	{
110
	    pOdbcTest->listHandle.append( new OdbcHandle( type, out_handle, pOdbcTest->listHandle ));
111
	}
112
113
	accept();
114
}
115
116
void DlgEnvAllocHandle::out_handle_ptr_clkd()
117
{
118
	if ( valid->isChecked() )
119
	    valid->setText( "OutputHandlePtr: SQL_NULL_HANDLE" );
120
	else
121
	    valid->setText( "OutputHandlePtr: VALID" );
122
}
123
124
DlgEnvAllocHandle::DlgEnvAllocHandle( OdbcTest *pOdbcTest, QString name )
125
        : QDialog( pOdbcTest )
126
{
127
	setWindowTitle( name );
128
129
	this->pOdbcTest = pOdbcTest;
130
131
	QVBoxLayout *playoutTop = new QVBoxLayout( this );
132
	QGridLayout *pLayout 	= new QGridLayout;
133
134
	playoutTop->addLayout( pLayout );
135
136
	l_handle = new QLabel( "InputHandle:", this );
137
	handles = new QComboBox( this );
138
	pOdbcTest->fill_handle_list( -1, handles );
139
	pLayout->addWidget( l_handle, 0, 0 );
140
	pLayout->addWidget( handles, 0, 1 );
141
142
	l_types = new QLabel( "HandleType:", this );
143
	types = new QComboBox( this );
144
	types->insertItem( 0, "SQL_HANDLE_ENV=1 (3.0)" );
145
	types->insertItem( 1, "SQL_HANDLE_DBC=2 (3.0)" );
146
	types->insertItem( 2, "SQL_HANDLE_STMT=3 (3.0)" );
147
	types->insertItem( 3, "SQL_HANDLE_DESC=3 (3.0)" );
148
	pLayout->addWidget( l_types, 1, 0 );
149
	pLayout->addWidget( types, 1, 1 );
150
151
	valid = new QCheckBox( "OutputHandlePtr: VALID", this );
152
	pLayout->addWidget( valid, 2, 1 );
153
154
	pDialogButtonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help, Qt::Horizontal, this );
155
	playoutTop->addWidget( pDialogButtonBox );
156
157
	connect( valid, SIGNAL( clicked()), this, SLOT( out_handle_ptr_clkd()));
158
	connect( pDialogButtonBox, SIGNAL(accepted()), this, SLOT(slotDone()) );
159
	connect( pDialogButtonBox, SIGNAL(rejected()), this, SLOT(reject()) );
160
//	connect( pDialogButtonBox, SIGNAL(helpRequested()), this, SLOT(slotHelp()) );
161
}
162
163
DlgEnvAllocHandle::~DlgEnvAllocHandle()
164
{
165
	delete types;
166
	delete handles;
167
	delete l_handle;
168
	delete l_types;
169
	delete valid;
170
}
171
172