~ubuntu-branches/ubuntu/trusty/qgis/trusty

« back to all changes in this revision

Viewing changes to src/plugins/evis/databaseconnection/evisdatabaseconnectiongui.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
** File: evisdatabaseconnectiongui.cpp
 
3
** Author: Peter J. Ersts ( ersts at amnh.org )
 
4
** Creation Date: 2007-03-07
 
5
**
 
6
** Copyright ( c ) 2007, American Museum of Natural History. All rights reserved.
 
7
**
 
8
** This library/program is free software; you can redistribute it
 
9
** and/or modify it under the terms of the GNU Library General Public
 
10
** License as published by the Free Software Foundation; either
 
11
** version 2 of the License, or ( at your option ) any later version.
 
12
**
 
13
** This library/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 GNU
 
16
** Library General Public License for more details.
 
17
**
 
18
** This work was made possible through a grant by the the John D. and
 
19
** Catherine T. MacArthur Foundation. Additionally, this program was prepared by
 
20
** the American Museum of Natural History under award No. NA05SEC46391002
 
21
** from the National Oceanic and Atmospheric Administration, U.S. Department
 
22
** of Commerce.  The statements, findings, conclusions, and recommendations
 
23
** are those of the author( s ) and do not necessarily reflect the views of the
 
24
** National Oceanic and Atmospheric Administration or the Department of Commerce.
 
25
**
 
26
**/
 
27
/*  $Id: $ */
 
28
#include "evisdatabaseconnectiongui.h"
 
29
 
 
30
#include "qgscontexthelp.h"
 
31
#include "qgsapplication.h"
 
32
 
 
33
#include <QMessageBox>
 
34
#include <QTextStream>
 
35
#include <QFileDialog>
 
36
#include <QtSql/QSqlQuery>
 
37
#include <QtSql/QSqlError>
 
38
#include <QtSql/QSqlRecord>
 
39
#include <QtXml/QDomDocument>
 
40
#include <QtXml/QDomElement>
 
41
#include <QtXml/QDomNode>
 
42
 
 
43
/**
 
44
* Constructor
 
45
* @param parent - Pointer the to parent QWidget for modality
 
46
* @param fl - Windown flags
 
47
*/
 
48
eVisDatabaseConnectionGui::eVisDatabaseConnectionGui( QList<QTemporaryFile*>* theTemoraryFileList, QWidget* parent, Qt::WFlags fl )
 
49
    : QDialog( parent, fl )
 
50
{
 
51
  setupUi( this );
 
52
 
 
53
  mTempOutputFileList = theTemoraryFileList;
 
54
 
 
55
  //Initialize varaibles
 
56
  mQueryDefinitionMap = new QMap<int, eVisQueryDefinition>;
 
57
  mDatabaseConnection = 0;
 
58
 
 
59
  //Create a new instance of the file selector
 
60
  mDatabaseLayerFieldSelector = new eVisDatabaseLayerFieldSelectionGui( this, fl );
 
61
  connect( mDatabaseLayerFieldSelector, SIGNAL( eVisDatabaseLayerFieldsSelected( QString, QString, QString ) ), this, SLOT( drawNewVectorLayer( QString, QString, QString ) ) );
 
62
 
 
63
  //Populate gui components
 
64
#ifdef WIN32
 
65
  cboxDatabaseType->insertItem( 0, "MSAccess" );
 
66
#endif
 
67
  cboxDatabaseType->insertItem( 0, "MYSQL" );
 
68
  cboxDatabaseType->insertItem( 0, "ODBC" );
 
69
  cboxDatabaseType->insertItem( 0, "PostGreSQL" );
 
70
  cboxDatabaseType->insertItem( 0, "SQLITE" );
 
71
  cboxDatabaseType->insertItem( 0, tr( "Undefined" ) );
 
72
  cboxDatabaseType->setCurrentIndex( 0 );
 
73
  cboxPredefinedQueryList->insertItem( 0, tr( "No predefined queries loaded" ) );
 
74
 
 
75
  //set icons
 
76
  QString myThemePath = QgsApplication::activeThemePath( );
 
77
  pbtnOpenFile->setIcon( QIcon( QPixmap( myThemePath + "/mActionFolder.png" ) ) );
 
78
  pbtnOpenFile->setToolTip( tr( "Open File" ) );
 
79
  pbtnLoadPredefinedQueries->setIcon( QIcon( QPixmap( myThemePath + "/mActionFolder.png" ) ) );
 
80
  pbtnLoadPredefinedQueries->setToolTip( tr( "Open File" ) );
 
81
}
 
