void SQLApp::Query(int q) { book.Query(); if(book.FindSetCursor(q)) return; ClearQuery(); book.Query(); book.FindSetCursor(q); }
OGRFeature *OGRIDBTableLayer::GetFeature( GIntBig nFeatureId ) { if( pszFIDColumn == NULL ) return OGRIDBLayer::GetFeature( nFeatureId ); ClearQuery(); iNextShapeId = nFeatureId; poCurr = new ITCursor( *poDS->GetConnection() ); // Create list of fields CPLString osFields; if ( poFeatureDefn->GetFieldIndex( pszFIDColumn ) == -1 ) osFields += pszFIDColumn; if ( pszGeomColumn ) { if ( ! osFields.empty() ) osFields += ","; osFields += "st_asbinary("; osFields += pszGeomColumn; osFields += ") as "; osFields += pszGeomColumn; } for( int i = 0; i < poFeatureDefn->GetFieldCount(); i++ ) { if ( ! osFields.empty() ) osFields += ","; osFields += poFeatureDefn->GetFieldDefn(i)->GetNameRef(); } CPLString sql; sql.Printf( "SELECT %s FROM %s WHERE %s = %d", osFields.c_str(), poFeatureDefn->GetName(), pszFIDColumn, nFeatureId ); CPLDebug( "OGR_IDB", "ExecuteSQL(%s)", sql.c_str() ); if( !poCurr->Prepare( sql.c_str() ) || !poCurr->Open(ITCursor::ReadOnly) ) { delete poCurr; poCurr = NULL; return NULL; } return GetNextRawFeature(); }
OGRErr OGRIDBTableLayer::SetAttributeFilter( const char *pszQuery ) { CPLFree(m_pszAttrQueryString); m_pszAttrQueryString = (pszQuery) ? CPLStrdup(pszQuery) : NULL; if( (pszQuery == NULL && this->pszQuery == NULL) || (pszQuery != NULL && this->pszQuery != NULL && EQUAL(pszQuery,this->pszQuery)) ) return OGRERR_NONE; CPLFree( this->pszQuery ); this->pszQuery = CPLStrdup( pszQuery ); ClearQuery(); return OGRERR_NONE; }
OGRIDBTableLayer::~OGRIDBTableLayer() { CPLFree( pszQuery ); ClearQuery(); }
void OGRIDBTableLayer::ResetReading() { ClearQuery(); OGRIDBLayer::ResetReading(); }
OGRErr OGRIDBTableLayer::ResetQuery() { ClearQuery(); iNextShapeId = 0; poCurr = new ITCursor( *poDS->GetConnection() ); // Create list of fields CPLString osFields; if ( pszGeomColumn ) { if ( ! osFields.empty() ) osFields += ","; osFields += "st_asbinary("; osFields += pszGeomColumn; osFields += ") as "; osFields += pszGeomColumn; } for( int i = 0; i < poFeatureDefn->GetFieldCount(); i++ ) { if ( ! osFields.empty() ) osFields += ","; osFields += poFeatureDefn->GetFieldDefn(i)->GetNameRef(); } CPLString sql; sql += "SELECT "; sql += osFields; sql += " FROM "; sql += poFeatureDefn->GetName(); /* Append attribute query if we have it */ if( pszQuery != NULL ) { sql += " WHERE "; sql += pszQuery; } /* If we have a spatial filter, and per record extents, query on it */ if( m_poFilterGeom != NULL && bHaveSpatialExtents ) { if( pszQuery == NULL ) sql += " WHERE"; else sql += " AND"; sql.Printf( "%s XMAX > %.8f AND XMIN < %.8f" " AND YMAX > %.8f AND YMIN < %.8f", sql.c_str(), m_sFilterEnvelope.MinX, m_sFilterEnvelope.MaxX, m_sFilterEnvelope.MinY, m_sFilterEnvelope.MaxY ); } CPLDebug( "OGR_IDB", "Exec(%s)", sql.c_str() ); if( poCurr->Prepare( sql.c_str() ) && poCurr->Open(ITCursor::ReadOnly) ) { return OGRERR_NONE; } else { delete poCurr; poCurr = NULL; return OGRERR_FAILURE; } }