Changeset 14396

Show
Ignore:
Timestamp:
05/08/08 12:27:19 (2 months ago)
Author:
rouault
Message:

Improve SQLite test coverage (blob columns, GetFeatureCount?)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/autotest/ogr/ogr_sqlite.py

    r14395 r14396  
    122122        return 'skip' 
    123123 
     124    if gdaltest.sl_lyr.GetFeatureCount() != 10: 
     125        gdaltest.post_reason( 'GetFeatureCount() returned %d instead of 10' % gdaltest.sl_lyr.GetFeatureCount() ) 
     126        return 'fail' 
     127 
    124128    expect = [168, 169, 166, 158, 165] 
    125129 
     
    127131    tr = ogrtest.check_features_against_list( gdaltest.sl_lyr, 
    128132                                              'eas_id', expect ) 
     133 
     134    if gdaltest.sl_lyr.GetFeatureCount() != 5: 
     135        gdaltest.post_reason( 'GetFeatureCount() returned %d instead of 5' % gdaltest.sl_lyr.GetFeatureCount() ) 
     136        return 'fail' 
     137 
    129138    gdaltest.sl_lyr.SetAttributeFilter( None ) 
    130139 
     
    214223     
    215224    sql_lyr = gdaltest.sl_ds.ExecuteSQL( 'select distinct eas_id from tpoly order by eas_id desc' ) 
     225 
     226    if sql_lyr.GetFeatureCount() != 11: 
     227        gdaltest.post_reason( 'GetFeatureCount() returned %d instead of 11' % sql_lyr.GetFeatureCount() ) 
     228        return 'fail' 
    216229 
    217230    tr = ogrtest.check_features_against_list( sql_lyr, 'eas_id', expect ) 
     
    263276    gdaltest.sl_lyr.SetSpatialFilter( geom ) 
    264277    geom.Destroy() 
    265      
     278 
     279    if gdaltest.sl_lyr.GetFeatureCount() != 1: 
     280        gdaltest.post_reason( 'GetFeatureCount() returned %d instead of 1' % gdaltest.sl_lyr.GetFeatureCount() ) 
     281        return 'fail' 
     282 
    266283    tr = ogrtest.check_features_against_list( gdaltest.sl_lyr, 'eas_id', 
    267284                                              [ 158 ] ) 
     285 
     286    gdaltest.sl_lyr.SetAttributeFilter( 'eas_id = 158' ) 
     287 
     288    if gdaltest.sl_lyr.GetFeatureCount() != 1: 
     289        gdaltest.post_reason( 'GetFeatureCount() returned %d instead of 1' % gdaltest.sl_lyr.GetFeatureCount() ) 
     290        return 'fail' 
     291 
     292    gdaltest.sl_lyr.SetAttributeFilter( None ) 
    268293 
    269294    gdaltest.sl_lyr.SetSpatialFilter( None ) 
     
    490515    feat_read.Destroy() 
    491516 
     517    feat_read = sql_lyr.GetFeature(0) 
     518    if ogrtest.check_feature_geometry(feat_read,geom,max_error = 0.001 ) != 0: 
     519        return 'fail' 
     520    feat_read.Destroy() 
     521 
    492522    gdaltest.sl_ds.ReleaseResultSet( sql_lyr ) 
    493523 
     
    532562    return 'success' 
    533563 
     564 
     565############################################################################### 
     566# Test all column types 
     567 
     568def ogr_sqlite_14(): 
     569 
     570    if gdaltest.sl_ds is None: 
     571        return 'skip' 
     572 
     573    gdaltest.sl_lyr = gdaltest.sl_ds.CreateLayer( 'testtypes' ) 
     574    ogrtest.quick_create_layer_def( gdaltest.sl_lyr, 
     575                                    [ ('INTEGER', ogr.OFTInteger), 
     576                                      ('FLOAT', ogr.OFTReal), 
     577                                      ('STRING', ogr.OFTString), 
     578                                      ('BLOB', ogr.OFTBinary), 
     579                                      ('BLOB2', ogr.OFTBinary) ] ) 
     580 
     581    dst_feat = ogr.Feature( feature_def = gdaltest.sl_lyr.GetLayerDefn() ) 
     582 
     583    dst_feat.SetField('INTEGER', 1) 
     584    dst_feat.SetField('FLOAT', 1.2) 
     585    dst_feat.SetField('STRING', 'myString\'a') 
     586 
     587    gdaltest.sl_lyr.CreateFeature( dst_feat ) 
     588 
     589    dst_feat.Destroy() 
     590 
     591    # Set the BLOB attribute via SQL UPDATE instructions as there's no binding 
     592    # for OGR_F_SetFieldBinary 
     593    gdaltest.sl_ds.ExecuteSQL("UPDATE testtypes SET BLOB = x'0001FF' WHERE OGC_FID = 1") 
     594 
     595    ###################################################### 
     596    # Reopen DB 
     597    gdaltest.sl_ds.Destroy() 
     598    gdaltest.sl_ds = ogr.Open( 'tmp/sqlite_test.db'  ) 
     599    gdaltest.sl_lyr = gdaltest.sl_ds.GetLayerByName('testtypes') 
     600 
     601    # Duplicate the first record 
     602    dst_feat = ogr.Feature( feature_def = gdaltest.sl_lyr.GetLayerDefn() ) 
     603    feat_read = gdaltest.sl_lyr.GetNextFeature() 
     604    dst_feat.SetFrom(feat_read) 
     605    gdaltest.sl_lyr.CreateFeature( dst_feat ) 
     606    dst_feat.Destroy() 
     607 
     608    # Check the 2 records 
     609    gdaltest.sl_lyr.ResetReading() 
     610    for i in range(2): 
     611        feat_read = gdaltest.sl_lyr.GetNextFeature() 
     612        if feat_read.GetField('INTEGER') != 1 or \ 
     613           feat_read.GetField('FLOAT') != 1.2 or \ 
     614           feat_read.GetField('STRING') != 'myString\'a' or \ 
     615           feat_read.GetFieldAsString('BLOB') != '0001FF': 
     616            return 'fail' 
     617 
     618    gdaltest.sl_lyr.ResetReading() 
     619 
     620    return 'success' 
    534621 
    535622############################################################################### 
     
    546633    gdaltest.sl_ds.ExecuteSQL( 'DELLAYER:wgs84layer' ) 
    547634    gdaltest.sl_ds.ExecuteSQL( 'DELLAYER:wgs84layer_approx' ) 
     635    gdaltest.sl_ds.ExecuteSQL( 'DELLAYER:testtypes' ) 
    548636 
    549637    gdaltest.sl_ds.Destroy() 
     
    571659    ogr_sqlite_12, 
    572660    ogr_sqlite_13, 
     661    ogr_sqlite_14, 
    573662    ogr_sqlite_cleanup ] 
    574663