82
 
 
83
/**
 
84
* Destructor
 
85
*/
 
86
eVisDatabaseConnectionGui::~eVisDatabaseConnectionGui( )
 
87
{
 
88
}
 
89
 
 
90
 
 
91
/*
 
92
 *
 
93
 * Public and Private Slots
 
94
 *
 
95
 */
 
96
 
 
97
/**
 
98
* Slot called after the user selects the x, y fields in the field selection gui component
 
99
* @param layerName - Name to display in the legend
 
100
* @param xCoordinate - Name of the field containing the x coordinate
 
101
* @param yCoordinate - Name of the field containing the y coordinate
 
102
*/
 
103
void eVisDatabaseConnectionGui::drawNewVectorLayer( QString layerName, QString xCoordinate, QString yCoordinate )
 
104
{
 
105
  //if coorindate fields are defined, load as a delimited text layer
 
106
  if ( !xCoordinate.isEmpty( ) && !yCoordinate.isEmpty( ) && mTempOutputFileList->size( ) > 0 )
 
107
  {
 
108
    //fileName is only available if the file is open
 
109
    //the last file in the list is always the newest
 
110
    mTempOutputFileList->last( )->open( );
 
111
    QString uri = QString( "%1?delimiter=%2&xField=%3&yField=%4" )
 
112
                  .arg( mTempOutputFileList->last( )->fileName( ) )
 
113
                  .arg( "\t" )
 
114
                  .arg( xCoordinate )
 
115
                  .arg( yCoordinate );
 
116
    emit drawVectorLayer( uri, layerName, "delimitedtext" );
 
117
    mTempOutputFileList->last( )->close( );
 
118
  }
 
119
}
 
120
 
 
121
/**
 
122
* Slot called when the accept button is pressed
 
123
*/
 
124
void eVisDatabaseConnectionGui::on_buttonBox_accepted( )
 
125
{
 
126
  //Deallocate memory, basically a predescructor
 
127
  if ( 0 != mDatabaseConnection )
 
128
  {
 
129
    mDatabaseConnection->close( );
 
130
    delete( mDatabaseConnection );
 
131
  }
 
132
 
 
133
  if ( 0 != mDatabaseLayerFieldSelector )
 
134
  {
 
135
    delete( mDatabaseLayerFieldSelector );
 
136
  }
 
137
 
 
138
  if ( 0 != mQueryDefinitionMap )
 
139
  {
 
140
    mQueryDefinitionMap->clear();
 
141
    delete mQueryDefinitionMap;
 
142
  }
 
143
 
 
144
  accept( );
 
145
}
 
146
 
 
147
/**
 
148
* Slot called when the cboxDatabaseType combo box index changes
 
149
* @param currentIndex - The new index of the currently selected field
 
150
*/
 
151
void eVisDatabaseConnectionGui::on_cboxDatabaseType_currentIndexChanged( int currentIndex )
 
