155
162
/************************************************************************/
156
/* OGRFeatureQueryEvaluator() */
163
/* OGRFeatureFetcher() */
157
164
/************************************************************************/
159
static int OGRFeatureQueryEvaluator( swq_field_op *op, OGRFeature *poFeature )
166
static swq_expr_node *OGRFeatureFetcher( swq_expr_node *op, void *pFeatureIn )
165
int iSpecialField = op->field_index - poFeature->GetDefnRef()->GetFieldCount();
166
if( iSpecialField >= 0 )
168
if ( iSpecialField < SPECIAL_FIELD_COUNT )
170
switch ( SpecialFieldTypes[iSpecialField] )
173
sField.Integer = poFeature->GetFieldAsInteger(op->field_index);
177
sField.Real = poFeature->GetFieldAsDouble(op->field_index);
181
sField.String = (char*)
182
poFeature->GetFieldAsString( op->field_index );
192
CPLDebug( "OGRFeatureQuery", "Illegal special field index.");
198
psField = poFeature->GetRawFieldRef( op->field_index );
169
OGRFeature *poFeature = (OGRFeature *) pFeatureIn;
170
swq_expr_node *poRetNode = NULL;
200
172
switch( op->field_type )
202
174
case SWQ_INTEGER:
203
switch( op->operation )
206
return psField->Integer == op->int_value;
208
return psField->Integer != op->int_value;
210
return psField->Integer < op->int_value;
212
return psField->Integer > op->int_value;
214
return psField->Integer <= op->int_value;
216
return psField->Integer >= op->int_value;
218
return !poFeature->IsFieldSet( op->field_index );
224
pszSrc = op->string_value;
225
while( *pszSrc != '\0' )
227
if( atoi(pszSrc) == psField->Integer )
229
pszSrc += strlen(pszSrc) + 1;
236
CPLDebug( "OGRFeatureQuery",
237
"Illegal operation (%d) on integer field.",
176
poRetNode = new swq_expr_node(
177
poFeature->GetFieldAsInteger(op->field_index) );
243
switch( op->operation )
246
return psField->Real == op->float_value;
248
return psField->Real != op->float_value;
250
return psField->Real < op->float_value;
252
return psField->Real > op->float_value;
254
return psField->Real <= op->float_value;
256
return psField->Real >= op->float_value;
258
return !poFeature->IsFieldSet( op->field_index );
263
pszSrc = op->string_value;
264
while( *pszSrc != '\0' )
266
if( atof(pszSrc) == psField->Real )
268
pszSrc += strlen(pszSrc) + 1;
275
CPLDebug( "OGRFeatureQuery",
276
"Illegal operation (%d) on float field.",
282
switch( op->operation )
285
if (psField->Set.nMarker1 == OGRUnsetMarker
286
&& psField->Set.nMarker2 == OGRUnsetMarker )
288
return (op->string_value[0] == '\0');
292
return EQUAL(psField->String,op->string_value);
295
if (psField->Set.nMarker1 == OGRUnsetMarker
296
&& psField->Set.nMarker2 == OGRUnsetMarker )
298
return (op->string_value[0] != '\0');
302
return !EQUAL(psField->String,op->string_value);
306
if (psField->Set.nMarker1 == OGRUnsetMarker
307
&& psField->Set.nMarker2 == OGRUnsetMarker )
309
return (op->string_value[0] != '\0');
313
return strcmp(psField->String,op->string_value) < 0;
316
if (psField->Set.nMarker1 == OGRUnsetMarker
317
&& psField->Set.nMarker2 == OGRUnsetMarker )
319
return (op->string_value[0] != '\0');
323
return strcmp(psField->String,op->string_value) > 0;
326
if (psField->Set.nMarker1 == OGRUnsetMarker
327
&& psField->Set.nMarker2 == OGRUnsetMarker )
329
return (op->string_value[0] != '\0');
333
return strcmp(psField->String,op->string_value) <= 0;
336
if (psField->Set.nMarker1 == OGRUnsetMarker
337
&& psField->Set.nMarker2 == OGRUnsetMarker )
339
return (op->string_value[0] != '\0');
343
return strcmp(psField->String,op->string_value) >= 0;
347
return !poFeature->IsFieldSet( op->field_index );
350
if (psField->Set.nMarker1 != OGRUnsetMarker
351
|| psField->Set.nMarker2 != OGRUnsetMarker )
352
return swq_test_like(psField->String, op->string_value);
360
if( !poFeature->IsFieldSet(op->field_index) )
363
pszSrc = op->string_value;
364
while( *pszSrc != '\0' )
366
if( EQUAL(pszSrc,psField->String) )
368
pszSrc += strlen(pszSrc) + 1;
375
CPLDebug( "OGRFeatureQuery",
376
"Illegal operation (%d) on string field.",
382
switch( op->operation )
385
return !poFeature->IsFieldSet( op->field_index );
388
CPLDebug( "OGRFeatureQuery",
389
"Illegal operation (%d) on list or binary field.",
181
poRetNode = new swq_expr_node(
182
poFeature->GetFieldAsDouble(op->field_index) );
186
poRetNode = new swq_expr_node(
187
poFeature->GetFieldAsString(op->field_index) );
191
poRetNode->is_null = !(poFeature->IsFieldSet(op->field_index));
400
196
/************************************************************************/
460
278
OGRFieldDefn *poFieldDefn;
462
poFieldDefn = poLayer->GetLayerDefn()->GetFieldDefn(psExpr->field_index);
280
poFieldDefn = poLayer->GetLayerDefn()->GetFieldDefn(poColumn->field_index);
282
/* -------------------------------------------------------------------- */
283
/* Handle the case of an IN operation. */
284
/* -------------------------------------------------------------------- */
285
if (psExpr->nOperation == SWQ_IN)
287
int nFIDCount = 0, nLength;
288
long *panFIDs = NULL;
291
for( iIN = 1; iIN < psExpr->nSubExprCount; iIN++ )
293
switch( poFieldDefn->GetType() )
296
if (psExpr->papoSubExpr[iIN]->field_type == SWQ_FLOAT)
297
sValue.Integer = (int) psExpr->papoSubExpr[iIN]->float_value;
299
sValue.Integer = psExpr->papoSubExpr[iIN]->int_value;
303
sValue.Real = psExpr->papoSubExpr[iIN]->float_value;
307
sValue.String = psExpr->papoSubExpr[iIN]->string_value;
315
panFIDs = poIndex->GetAllMatches( &sValue, panFIDs, &nFIDCount, &nLength );
320
/* the returned FIDs are expected to be in sorted order */
321
qsort(panFIDs, nFIDCount, sizeof(long), CompareLong);
326
/* -------------------------------------------------------------------- */
327
/* Handle equality test. */
328
/* -------------------------------------------------------------------- */
464
329
switch( poFieldDefn->GetType() )
467
sValue.Integer = psExpr->int_value;
332
if (poValue->field_type == SWQ_FLOAT)
333
sValue.Integer = (int) poValue->float_value;
335
sValue.Integer = poValue->int_value;
471
sValue.Real = psExpr->float_value;
339
sValue.Real = poValue->float_value;
475
sValue.String = psExpr->string_value;
343
sValue.String = poValue->string_value;
505
369
char **papszList )
508
swq_field_op *op = (swq_field_op *) pBareOp;
372
swq_expr_node *op = (swq_expr_node *) pBareOp;
510
374
/* -------------------------------------------------------------------- */
511
375
/* References to tables other than the primarily are currently */
512
376
/* unsupported. Error out. */
513
377
/* -------------------------------------------------------------------- */
514
if( op->table_index != 0 )
378
if( op->eNodeType == SNT_COLUMN )
516
CSLDestroy( papszList );
380
if( op->table_index != 0 )
382
CSLDestroy( papszList );
520
386
/* -------------------------------------------------------------------- */
521
387
/* Add the field name into our list if it is not already there. */
522
388
/* -------------------------------------------------------------------- */
523
const char *pszFieldName;
389
const char *pszFieldName;
525
if( op->field_index >= poTargetDefn->GetFieldCount()
526
&& op->field_index < poTargetDefn->GetFieldCount() + SPECIAL_FIELD_COUNT)
527
pszFieldName = SpecialFieldNames[op->field_index];
528
else if( op->field_index >= 0
529
&& op->field_index < poTargetDefn->GetFieldCount() )
531
poTargetDefn->GetFieldDefn(op->field_index)->GetNameRef();
534
CSLDestroy( papszList );
391
if( op->field_index >= poTargetDefn->GetFieldCount()
392
&& op->field_index < poTargetDefn->GetFieldCount() + SPECIAL_FIELD_COUNT)
393
pszFieldName = SpecialFieldNames[op->field_index];
394
else if( op->field_index >= 0
395
&& op->field_index < poTargetDefn->GetFieldCount() )
397
poTargetDefn->GetFieldDefn(op->field_index)->GetNameRef();
400
CSLDestroy( papszList );
404
if( CSLFindString( papszList, pszFieldName ) == -1 )
405
papszList = CSLAddString( papszList, pszFieldName );
538
if( CSLFindString( papszList, pszFieldName ) == -1 )
539
papszList = CSLAddString( papszList, pszFieldName );
541
408
/* -------------------------------------------------------------------- */
542
409
/* Add in fields from subexpressions. */
543
410
/* -------------------------------------------------------------------- */
544
if( op->first_sub_expr != NULL )
545
papszList = FieldCollector( op->first_sub_expr, papszList );
546
if( op->second_sub_expr != NULL )
547
papszList = FieldCollector( op->second_sub_expr, papszList );
411
if( op->eNodeType == SNT_OPERATION )
413
for( int iSubExpr = 0; iSubExpr < op->nSubExprCount; iSubExpr++ )
415
papszList = FieldCollector( op->papoSubExpr[iSubExpr], papszList );
549
419
return papszList;