@@ -91,7 +91,8 @@ QgsSpatiaLiteSourceSelect::QgsSpatiaLiteSourceSelect( QgisApp * app, Qt::WFlags
91
91
mSearchModeComboBox ->setVisible ( false );
92
92
mSearchModeLabel ->setVisible ( false );
93
93
mSearchTableEdit ->setVisible ( false );
94
- cbxAllowGeometrylessTables->setVisible ( false );
94
+
95
+ cbxAllowGeometrylessTables->setDisabled ( true );
95
96
}
96
97
97
98
// Slot for performing action when the Add button is clicked
@@ -113,6 +114,11 @@ void QgsSpatiaLiteSourceSelect::buildQuery()
113
114
setSql ( mTablesTreeView ->currentIndex () );
114
115
}
115
116
117
+ void QgsSpatiaLiteSourceSelect::on_cbxAllowGeometrylessTables_stateChanged ( int )
118
+ {
119
+ on_btnConnect_clicked ();
120
+ }
121
+
116
122
void QgsSpatiaLiteSourceSelect::on_mTablesTreeView_clicked ( const QModelIndex &index )
117
123
{
118
124
mBuildQueryButton ->setEnabled ( index .parent ().isValid () );
@@ -269,13 +275,8 @@ sqlite3 *QgsSpatiaLiteSourceSelect::openSpatiaLiteDb( QString path )
269
275
if ( gcSpatiaLite && rsSpatiaLite )
270
276
return handle;
271
277
272
- // this one cannot be a valid SpatiaLite DB - no Spatial MetaData where found
273
- closeSpatiaLiteDb ( handle );
274
- errCause = tr ( " seems to be a valid SQLite DB, but not a SpatiaLite's one ..." );
275
- QMessageBox::critical ( this , tr ( " SpatiaLite DB Open Error" ),
276
- tr ( " Failure while connecting to: %1\n\n %2" ).arg ( mSqlitePath ).arg ( errCause ) );
277
- mSqlitePath = " " ;
278
- return NULL ;
278
+ // this seems to be a valid SQLite DB, but not a SpatiaLite's one
279
+ return handle;
279
280
280
281
error:
281
282
// unexpected IO error
@@ -471,6 +472,8 @@ void QgsSpatiaLiteSourceSelect::on_btnConnect_clicked()
471
472
{
472
473
sqlite3 *handle;
473
474
475
+ cbxAllowGeometrylessTables->setEnabled ( false );
476
+
474
477
QSettings settings;
475
478
QString subKey = cmbConnections->currentText ();
476
479
int idx = subKey.indexOf ( " @" );
@@ -517,6 +520,8 @@ void QgsSpatiaLiteSourceSelect::on_btnConnect_clicked()
517
520
}
518
521
mTablesTreeView ->resizeColumnToContents ( 0 );
519
522
mTablesTreeView ->resizeColumnToContents ( 1 );
523
+
524
+ cbxAllowGeometrylessTables->setEnabled ( true );
520
525
}
521
526
522
527
QStringList QgsSpatiaLiteSourceSelect::selectedTables ()
@@ -562,7 +567,7 @@ bool QgsSpatiaLiteSourceSelect::getTableInfo( sqlite3 * handle )
562
567
int columns;
563
568
char *errMsg = NULL ;
564
569
bool ok = false ;
565
- char sql[ 1024 ] ;
570
+ QString sql;
566
571
QApplication::setOverrideCursor ( Qt::WaitCursor );
567
572
568
573
// setting the SQLite DB name
@@ -571,9 +576,9 @@ bool QgsSpatiaLiteSourceSelect::getTableInfo( sqlite3 * handle )
571
576
mTableModel .setSqliteDb ( myName );
572
577
573
578
// the following query return the tables containing a Geometry column
574
- strcpy ( sql, " SELECT f_table_name, f_geometry_column, type " );
575
- strcat ( sql, " FROM geometry_columns" ) ;
576
- ret = sqlite3_get_table ( handle, sql, &results, &rows, &columns, &errMsg );
579
+ sql = " SELECT f_table_name, f_geometry_column, type "
580
+ " FROM geometry_columns" ;
581
+ ret = sqlite3_get_table ( handle, sql. toUtf8 () , &results, &rows, &columns, &errMsg );
577
582
if ( ret != SQLITE_OK )
578
583
goto error;
579
584
if ( rows < 1 )
@@ -599,10 +604,10 @@ bool QgsSpatiaLiteSourceSelect::getTableInfo( sqlite3 * handle )
599
604
if ( checkViewsGeometryColumns ( handle ) )
600
605
{
601
606
// the following query return the views supporting a Geometry column
602
- strcpy ( sql, " SELECT view_name, view_geometry, type " );
603
- strcat ( sql, " FROM views_geometry_columns " );
604
- strcat ( sql, " JOIN geometry_columns USING (f_table_name, f_geometry_column)" ) ;
605
- ret = sqlite3_get_table ( handle, sql, &results, &rows, &columns, &errMsg );
607
+ sql = " SELECT view_name, view_geometry, type "
608
+ " FROM views_geometry_columns "
609
+ " JOIN geometry_columns USING (f_table_name, f_geometry_column)" ;
610
+ ret = sqlite3_get_table ( handle, sql. toUtf8 () , &results, &rows, &columns, &errMsg );
606
611
if ( ret != SQLITE_OK )
607
612
goto error;
608
613
if ( rows < 1 )
@@ -627,9 +632,9 @@ bool QgsSpatiaLiteSourceSelect::getTableInfo( sqlite3 * handle )
627
632
if ( checkVirtsGeometryColumns ( handle ) )
628
633
{
629
634
// the following query return the VirtualShapefiles
630
- strcpy ( sql, " SELECT virt_name, virt_geometry, type " );
631
- strcat ( sql, " FROM virts_geometry_columns" ) ;
632
- ret = sqlite3_get_table ( handle, sql, &results, &rows, &columns, &errMsg );
635
+ sql = " SELECT virt_name, virt_geometry, type "
636
+ " FROM virts_geometry_columns" ;
637
+ ret = sqlite3_get_table ( handle, sql. toUtf8 () , &results, &rows, &columns, &errMsg );
633
638
if ( ret != SQLITE_OK )
634
639
goto error;
635
640
if ( rows < 1 )
@@ -651,6 +656,29 @@ bool QgsSpatiaLiteSourceSelect::getTableInfo( sqlite3 * handle )
651
656
sqlite3_free_table ( results );
652
657
}
653
658
659
+ if ( cbxAllowGeometrylessTables->isChecked () )
660
+ {
661
+ // get all tables
662
+ sql = " SELECT name "
663
+ " FROM sqlite_master "
664
+ " WHERE type in ('table', 'view')" ;
665
+ ret = sqlite3_get_table ( handle, sql.toUtf8 (), &results, &rows, &columns, &errMsg );
666
+ if ( ret != SQLITE_OK )
667
+ goto error;
668
+ if ( rows < 1 )
669
+ ;
670
+ else
671
+ {
672
+ for ( i = 1 ; i <= rows; i++ )
673
+ {
674
+ QString tableName = QString::fromUtf8 ( results[( i * columns ) + 0 ] );
675
+ mTableModel .addTableEntry ( tr ( " No geometry" ), tableName, QString::null, " " );
676
+ }
677
+ ok = true ;
678
+ }
679
+ sqlite3_free_table ( results );
680
+ }
681
+
654
682
QApplication::restoreOverrideCursor ();
655
683
return ok;
656
684
0 commit comments