152
{
 
153
  if ( cboxDatabaseType->currentText( ) == "MYSQL" )
 
154
  {
 
155
    lblDatabaseHost->setEnabled( true );
 
156
    leDatabaseHost->setEnabled( true );
 
157
    lblDatabasePort->setEnabled( true );
 
158
    leDatabasePort->setText( "3306" );
 
159
    leDatabasePort->setEnabled( true );
 
160
    pbtnOpenFile->setEnabled( false );
 
161
    lblDatabaseUsername->setEnabled( true );
 
162
    leDatabaseUsername->setEnabled( true );
 
163
    lblDatabasePassword->setEnabled( true );
 
164
    leDatabasePassword->setEnabled( true );
 
165
    leDatabaseName->setText( "" );
 
166
  }
 
167
  else if ( cboxDatabaseType->currentText( ) == "PostGreSQL" )
 
168
  {
 
169
    lblDatabaseHost->setEnabled( true );
 
170
    leDatabaseHost->setEnabled( true );
 
171
    lblDatabasePort->setEnabled( true );
 
172
    leDatabasePort->setText( "5432" );
 
173
    leDatabasePort->setEnabled( true );
 
174
    pbtnOpenFile->setEnabled( false );
 
175
    lblDatabaseUsername->setEnabled( true );
 
176
    leDatabaseUsername->setEnabled( true );
 
177
    lblDatabasePassword->setEnabled( true );
 
178
    leDatabasePassword->setEnabled( true );
 
179
    leDatabaseName->setText( "" );
 
180
  }
 
181
  else if ( cboxDatabaseType->currentText( ) == "SQLITE" || cboxDatabaseType->currentText( ) == "MSAccess" )
 
182
  {
 
183
    lblDatabaseHost->setEnabled( false );
 
184
    leDatabaseHost->setText( "" );
 
185
    leDatabaseHost->setEnabled( false );
 
186
    lblDatabasePort->setEnabled( false );
 
187
    leDatabasePort->setText( "" );
 
188
    leDatabasePort->setEnabled( false );
 
189
    pbtnOpenFile->setEnabled( true );
 
190
    lblDatabaseUsername->setEnabled( false );
 
191
    leDatabaseUsername->setText( "" );
 
192
    leDatabaseUsername->setEnabled( false );
 
193
    lblDatabasePassword->setEnabled( false );
 
194
    leDatabasePassword->setText( "" );
 
195
    leDatabasePassword->setEnabled( false );
 
196
    leDatabaseName->setText( "" );
 
197
  }
 
198
  else
 
199
  {
 
200
    lblDatabaseHost->setEnabled( true );
 
201
    leDatabaseHost->setEnabled( true );
 
202
    lblDatabasePort->setEnabled( false );
 
203
    leDatabasePort->setText( "" );
 
204
    leDatabasePort->setEnabled( false );
 
205
    pbtnOpenFile->setEnabled( false );
 
206
    lblDatabaseUsername->setEnabled( true );
 
207
    leDatabaseUsername->setEnabled( true );
 
208
    lblDatabasePassword->setEnabled( true );
 
209
    leDatabasePassword->setEnabled( true );
 
210
    leDatabaseName->setText( "" );
 
211
  }
 
212
}
 
213
 
 
214
/**
 
215
* Slot called when pbtnConnect button pressed. This function does some basic error checking before
 
216
* requesting a new database connection
 
217
*/
 
218
void eVisDatabaseConnectionGui::on_pbtnConnect_clicked( )
 
219
{
 
220
  teditConsole->append( tr( "New Database connection requested..." ) );
 
221
  bool errors = false;
 
222
 
 
223
  if ( cboxDatabaseType->currentText( ) == tr( "Undefined" ) )
 
224
  {
 
225
    teditConsole->append( tr( "Error: You must select a database type" ) );
 
226
    errors = true;
 
227
  }
 
228
 
 
229
  if ( !errors && ( cboxDatabaseType->currentText( ) == "MYSQL" || cboxDatabaseType->currentText( ) == "PostGreSQL" ) )
 
230
  {
 
231
    if ( leDatabaseHost->text( ).isEmpty( ) )
 
232
    {
 
233
      teditConsole->append( tr( "Error: No host name entered" ) );
 
234
      errors = true;
 
235
    }
 
236
  }
 
237
 
 
238
  if ( !errors && leDatabaseName->text( ).isEmpty( ) )
 
239
  {
 
240
    teditConsole->append( tr( "Error: No database name entered" ) );
 
241
    errors = true;
 
242
  }
 
243
 
 
244
  //If no errors thus far, request a new database connection
 
245
  if ( !errors )
 
246
  {
 
247
    eVisDatabaseConnection::DATABASE_TYPE myDatabaseType;
 
248
    if ( cboxDatabaseType->currentText( ) == "MSAccess" )
 
249
    {
 
250
      myDatabaseType = eVisDatabaseConnection::MSACCESS;
 
251
    }
 
252
    else if ( cboxDatabaseType->currentText( ) == "MYSQL" )
 
253
    {
 
254
      myDatabaseType = eVisDatabaseConnection::QMYSQL;
 
255
    }
 
256
    else if ( cboxDatabaseType->currentText( ) == "ODBC" )
 
257
    {
 
258
      myDatabaseType = eVisDatabaseConnection::QODBC;
 
259
    }
 
260
    else if ( cboxDatabaseType->currentText( ) == "PostGreSQL" )
 
261
    {
 
262
      myDatabaseType = eVisDatabaseConnection::QPSQL;
 
263
    }
 
264
    else
 
265
    {
 
266
      myDatabaseType = eVisDatabaseConnection::QSQLITE;
 
267
    }
 
268
 
 
269
    //If there is aready a database connection object, reset with the current parameters
 
270
    if ( 0 != mDatabaseConnection )
 
271
    {
 
272
      mDatabaseConnection->resetConnectionParameters( leDatabaseHost->text( ), leDatabasePort->text( ).toInt( ), leDatabaseName->text( ), leDatabaseUsername->text( ), leDatabasePassword->text( ), myDatabaseType );
 
273
    }
 
274
    else //create a new database connection object
 
275
    {
 
276
      mDatabaseConnection = new eVisDatabaseConnection( leDatabaseHost->text( ), leDatabasePort->text( ).toInt( ), leDatabaseName->text( ), leDatabaseUsername->text( ), leDatabasePassword->text( ), myDatabaseType );
 
277
    }
 
278
 
 
279
    //Try to connect the database connection object
 
280
    if ( mDatabaseConnection->connect( ) )
 
281
    {
 
282
      teditConsole->append( tr( "Connection to [%1.%2] established" ).arg( leDatabaseHost->text() ).arg( leDatabaseName->text() ) );
 
283
      lblConnectionStatus->setText( tr( "connected" ) );
 
284
 
 
285
      //List the tables in the database
 
286
      teditConsole->append( tr( "Tables" ) + ":" );
 
287
      QStringList myTableList = mDatabaseConnection->tables( );
 
288
      for ( int myIterator = 0; myIterator < myTableList.size( ); myIterator++ )
 
289
      {
 
290
        teditConsole->append( "->" + myTableList[myIterator] );
 
291
      }
 
292
    }
 
293
    else
 
294
    {
 
295
      teditConsole->append( tr( "Connection to [%1.%2] failed: %3" )
 
296
                            .arg( leDatabaseHost->text() ).arg( leDatabaseName->text( ) ).arg( mDatabaseConnection->lastError() ) );
 
297
    }
 
298
  }
 
299
}
 
