47 |
47 |
QgsDataSourceURI mUri = QgsDataSourceURI( uri );
|
48 |
48 |
|
49 |
49 |
// parsing members from the uri structure
|
|
50 |
mSqlitePath = mUri.database();
|
50 |
51 |
mTableName = mUri.table();
|
51 |
52 |
geometryColumn = mUri.geometryColumn();
|
|
53 |
mSubsetString = mUri.sql();
|
52 |
54 |
|
53 |
|
// extracting the DB path
|
54 |
|
int idx = uri.indexOf( "dbname='" );
|
55 |
|
if ( idx >= 0 )
|
56 |
|
mSqlitePath = uri.mid( idx + 8 );
|
57 |
|
else
|
58 |
|
mSqlitePath = uri;
|
59 |
|
idx = mSqlitePath.indexOf( "' table=" );
|
60 |
|
if ( idx > 0 )
|
61 |
|
mSqlitePath.truncate( idx );
|
62 |
|
|
63 |
55 |
// trying to open the SQLite DB
|
64 |
56 |
spatialite_init( 0 );
|
65 |
57 |
valid = true;
|
... | ... | |
472 |
464 |
return true;
|
473 |
465 |
}
|
474 |
466 |
|
|
467 |
QString QgsSpatiaLiteProvider::subsetString()
|
|
468 |
{
|
|
469 |
return mSubsetString;
|
|
470 |
}
|
|
471 |
|
|
472 |
void QgsSpatiaLiteProvider::setSubsetString( QString theSQL )
|
|
473 |
{
|
|
474 |
mSubsetString = theSQL;
|
|
475 |
|
|
476 |
// update URI
|
|
477 |
QgsDataSourceURI uri = QgsDataSourceURI(dataSourceUri());
|
|
478 |
uri.setSql( theSQL );
|
|
479 |
setDataSourceUri( uri.uri() );
|
|
480 |
|
|
481 |
// update feature count and extents
|
|
482 |
getTableSummary();
|
|
483 |
}
|
|
484 |
|
475 |
485 |
void QgsSpatiaLiteProvider::select( QgsAttributeList fetchAttributes, QgsRectangle rect, bool fetchGeometry, bool useIntersect )
|
476 |
486 |
{
|
477 |
487 |
// preparing the SQL statement
|
... | ... | |
553 |
563 |
if ( !whereClause.isEmpty() )
|
554 |
564 |
sql += whereClause;
|
555 |
565 |
|
|
566 |
if ( !mSubsetString.isEmpty() )
|
|
567 |
{
|
|
568 |
if ( !whereClause.isEmpty() )
|
|
569 |
{
|
|
570 |
sql += " AND ";
|
|
571 |
}
|
|
572 |
else
|
|
573 |
{
|
|
574 |
sql += " WHERE ";
|
|
575 |
}
|
|
576 |
sql += "( " + mSubsetString + ")";
|
|
577 |
}
|
|
578 |
|
556 |
579 |
mFetchGeom = fetchGeometry;
|
557 |
580 |
mAttributesToFetch = fetchAttributes;
|
558 |
581 |
strcpy( xSql, sql.toUtf8().constData() );
|
... | ... | |
662 |
685 |
|
663 |
686 |
QString sql = QString( "SELECT Min(%1) FROM %2" ).arg( fld.name() ).arg( quotedValue( mTableName ) );
|
664 |
687 |
|
|
688 |
if ( !mSubsetString.isEmpty() )
|
|
689 |
{
|
|
690 |
sql += " WHERE ( " + mSubsetString + ")";
|
|
691 |
}
|
|
692 |
|
665 |
693 |
strcpy( xSql, sql.toUtf8().constData() );
|
666 |
694 |
ret = sqlite3_get_table( sqliteHandle, xSql, &results, &rows, &columns, &errMsg );
|
667 |
695 |
if ( ret != SQLITE_OK )
|
... | ... | |
717 |
745 |
|
718 |
746 |
QString sql = QString( "SELECT Max(%1) FROM %2" ).arg( fld.name() ).arg( quotedValue( mTableName ) );
|
719 |
747 |
|
|
748 |
if ( !mSubsetString.isEmpty() )
|
|
749 |
{
|
|
750 |
sql += " WHERE ( " + mSubsetString + ")";
|
|
751 |
}
|
|
752 |
|
720 |
753 |
strcpy( xSql, sql.toUtf8().constData() );
|
721 |
754 |
ret = sqlite3_get_table( sqliteHandle, xSql, &results, &rows, &columns, &errMsg );
|
722 |
755 |
if ( ret != SQLITE_OK )
|
... | ... | |
771 |
804 |
|
772 |
805 |
sql = QString( "SELECT DISTINCT %1 FROM %2 ORDER BY %1" ).arg( fld.name() ).arg( quotedValue( mTableName ) );
|
773 |
806 |
|
|
807 |
if ( !mSubsetString.isEmpty() )
|
|
808 |
{
|
|
809 |
sql += " WHERE ( " + mSubsetString + ")";
|
|
810 |
}
|
|
811 |
|
774 |
812 |
// SQLite prepared statement
|
775 |
813 |
strcpy( xSql, sql.toUtf8().constData() );
|
776 |
814 |
if ( sqlite3_prepare_v2( sqliteHandle, xSql, strlen( xSql ), &stmt, NULL ) != SQLITE_OK )
|
... | ... | |
1550 |
1588 |
QString sql = QString( "SELECT Min(MbrMinX(%1)), Min(MbrMinY(%1)), "
|
1551 |
1589 |
"Max(MbrMaxX(%1)), Max(MbrMaxY(%1)), Count(*) " "FROM %2" ).arg( geometryColumn ).arg( quotedValue( mTableName ) );
|
1552 |
1590 |
|
|
1591 |
if ( !mSubsetString.isEmpty() )
|
|
1592 |
{
|
|
1593 |
sql += " WHERE ( " + mSubsetString + ")";
|
|
1594 |
}
|
|
1595 |
|
1553 |
1596 |
strcpy( xSql, sql.toUtf8().constData() );
|
1554 |
1597 |
ret = sqlite3_get_table( sqliteHandle, xSql, &results, &rows, &columns, &errMsg );
|
1555 |
1598 |
if ( ret != SQLITE_OK )
|