Ticket #2134: gdal-1.5.0-ogr2ogr-sql.patch
| File gdal-1.5.0-ogr2ogr-sql.patch, 3.2 kB (added by dgrichard, 4 months ago) |
|---|
-
gdal-1.5.0/apps/ogr2ogr.cpp
old new 77 77 OGRGeometry *poSpatialFilter = NULL; 78 78 const char *pszSelect; 79 79 char **papszSelFields = NULL; 80 c onst char*pszSQLStatement = NULL;80 char *pszSQLStatement = NULL; 81 81 int eGType = -2; 82 82 83 83 /* -------------------------------------------------------------------- */ … … 376 376 if( pszSQLStatement != NULL ) 377 377 { 378 378 OGRLayer *poResultSet; 379 char *sql_pos; 380 char *sql_statement; 381 int isFile= FALSE; 382 383 /* allow passing a local file instead of text for */ 384 /* SQL statement. This hack is due to the */ 385 /* limitation of the command line (See ARG_MAX) */ 386 if( (sql_pos= strstr(pszSQLStatement,"file://")) != NULL ) 387 { 388 #define kSQLSTATEMENT_BUFLEN 10240 389 char *sql_file; 390 FILE *fp; 391 char buf[kSQLSTATEMENT_BUFLEN]; 392 sql_file= sql_pos+7; 393 size_t size_S= kSQLSTATEMENT_BUFLEN; 394 395 isFile= TRUE; 396 memset(buf,kSQLSTATEMENT_BUFLEN,'\0') ; 397 sql_statement= (char*)malloc(kSQLSTATEMENT_BUFLEN) ; 398 if ( (fp= fopen(sql_file,"r")) != NULL ) 399 { 400 fgets(buf,kSQLSTATEMENT_BUFLEN-1,fp) ; 401 strcpy(sql_statement,buf) ; 402 while( (fgets(buf,kSQLSTATEMENT_BUFLEN-1,fp)) != NULL ) 403 { 404 sql_statement= (char*)realloc(sql_statement,size_S+kSQLSTATEMENT_BUFLEN) ; 405 size_S+= kSQLSTATEMENT_BUFLEN ; 406 strcat(sql_statement,buf) ; 407 } 408 fclose(fp); 409 } 410 else 411 { 412 CPLError( CE_Failure, CPLE_AppDefined, 413 "--sql option : file %s is unreadable.", 414 sql_file); 415 exit( 1 ); 416 } 417 pszSQLStatement= sql_statement ; 418 #undef kSQLSTATEMENT_BUFLEN 419 } 379 420 380 421 if( pszWHERE != NULL ) 381 422 printf( "-where clause ignored in combination with -sql.\n" ); … … 385 426 poResultSet = poDS->ExecuteSQL( pszSQLStatement, poSpatialFilter, 386 427 NULL ); 387 428 429 if( isFile ) 430 { 431 free(pszSQLStatement) ; 432 } 433 388 434 if( poResultSet != NULL ) 389 435 { 390 436 if( !TranslateLayer( poDS, poResultSet, poODS, papszLCO, … … 502 548 " copy to the new layer (defaults to all)\n" 503 549 " -where restricted_where: Attribute query (like SQL WHERE)\n" 504 550 " -sql statement: Execute given SQL statement and save result.\n" 551 " The statement can be a local file with the\n" 552 " file://path_to_sql_file syntax.\n" 505 553 " -skipfailures: skip features or layers that fail to convert\n" 506 554 " -spat xmin ymin xmax ymax: spatial query extents\n" 507 555 " -dsco NAME=VALUE: Dataset creation option (format specific)\n"