300
 
 
301
/**
 
302
* Slot called when pbtnLoadPredefinedQueries button is pressed. The method will open a file dialog and then
 
303
* try to parse through an XML file of predefined queries.
 
304
*/
 
305
void eVisDatabaseConnectionGui::on_pbtnLoadPredefinedQueries_clicked( )
 
306
{
 
307
  //There probably needs to be some more error checking, but works for now.
 
308
 
 
309
  //Select the XML file to parse
 
310
  QString myFilename = QFileDialog::getOpenFileName( this, tr( "Open File" ), ".", "XML ( *.xml )" );
 
311
  if ( myFilename != "" )
 
312
  {
 
313
    //Display the name of the file being parsed
 
314
    lblPredefinedQueryFilename->setText( myFilename );
 
315
 
 
316
    //If the file exists load it into a QDomDocument
 
317
    QFile myInputFile( myFilename );
 
318
    if ( myInputFile.open( QIODevice::ReadOnly | QIODevice::Text ) )
 
319
    {
 
320
      QString errorString;
 
321
      int errorLine;
 
322
      int errorColumn;
 
323
      QDomDocument myXmlDoc;
 
324
      if ( myXmlDoc.setContent( &myInputFile, &errorString, &errorLine, &errorColumn ) )
 
325
      {
 
326
        //clear any existing query descrptions
 
327
        cboxPredefinedQueryList->clear( );
 
328
        if ( !mQueryDefinitionMap->empty( ) )
 
329
        {
 
330
          delete( mQueryDefinitionMap );
 
331
          mQueryDefinitionMap = new QMap<int, eVisQueryDefinition>;
 
332
        }
 
333
 
 
334
        //Loop through each child looking for a query tag
 
335
        int myQueryCount = 0;
 
336
        QDomNode myNode = myXmlDoc.documentElement( ).firstChild( );
 
337
        while ( !myNode.isNull( ) )
 
338
        {
 
339
          if ( myNode.toElement( ).tagName( ) == "query" )
 
340
          {
 
341
            bool insert = false;
 
342
            eVisQueryDefinition myQueryDefinition;
 
343
            QDomNode myChildNodes = myNode.toElement( ).firstChild( );
 
344
            while ( !myChildNodes.isNull( ) )
 
345
            {
 
346
              QDomNode myDataNode = myChildNodes.toElement( ).firstChild( );
 
347
              QString myDataNodeContent = "";
 
348
              if ( !myDataNode.isNull( ) )
 
349
              {
 
350
                myDataNodeContent = myDataNode.toText( ).data( );
 
351
              }
 
352
 
 
353
              if ( myChildNodes.toElement( ).tagName( ) == "shortdescription" )
 
354
              {
 
355
                if ( myDataNodeContent != "" )
 
356
                {
 
357
                  myQueryDefinition.setShortDescription( myDataNodeContent );
 
358
                  myQueryCount++;
 
359
                  insert = true;
 
360
                }
 
361
              }
 
362
              else if ( myChildNodes.toElement( ).tagName( ) == "description" )
 
363
              {
 
364
                myQueryDefinition.setDescription( myDataNodeContent );
 
365
              }
 
366
              else if ( myChildNodes.toElement( ).tagName( ) == "databasetype" )
 
367
              {
 
368
                myQueryDefinition.setDatabaseType( myDataNodeContent );
 
369
              }
 
370
              else if ( myChildNodes.toElement( ).tagName( ) == "databasehost" )
 
371
              {
 
372
                myQueryDefinition.setDatabaseHost( myDataNodeContent );
 
373
              }
 
374
              else if ( myChildNodes.toElement( ).tagName( ) == "databaseport" )
 
375
              {
 
376
                myQueryDefinition.setDatabasePort( myDataNodeContent.toInt( ) );
 
377
              }
 
378
              else if ( myChildNodes.toElement( ).tagName( ) == "databasename" )
 
379
              {
 
380
                myQueryDefinition.setDatabaseName( myDataNodeContent );
 
381
              }
 
382
              else if ( myChildNodes.toElement( ).tagName( ) == "databaseusername" )
 
383
              {
 
384
                myQueryDefinition.setDatabaseUsername( myDataNodeContent );
 
385
              }
 
386
              else if ( myChildNodes.toElement( ).tagName( ) == "databasepassword" )
 
387
              {
 
388
                myQueryDefinition.setDatabasePassword( myDataNodeContent );
 
389
              }
 
390
              else if ( myChildNodes.toElement( ).tagName( ) == "sqlstatement" )
 
391
              {
 
392
                myQueryDefinition.setSqlStatement( myDataNodeContent );
 
393
              }
 
394
 
 
395
              myChildNodes = myChildNodes.nextSibling( );
 
396
            } //end  while( !myChildNodes.isNull( ) )
 
397
 
 
398
            if ( insert )
 
399
            {
 
400
              mQueryDefinitionMap->insert( myQueryCount - 1, myQueryDefinition );
 
401
              cboxPredefinedQueryList->insertItem( myQueryCount - 1, myQueryDefinition.shortDescription( ) );
 
402
            }
 
403
          } //end if( myNode.toElement( ).tagName( ) == "query" )
 
404
          myNode = myNode.nextSibling( );
 
405
        } // end  while( !myNode.isNull( ) )
 
406
      }
 
407
      else
 
408
      {
 
409
        teditConsole->append( tr( "Error: Parse error at line %1, column %2: %3" ).arg( errorLine ).arg( errorColumn ).arg( errorString ) );
 
410
      }
 
411
    }
 
412
    else
 
413
    {
 
414
      teditConsole->append( tr( "Error: Unabled to open file [%1]" ).arg( myFilename ) );
 
415
    }
 
416
  }
 
417
}
 
