Changeset 11353

Show
Ignore:
Timestamp:
04/25/07 17:44:54 (2 years ago)
Author:
mloskot
Message:

Added test case ogr_pg_22 checking PostgreSQL schema support in OGR PG.

Files:

Legend:

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

    r11065 r11353  
    791791 
    792792############################################################################### 
     793# Create table from data/poly.shp under specified SCHEMA 
     794# This test checks if schema support and schema name quoting works well. 
     795 
     796def ogr_pg_22(): 
     797 
     798    if gdaltest.pg_ds is None: 
     799        return 'skip' 
     800 
     801    ###################################################### 
     802    # Create Schema  
     803 
     804    schema_name = 'AutoTest-schema' 
     805    layer_name = schema_name + '.tpoly2' 
     806 
     807    gdaltest.pg_ds.ExecuteSQL( 'CREATE SCHEMA \"' + schema_name + '\"') 
     808 
     809    ###################################################### 
     810    # Create Layer 
     811    gdaltest.pg_lyr = gdaltest.pg_ds.CreateLayer( layer_name, 
     812                                                  options = [ 
     813                                                      'DIM=3', 
     814                                                      'SCHEMA=' + schema_name ] 
     815                                                ) 
     816 
     817    ###################################################### 
     818    # Setup Schema 
     819    ogrtest.quick_create_layer_def( gdaltest.pg_lyr, 
     820                                    [ ('AREA', ogr.OFTReal), 
     821                                      ('EAS_ID', ogr.OFTInteger), 
     822                                      ('PRFEDEA', ogr.OFTString), 
     823                                      ('SHORTNAME', ogr.OFTString, 8) ] ) 
     824 
     825    ###################################################### 
     826    # Copy 3 features from the poly.shp 
     827 
     828    dst_feat = ogr.Feature( feature_def = gdaltest.pg_lyr.GetLayerDefn() ) 
     829 
     830    shp_ds = ogr.Open( 'data/poly.shp' ) 
     831    gdaltest.shp_ds = shp_ds 
     832    shp_lyr = shp_ds.GetLayer(0) 
     833     
     834    # Insert 3 features only 
     835    for id in range(0, 3): 
     836        feat = shp_lyr.GetFeature(id) 
     837        dst_feat.SetFrom( feat ) 
     838        gdaltest.pg_lyr.CreateFeature( dst_feat ) 
     839 
     840    dst_feat.Destroy() 
     841 
     842    # Test if test layer under custom schema is listed 
     843     
     844    found = False 
     845    for i in range(0, gdaltest.pg_ds.GetLayerCount()): 
     846        name = gdaltest.pg_ds.GetLayer(i).GetName() 
     847        if name == layer_name: 
     848            found = True 
     849 
     850    if found is False: 
     851        gdaltest.post_reason( 'layer from schema \''+schema_name+'\' not listed' ) 
     852        return 'fail' 
     853 
     854    return 'success' 
     855 
     856############################################################################### 
    793857#  
    794858 
     
    802866    gdaltest.pg_ds.ExecuteSQL( 'DELLAYER:datetest' ) 
    803867    gdaltest.pg_ds.ExecuteSQL( 'DELLAYER:testgeom' ) 
     868     
     869    # Drop second 'tpoly' from schema 'AutoTest-schema' (do NOT quote names here) 
     870    gdaltest.pg_ds.ExecuteSQL( 'DELLAYER:AutoTest-schema.tpoly2' ) 
     871    # Drop 'AutoTest-schema' (here, double qoutes are required) 
     872    gdaltest.pg_ds.ExecuteSQL( 'DROP SCHEMA \"AutoTest-schema\" CASCADE') 
    804873 
    805874    gdaltest.pg_ds.Destroy() 
     
    832901    ogr_pg_20, 
    833902    ogr_pg_21, 
     903    ogr_pg_22, 
    834904    ogr_pg_cleanup ] 
    835905