[postgis-users] Re: Fwd: pgsql2shp errors out after upgrading to 0.8.1

strk strk at keybit.net
Wed Apr 21 00:39:19 PDT 2004


Try modifying around line 2667 of pgsql2shp.c
Memory is allocated for main_scan_query, I belive the ::text cast
part was not taken into account, and indeed when not specifying
-b that part is not written to the buffer...
I've made those lines look like this:

        tmpint = strlen(table)+2;
        for (i=0; i<mainscan_nflds; i++)
                tmpint += strlen(mainscan_flds[i])+32;
        main_scan_query = (char *)malloc(tmpint+256);

Please tell me if the segfault and error message go away.

--strk;

On Tue, Apr 20, 2004 at 06:36:26PM -0500, markc at weaponeer.com wrote:
>  
>   Here you go -- I see a garble in the query right before 
> the column mentioned in the message. Every error of this 
> type seems to mention 1121 as the first offending char (with 
> different tables) ? 
>  
> markc at linux:~/qgis-0.1> pgsql2shp -b gis_main us_plant_rad_x 
> Initializing... Done. 
> MAINSCAN: SELECT 
> "tapefile"::text,"doelab"::text,"ornlid"::text,"site"::text,"replc"::text,"lat"::text,"long"::text,"state"::text,"quad"::text,"mapcode"::text,"study"::text,"phase"::text,"basinid"::text,"b_lat_c"::text,"b_long_c"::text,"samptyp"::text,"osamptyp"::text,"sampdat"::text,"samphr"::text,"sampler"::text,"grabs"::text,"weather"::text,"airtemp"::text,"sampodor"::text,"smpcolr"::text,"sgeounit"::text,"sedtype"::text,"strwdth"::text,"strdpth"::text,"wtrlevel"::text,"strflow"::text,"strorder"::text,"vegtype"::text,"vegdens"::text,"relief"::text,"contamc"::text,"plantno"::text,"dtreetyp"::text,"coniftyp"::text,"bushtyp"::text,"mosstyp"::text,"algaetyp"::text,"trnkdiam"::text,"plnthght"::text,"tapedata"::text,"spcdat"::text,"batch_es"::text,"asbatch"::text,"ubatch_dn"::text,"ubatch_fl"::text,"ubatch_ms"::text,"ubatch_xx"::text,"u_xx_mthd"::text,"u_xx_ppm"::text,"u_dn_ppm"::text,"u_fl_ppm"::text,"u_ms_ppm"::text,"ag_ppm"::text,"al_pct"::text,"as_ppm"::text,"b_ppm"::text,"ba_ppm"::text,"be_ppm"::text,"ca_ppm"::text,"co_ppm"::text,"cr_ppm"::text,"cu_ppm"::text,"fe_pct"::ted®#@d®#@pm"::text,"mg_pct"::text,"mn_ppm"::text,"mo_ppm"::text,"na_pct"::text,"nb_ppm"::text,"ni_ppm"::text,"p_pct"::text,"pb_ppm"::text,"pt_ppm"::text,"sc_ppm"::text,"se_ppm"::text,"th_ppm"::text,"ti_ppm"::text,"v_ppm"::text,"y_ppm"::text,"zn_ppm"::text,"zr_ppm"::text,"methods"::text,"reformat"::text,"comments"::text,"comment2"::text,asbinary("us_plant_rad_x_geom", 
> 'NDR') FROM "us_plant_rad_x" 
> ERROR:  syntax error at or near ""::text,"" at character 
> 1121 
>  
> There is another error we have seen with "-b"  a segfault.  
> Here is query.  I see nothing obvious here -- obvious to to 
> me at least.  This is a ARC supplied .shp that was imported, 
> and it also behaves well without "-b".  
>  
> pgsql2shp -b gis_main us_states 
> Initializing... Done. 
> MAINSCAN: SELECT 
> "gid"::text,"area"::text,"state_name"::text,"state_fips"::text,"sub_region"::text,"state_abbr"::text,"pop2000"::text,"pop2001"::text,"pop00_sqmi"::text,"white"::text,"black"::text,"ameri_es"::text,"asian"::text,"hawn_pi"::text,"other"::text,"mult_race"::text,"hispanic"::text,"males"::text,"females"::text,"age_under5"::text,"age_5_17"::text,"age_18_21"::text,"age_22_29"::text,"age_30_39"::text,"age_40_49"::text,"age_50_64"::text,"age_65_up"::text,"med_age"::text,"med_age_m"::text,"med_age_f"::text,"households"::text,"ave_hh_sz"::text,"hsehld_1_m"::text,"hsehld_1_f"::text,"marhh_chd"::text,"marhh_no_c"::text,"mhh_child"::text,"fhh_child"::text,"families"::text,"ave_fam_sz"::text,"hse_units"::text,"vacant"::text,"owner_occ"::text,"renter_occ"::text,"no_farms97"::text,"avg_size97"::text,"crop_acr97"::text,"avg_sale97"::text,asbinary("the_geom", 
> 'NDR') FROM "us_states" 
> Dumping: XSegmentation fault 
>  
> Tomorrow I may fire this up using gdb and see what I can see 
>  
> Cheers, and Honestly -- thanks for all the great work!  If I 
> was not so old as to require at least 4 hours sleep -- I 
> would roll up my sleeves and help a bit more.... 
>  
> Mark 
>  
>  
> ---- Original message ---- 
> >Date: Tue, 20 Apr 2004 07:52:21 +0200 
> >From: strk <strk at keybit.net>   
> >Subject: Re: Fwd: pgsql2shp errors out after upgrading to 
> 0.8.1   
> >To: markc at weaponeer.com 
> >Cc: postgis-users at postgis.refractions.net 
> > 
> >On Mon, Apr 19, 2004 at 08:21:36PM -0500, 
> markc at weaponeer.com wrote: 
> >> This ended up being the "-b" option, we have never used 
> it  
> >> before -- and I have no idea as to why it was decided to 
> try  
> >> it now.  
> >>   
> >>   We have happy .shp output even with 3M rows.  
> >>   
> >> Thanks for the keen eye!  
> >>   
> >> Mark  
> > 
> >Mark, nonetheless I'd like to see the "incriminated" query, 
> >because 'syntax error' is not an error I'd expect from 
> pgsql2shp, 
> >even with the -b switch. What I expect is a 'Cannot 
> cast...' or  
> >similar. Could you please send that main_loop_query ? 
> > 
> >TIA 
> > 
> >--strk; 
> > 
> >>   
> >>   
> >>   
> >>   
> >>   
> > 
> >> Date: Sun, 18 Apr 2004 22:04:57 -0500 
> >> From: markc at weaponeer.com 
> >> X-Mailer: Webmail Mirapoint Direct 3.2.2-GA 
> >> Subject: pgsql2shp errors out after upgrading to 0.8.1 
> >> To: postgis-users at postgis.refractions.net 
> >>  
> >> Hello,  
> >>   I've used pgsql2shp many times with this database, 
> after  
> >> upgrading to 0.8.1 I am getting an odd cast error.  
> >>   
> >>   Postgres is 7.4.2, using bison-1.875 (the problem ??),  
> >> PostGIS is using gdal-1.2.0 (proj-4.4.7).  
> >>   
> >>   Also if I import a .shp of this made in 1-2004 (which  
> >> seems to work) it dies with another syntax error.  
> >>   
> >>   I can send a dump of this db, as it's reasonably small.  
> >>   
> >>  Thanks,  
> >>   
> >>   Mark  
> >>   
> >>   
> >>     
> >>   
> >> markc at linux:~/qgis-0.1> pgsql2shp -b gis_main 
> us_plant_rad_x  
> >> Initializing... Done.  
> >> ERROR:  syntax error at or near ""::text,"" at character  
> >> 1121  
> >> markc at linux:~/qgis-0.1> psql -d gis_main  
> >> Welcome to psql 7.4.2, the PostgreSQL interactive 
> terminal.  
> >>   
> >> Type:  \copyright for distribution terms  
> >>        \h for help with SQL commands  
> >>        \? for help on internal slash commands  
> >>        \g or terminate with semicolon to execute query  
> >>        \q to quit  
> >>   
> >> gis_main=# select * from us_plant_rad_x;  
> >> gis_main=#  
> >> gis_main=# select version();  
> >>                                        version  
> >> 
> -------------------------------------------------------------------------------------  
> >>  PostgreSQL 7.4.2 on i686-pc-linux-gnu, compiled by GCC 
> gcc  
> >> (GCC) 3.3.1 (SuSE Linux)  
> >> (1 row)  
> >>   
> > 



More information about the postgis-users mailing list