418
 
 
419
/**
 
420
* Slot called when cboxPredefinedQueryList combo box index changes
 
421
* @param index - The current index of the selected item
 
422
*/
 
423
void eVisDatabaseConnectionGui::on_cboxPredefinedQueryList_currentIndexChanged( int index )
 
424
{
 
425
  if ( !mQueryDefinitionMap->isEmpty( ) )
 
426
  {
 
427
    //get the query definition at the current index
 
428
    //NOTE: not really necessary to check to see if index is out of range from the query definition map because items cannot
 
429
    //be added to the combo box unless they are added to the query definition map
 
430
    eVisQueryDefinition myQueryDefinition = mQueryDefinitionMap->value( index );
 
431
 
 
432
    //Populate the GUI components with the values from the query definition
 
433
    teditQueryDescription->setText( myQueryDefinition.description( ) );
 
434
    cboxDatabaseType->setCurrentIndex( cboxDatabaseType->findText( myQueryDefinition.databaseType( ) ) );
 
435
    leDatabaseHost->setText( myQueryDefinition.databaseHost( ) );
 
436
    leDatabasePort->setText( QString( "%1" ).arg( myQueryDefinition.databasePort( ) ) );
 
437
    leDatabaseName->setText( myQueryDefinition.databaseName( ) );
 
438
    leDatabaseUsername->setText( myQueryDefinition.databaseUsername( ) );
 
439
    leDatabasePassword->setText( myQueryDefinition.databasePassword( ) );
 
440
    teditSqlStatement->setText( myQueryDefinition.sqlStatement( ) );
 
441
  }
 
442
}
 
