?? ogrdatasource.cpp
字號:
pszNewName, papszOptions );
}
/************************************************************************/
/* DeleteLayer() */
/************************************************************************/
OGRErr OGRDataSource::DeleteLayer( int iLayer )
{
(void) iLayer;
CPLError( CE_Failure, CPLE_NotSupported,
"DeleteLayer() not supported by this data source." );
return OGRERR_UNSUPPORTED_OPERATION;
}
/************************************************************************/
/* OGR_DS_DeleteLayer() */
/************************************************************************/
OGRErr OGR_DS_DeleteLayer( OGRDataSourceH hDS, int iLayer )
{
return ((OGRDataSource *) hDS)->DeleteLayer( iLayer );
}
/************************************************************************/
/* GetLayerByName() */
/************************************************************************/
OGRLayer *OGRDataSource::GetLayerByName( const char *pszName )
{
if ( ! pszName )
return NULL;
int i;
/* first a case sensitive check */
for( i = 0; i < GetLayerCount(); i++ )
{
OGRLayer *poLayer = GetLayer(i);
if( strcmp( pszName, poLayer->GetLayerDefn()->GetName() ) == 0 )
return poLayer;
}
/* then case insensitive */
for( i = 0; i < GetLayerCount(); i++ )
{
OGRLayer *poLayer = GetLayer(i);
if( EQUAL( pszName, poLayer->GetLayerDefn()->GetName() ) )
return poLayer;
}
return NULL;
}
/************************************************************************/
/* OGR_DS_GetLayerByName() */
/************************************************************************/
OGRLayerH OGR_DS_GetLayerByName( OGRDataSourceH hDS, const char *pszName )
{
return (OGRLayerH) ((OGRDataSource *) hDS)->GetLayerByName( pszName );
}
/************************************************************************/
/* ProcessSQLCreateIndex() */
/* */
/* The correct syntax for creating an index in our dialect of */
/* SQL is: */
/* */
/* CREATE INDEX ON <layername> USING <columnname> */
/************************************************************************/
OGRErr OGRDataSource::ProcessSQLCreateIndex( const char *pszSQLCommand )
{
char **papszTokens = CSLTokenizeString( pszSQLCommand );
/* -------------------------------------------------------------------- */
/* Do some general syntax checking. */
/* -------------------------------------------------------------------- */
if( CSLCount(papszTokens) != 6
|| !EQUAL(papszTokens[0],"CREATE")
|| !EQUAL(papszTokens[1],"INDEX")
|| !EQUAL(papszTokens[2],"ON")
|| !EQUAL(papszTokens[4],"USING") )
{
CSLDestroy( papszTokens );
CPLError( CE_Failure, CPLE_AppDefined,
"Syntax error in CREATE INDEX command.\n"
"Was '%s'\n"
"Should be of form 'CREATE INDEX ON <table> USING <field>'",
pszSQLCommand );
return OGRERR_FAILURE;
}
/* -------------------------------------------------------------------- */
/* Find the named layer. */
/* -------------------------------------------------------------------- */
int i;
OGRLayer *poLayer = NULL;
for( i = 0; i < GetLayerCount(); i++ )
{
poLayer = GetLayer(i);
if( EQUAL(poLayer->GetLayerDefn()->GetName(),papszTokens[3]) )
break;
}
if( i >= GetLayerCount() )
{
CPLError( CE_Failure, CPLE_AppDefined,
"CREATE INDEX ON failed, no such layer as `%s'.",
papszTokens[3] );
CSLDestroy( papszTokens );
return OGRERR_FAILURE;
}
/* -------------------------------------------------------------------- */
/* Does this layer even support attribute indexes? */
/* -------------------------------------------------------------------- */
if( poLayer->GetIndex() == NULL )
{
CPLError( CE_Failure, CPLE_AppDefined,
"CREATE INDEX ON not supported by this driver." );
CSLDestroy( papszTokens );
return OGRERR_FAILURE;
}
/* -------------------------------------------------------------------- */
/* Find the named field. */
/* -------------------------------------------------------------------- */
for( i = 0; i < poLayer->GetLayerDefn()->GetFieldCount(); i++ )
{
if( EQUAL(papszTokens[5],
poLayer->GetLayerDefn()->GetFieldDefn(i)->GetNameRef()) )
break;
}
CSLDestroy( papszTokens );
if( i >= poLayer->GetLayerDefn()->GetFieldCount() )
{
CPLError( CE_Failure, CPLE_AppDefined,
"`%s' failed, field not found.",
pszSQLCommand );
return OGRERR_FAILURE;
}
/* -------------------------------------------------------------------- */
/* Attempt to create the index. */
/* -------------------------------------------------------------------- */
OGRErr eErr;
eErr = poLayer->GetIndex()->CreateIndex( i );
if( eErr == OGRERR_NONE )
eErr = poLayer->GetIndex()->IndexAllFeatures( i );
return eErr;
}
/************************************************************************/
/* ProcessSQLDropIndex() */
/* */
/* The correct syntax for droping one or more indexes in */
/* the OGR SQL dialect is: */
/* */
/* DROP INDEX ON <layername> [USING <columnname>] */
/************************************************************************/
OGRErr OGRDataSource::ProcessSQLDropIndex( const char *pszSQLCommand )
{
char **papszTokens = CSLTokenizeString( pszSQLCommand );
/* -------------------------------------------------------------------- */
/* Do some general syntax checking. */
/* -------------------------------------------------------------------- */
if( (CSLCount(papszTokens) != 4 && CSLCount(papszTokens) != 6)
|| !EQUAL(papszTokens[0],"DROP")
|| !EQUAL(papszTokens[1],"INDEX")
|| !EQUAL(papszTokens[2],"ON")
|| (CSLCount(papszTokens) == 6 && !EQUAL(papszTokens[4],"USING")) )
{
CSLDestroy( papszTokens );
CPLError( CE_Failure, CPLE_AppDefined,
"Syntax error in DROP INDEX command.\n"
"Was '%s'\n"
"Should be of form 'DROP INDEX ON <table> [USING <field>]'",
pszSQLCommand );
return OGRERR_FAILURE;
}
/* -------------------------------------------------------------------- */
/* Find the named layer. */
/* -------------------------------------------------------------------- */
int i;
OGRLayer *poLayer=NULL;
for( i = 0; i < GetLayerCount(); i++ )
{
poLayer = GetLayer(i);
if( EQUAL(poLayer->GetLayerDefn()->GetName(),papszTokens[3]) )
break;
}
if( i >= GetLayerCount() )
{
CPLError( CE_Failure, CPLE_AppDefined,
"CREATE INDEX ON failed, no such layer as `%s'.",
papszTokens[3] );
CSLDestroy( papszTokens );
return OGRERR_FAILURE;
}
/* -------------------------------------------------------------------- */
/* Does this layer even support attribute indexes? */
/* -------------------------------------------------------------------- */
if( poLayer->GetIndex() == NULL )
{
CPLError( CE_Failure, CPLE_AppDefined,
"Indexes not supported by this driver." );
CSLDestroy( papszTokens );
return OGRERR_FAILURE;
}
/* -------------------------------------------------------------------- */
/* If we weren't given a field name, drop all indexes. */
/* -------------------------------------------------------------------- */
OGRErr eErr;
if( CSLCount(papszTokens) == 4 )
{
for( i = 0; i < poLayer->GetLayerDefn()->GetFieldCount(); i++ )
{
OGRAttrIndex *poAttrIndex;
poAttrIndex = poLayer->GetIndex()->GetFieldIndex(i);
if( poAttrIndex != NULL )
{
eErr = poLayer->GetIndex()->DropIndex( i );
if( eErr != OGRERR_NONE )
return eErr;
}
}
CSLDestroy(papszTokens);
return OGRERR_NONE;
}
/* -------------------------------------------------------------------- */
/* Find the named field. */
/* -------------------------------------------------------------------- */
for( i = 0; i < poLayer->GetLayerDefn()->GetFieldCount(); i++ )
{
if( EQUAL(papszTokens[5],
poLayer->GetLayerDefn()->GetFieldDefn(i)->GetNameRef()) )
break;
}
CSLDestroy( papszTokens );
if( i >= poLayer->GetLayerDefn()->GetFieldCount() )
{
CPLError( CE_Failure, CPLE_AppDefined,
"`%s' failed, field not found.",
pszSQLCommand );
return OGRERR_FAILURE;
}
/* -------------------------------------------------------------------- */
/* Attempt to drop the index. */
/* -------------------------------------------------------------------- */
eErr = poLayer->GetIndex()->DropIndex( i );
return eErr;
}
/************************************************************************/
/* ExecuteSQL() */
/************************************************************************/
OGRLayer * OGRDataSource::ExecuteSQL( const char *pszStatement,
OGRGeometry *poSpatialFilter,
const char *pszDialect )
{
const char *pszError;
swq_select *psSelectInfo = NULL;
(void) pszDialect;
/* -------------------------------------------------------------------- */
/* Handle CREATE INDEX statements specially. */
/* -------------------------------------------------------------------- */
if( EQUALN(pszStatement,"CREATE INDEX",12) )
{
ProcessSQLCreateIndex( pszStatement );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Handle DROP INDEX statements specially. */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -