예제 #1
0
/**
\param val
**/
void BlSearchWidget::setFieldValue ( QString campo, QString val )
{
    BL_FUNC_DEBUG
    BlDebug::blDebug ( "BlSearchWidget::setcifprofesor", 0, val );

    QString SQLQuery("");
    SQLQuery = "SELECT * FROM " + m_tabla + " WHERE " + campo + " = $1";
    BlDbRecordSet *cur = mainCompany() ->load ( SQLQuery, val );

    if ( !cur->eof() ) {
        /// Inicializamos los valores de vuelta a ""
        QMapIterator<QString, QString> i ( m_valores );
        while ( i.hasNext() ) {
            i.next();
            m_valores.insert ( i.key(), cur->value( i.key() ) );
        } // end while
    } else {
        /// Inicializamos los valores de vuelta a ""
        QMapIterator<QString, QString> i ( m_valores );
        while ( i.hasNext() ) {
            i.next();
            m_valores.insert ( i.key(), "" );
        } // end while
    } // end if
    delete cur;
    pinta();
    
}
예제 #2
0
OGRSpatialReference* OGRGeoPackageDataSource::GetSpatialRef(int iSrsId)
{
    SQLResult oResult;
    
    /* Should we do something special with undefined SRS ? */
    if( iSrsId == 0 || iSrsId == -1 )
    {
        return NULL;
    }
    
    CPLString oSQL;
    oSQL.Printf("SELECT definition FROM gpkg_spatial_ref_sys WHERE srs_id = %d", iSrsId);
    
    OGRErr err = SQLQuery(m_poDb, oSQL.c_str(), &oResult);

    if ( err != OGRERR_NONE || oResult.nRowCount != 1 )
    {
        SQLResultFree(&oResult);
        CPLError( CE_Warning, CPLE_AppDefined, "unable to read srs_id '%d' from gpkg_spatial_ref_sys",
                  iSrsId);
        return NULL;
    }
    
    const char *pszWkt = SQLResultGetValue(&oResult, 0, 0);
    if ( ! pszWkt )
    {
        SQLResultFree(&oResult);
        CPLError( CE_Warning, CPLE_AppDefined, "null definition for srs_id '%d' in gpkg_spatial_ref_sys",
                  iSrsId);
        return NULL;
    }
    
    OGRSpatialReference *poSpatialRef = new OGRSpatialReference(pszWkt);
    
    if ( poSpatialRef == NULL )
    {
        SQLResultFree(&oResult);
        CPLError( CE_Warning, CPLE_AppDefined, "unable to parse srs_id '%d' well-known text '%s'",
                  iSrsId, pszWkt);
        return NULL;
    }
    
    SQLResultFree(&oResult);
    return poSpatialRef;
}
예제 #3
0
/**
\param val
**/
void BlSearchWidget::setId ( QString val, bool cargarvalores )
{
    BL_FUNC_DEBUG
    BlDebug::blDebug ( "BlSearchWidget::setId", 0, val );
    mdb_id = val;

    if ( m_tabla == "" || !cargarvalores) {
        return;
    } // end if

    if ( val == "" ) {
        m_inputBusqueda->setText ( "" );
        m_textBusqueda->setText ( "" );
        mdb_id = "";
        /// Inicializamos los valores de vuelta a ""
        QMapIterator<QString, QString> i ( m_valores );
        while ( i.hasNext() ) {
            i.next();
            m_valores.insert ( i.key(), "" );
        } // end while
    } else {
        QString SQLQuery("");
	SQLQuery = "SELECT * FROM " + m_tabla + " WHERE " + m_campoid + "= $1";
        BlDbRecordSet *cur = mainCompany() ->load( SQLQuery, mdb_id );
        if ( !cur->eof() ) {
            /// Inicializamos los valores de vuelta a ""
            QMapIterator<QString, QString> i ( m_valores );
            while ( i.hasNext() ) {
                i.next();
                m_valores.insert ( i.key(), cur->value( i.key() ) );
            } // end while
        } // end if
        delete cur;
    } // end if
    pinta();
    
}
예제 #4
0
int OGRGeoPackageDataSource::Open(const char * pszFilename, int bUpdate )
{
    int i;
    OGRErr err;

    CPLAssert( m_nLayers == 0 );
    CPLAssert( m_poDb == NULL );
    CPLAssert( m_pszFileName == NULL );

    m_bUpdate = bUpdate;

    /* Requirement 3: File name has to end in "gpkg" */
    /* http://opengis.github.io/geopackage/#_file_extension_name */
    int nLen = strlen(pszFilename);
    if(! (nLen >= 5 && EQUAL(pszFilename + nLen - 5, ".gpkg")) )
        return FALSE;

    /* Check that the filename exists and is a file */
    VSIStatBuf stat;
    if( CPLStat( pszFilename, &stat ) != 0 || !VSI_ISREG(stat.st_mode) )
        return FALSE;

    /* Requirement 2: A GeoPackage SHALL contain 0x47503130 ("GP10" in ASCII) */
    /* in the application id */
    /* http://opengis.github.io/geopackage/#_file_format */
    if ( ! CheckApplicationId(pszFilename) )
    {
        CPLError( CE_Failure, CPLE_AppDefined, "bad application_id on '%s'", pszFilename);
        return FALSE;
    }

    /* See if we can open the SQLite database */
    int rc = sqlite3_open( pszFilename, &m_poDb );
    if ( rc != SQLITE_OK )
    {
        m_poDb = NULL;
        CPLError( CE_Failure, CPLE_OpenFailed, "sqlite3_open(%s) failed: %s",
                  pszFilename, sqlite3_errmsg( m_poDb ) );
        return FALSE;
    }
    
    /* Filename is good, store it for future reference */
    m_pszFileName = CPLStrdup( pszFilename );

    /* Requirement 6: The SQLite PRAGMA integrity_check SQL command SHALL return “ok” */
    /* http://opengis.github.io/geopackage/#_file_integrity */
    if ( OGRERR_NONE != PragmaCheck("integrity_check", "ok", 1) )
    {
        CPLError( CE_Failure, CPLE_AppDefined, "pragma integrity_check on '%s' failed", pszFilename);
        return FALSE;
    }
    
    /* Requirement 7: The SQLite PRAGMA foreign_key_check() SQL with no */
    /* parameter value SHALL return an empty result set */
    /* http://opengis.github.io/geopackage/#_file_integrity */
    if ( OGRERR_NONE != PragmaCheck("foreign_key_check", "", 0) ) 
    {
        CPLError( CE_Failure, CPLE_AppDefined, "pragma foreign_key_check on '%s' failed", pszFilename);
        return FALSE; 
    }

    /* OGR UTF-8 capability, we'll advertise UTF-8 support if we have it */
    if ( OGRERR_NONE == PragmaCheck("encoding", "UTF-8", 1) ) 
    {
        m_bUtf8 = TRUE;
    }
    else
    {
        m_bUtf8 = FALSE;
    }

    /* Check for requirement metadata tables */
    /* Requirement 10: gpkg_spatial_ref_sys must exist */
    /* Requirement 13: gpkg_contents must exist */
    /* Requirement 21: gpkg_geometry_columns must exist */
    static std::string aosGpkgTables[] = {
        "gpkg_geometry_columns",
        "gpkg_spatial_ref_sys",
        "gpkg_contents"
    };
    
    for ( i = 0; i < 3; i++ )
    {
        SQLResult oResult;
        char *pszSQL = sqlite3_mprintf("pragma table_info('%s')", aosGpkgTables[i].c_str());
        err = SQLQuery(m_poDb, pszSQL, &oResult);
        sqlite3_free(pszSQL);
        
        if  ( err != OGRERR_NONE )
            return FALSE;
            
        if ( oResult.nRowCount <= 0 )
        {
            CPLError( CE_Failure, CPLE_AppDefined, "required GeoPackage table '%s' is missing", aosGpkgTables[i].c_str());
            SQLResultFree(&oResult);
            return FALSE;
        }
        
        SQLResultFree(&oResult);
    }
        
    /* Load layer definitions for all tables in gpkg_contents & gpkg_geometry_columns */
    SQLResult oResult;
    std::string osSQL = 
        "SELECT c.table_name, c.identifier, c.min_x, c.min_y, c.max_x, c.max_y "
        "FROM gpkg_geometry_columns g JOIN gpkg_contents c ON (g.table_name = c.table_name)"
        "WHERE c.data_type = 'features'";
        
    err = SQLQuery(m_poDb, osSQL.c_str(), &oResult);
    if  ( err != OGRERR_NONE )
    {
        SQLResultFree(&oResult);
        return FALSE;
    }

    if ( oResult.nRowCount > 0 )
    {
        m_papoLayers = (OGRLayer**)CPLMalloc(sizeof(OGRGeoPackageLayer*) * oResult.nRowCount);

        for ( i = 0; i < oResult.nRowCount; i++ )
        {
            const char *pszTableName = SQLResultGetValue(&oResult, 0, i);
            if ( ! pszTableName )
            {
                CPLError(CE_Warning, CPLE_AppDefined, "unable to read table name for layer(%d)", i);            
                continue;
            }
            OGRGeoPackageLayer *poLayer = new OGRGeoPackageLayer(this, pszTableName);
            if( OGRERR_NONE != poLayer->ReadTableDefinition() )
            {
                delete poLayer;
                CPLError(CE_Warning, CPLE_AppDefined, "unable to read table definition for '%s'", pszTableName);            
                continue;
            }
            m_papoLayers[m_nLayers++] = poLayer;
        }
    }
    
    SQLResultFree(&oResult);

    return TRUE;
}