443
 
 
444
/**
 
445
* Slot called when pbtnOpenFile button is pressed
 
446
*/
 
447
void eVisDatabaseConnectionGui::on_pbtnOpenFile_clicked( )
 
448
{
 
449
  if ( cboxDatabaseType->currentText( ) == "MSAccess" )
 
450
    leDatabaseName->setText( QFileDialog::getOpenFileName( this, tr( "Open File" ), ".", "MSAccess ( *.mdb )" ) );
 
451
  else
 
452
    leDatabaseName->setText( QFileDialog::getOpenFileName( this, tr( "Open File" ), ".", "Sqlite ( *.db )" ) );
 
453
}
 
454
 
 
455
/**
 
456
* Slot called when the pbtnRunQuery button is pressed
 
457
*/
 
458
void eVisDatabaseConnectionGui::on_pbtnRunQuery_clicked( )
 
459
{
 
460
  //Check to see if we have a query
 
461
  if ( !teditSqlStatement->toPlainText( ).isEmpty( ) )
 
462
  {
 
463
    //Verify that we have an active database connection
 
464
    if ( 0 != mDatabaseConnection )
 
465
    {
 
466
      //Execute query
 
467
      QSqlQuery* myResults = mDatabaseConnection->query( teditSqlStatement->toPlainText( ) );
 
468
      if ( 0 == myResults )
 
469
      {
 
470
        teditConsole->append( tr( "Error: Query failed: %1" ).arg( mDatabaseConnection->lastError( ) ) );
 
471
      }
 
472
      else if ( myResults->isSelect( ) )
 
473
      {
 
474
        //if valid and a select query, save results into temporary file and load as layer
 
475
        myResults->next( );
 
476
        if ( myResults->isValid( ) )
 
477
        {
 
478
          mTempOutputFileList->append( new QTemporaryFile( ) );
 
479
          if ( mTempOutputFileList->last( )->open( ) )
 
480
          {
 
481
            QTextStream outputStream( mTempOutputFileList->last( ) );
 
482
            QStringList fieldList;
 
483
            /*
 
484
             * Output column names
 
485
             */
 
486
            for ( int x = 0; x < myResults->record( ).count( ); x++ )
 
487
            {
 
488
              if ( 0 == x )
 
489
              {
 
490
                outputStream << myResults->record( ).fieldName( x );
 
491
              }
 
492
              else
 
493
              {
 
494
                outputStream << "\t" << myResults->record( ).fieldName( x );
 
495
              }
 
496
              fieldList << myResults->record( ).fieldName( x );
 
497
            }
 
498
            outputStream << endl;
 
499
            /*
 
500
             * Output Data
 
501
             */
 
502
            while ( myResults->isValid( ) )
 
503
            {
 
504
              for ( int x = 0; x < myResults->record( ).count( ); x++ )
 
505
              {
 
506
                if ( x == 0 )
 
507
                {
 
508
                  outputStream << myResults->value( x ).toString( );
 
509
                }
 
510
                else
 
511
                {
 
512
                  outputStream << "\t" << myResults->value( x ).toString( );
 
513
                }
 
514
              }
 
515
              outputStream << endl;
 
516
              myResults->next( );
 
517
            }
 
518
            mTempOutputFileList->last( )->close( );
 
519
            mDatabaseLayerFieldSelector->setFieldList( &fieldList );
 
520
            mDatabaseLayerFieldSelector->show( );
 
521
          }
 
522
          else
 
523
          {
 
524
            teditConsole->append( tr( "Error: Could not create temporary file, process halted" ) );
 
525
          }
 
526
        }
 
527
      }
 
528
    }
 
529
    else
 
530
    {
 
531
      teditConsole->append( tr( "Error: A database connection is not currently established" ) );
 
532
    }
 
533
  }
 
534
}