| | 793 | # Create table from data/poly.shp under specified SCHEMA |
|---|
| | 794 | # This test checks if schema support and schema name quoting works well. |
|---|
| | 795 | |
|---|
| | 796 | def 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 | ############################################################################### |
|---|