Changeset 11225
- Timestamp:
- 04/08/07 10:51:34 (2 years ago)
- Files:
-
- branches/1.4/gdal/ogr/ogrsf_frmts/pg/ogr_pg.h (modified) (1 diff)
- branches/1.4/gdal/ogr/ogrsf_frmts/pg/ogrpgdatasource.cpp (modified) (39 diffs)
- branches/1.4/gdal/ogr/ogrsf_frmts/pg/ogrpglayer.cpp (modified) (9 diffs)
- branches/1.4/gdal/ogr/ogrsf_frmts/pg/ogrpgtablelayer.cpp (modified) (37 diffs)
- branches/1.4/gdal/ogr/ogrsf_frmts/pg/ogrpgutility.h (copied) (copied from trunk/gdal/ogr/ogrsf_frmts/pg/ogrpgutility.h)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.4/gdal/ogr/ogrsf_frmts/pg/ogr_pg.h
r10646 r11225 315 315 }; 316 316 317 318 317 #endif /* ndef _OGR_PG_H_INCLUDED */ 319 318 320 branches/1.4/gdal/ogr/ogrsf_frmts/pg/ogrpgdatasource.cpp
r10875 r11225 29 29 30 30 #include "ogr_pg.h" 31 #include "ogrpgutility.h" 31 32 #include "cpl_conv.h" 32 33 #include "cpl_string.h" … … 167 168 if( strstr(pszNewName, "dbname=") != NULL ) 168 169 { 169 int i;170 171 170 pszDBName = CPLStrdup( strstr(pszNewName, "dbname=") + 7 ); 172 171 173 for( i = 0; pszDBName[i] != '\0'; i++ )172 for( int i = 0; pszDBName[i] != '\0'; i++ ) 174 173 { 175 174 if( pszDBName[i] == ' ' ) … … 192 191 /* so we will get the value of the gist indexes. */ 193 192 /* -------------------------------------------------------------------- */ 194 PGresult *hResult;193 PGresult *hResult = NULL; 195 194 196 195 hResult = PQexec(hPGConn, "BEGIN"); … … 198 197 if( hResult && PQresultStatus(hResult) == PGRES_COMMAND_OK ) 199 198 { 200 PQclear( hResult ); 199 OGRPGClearResult( hResult ); 200 CPLAssert(NULL == hResult); 201 201 202 202 hResult = PQexec(hPGConn, … … 211 211 } 212 212 else 213 { 213 214 nGeometryOID = (Oid) 0; 214 215 if( hResult ) 216 PQclear( hResult ); 215 } 216 217 OGRPGClearResult( hResult ); 218 CPLAssert(NULL == hResult); /* Test if safe PQclear has not been broken */ 217 219 218 220 // find out postgis version. … … 279 281 PQgetvalue(hResult,0,0) ); 280 282 } 281 PQclear(hResult);283 OGRPGClearResult(hResult); 282 284 283 285 … … 295 297 hResult = PQexec(hPGConn, "SET ENABLE_SEQSCAN = ON"); 296 298 } 297 PQclear( hResult );299 OGRPGClearResult( hResult ); 298 300 } 299 301 300 302 hResult = PQexec(hPGConn, "COMMIT"); 301 PQclear( hResult );303 OGRPGClearResult( hResult ); 302 304 303 305 /* -------------------------------------------------------------------- */ … … 308 310 if( hResult && PQresultStatus(hResult) == PGRES_COMMAND_OK ) 309 311 { 310 PQclear( hResult );312 OGRPGClearResult( hResult ); 311 313 312 314 if ( bHavePostGIS ) … … 325 327 if( hResult && PQresultStatus(hResult) == PGRES_COMMAND_OK ) 326 328 { 327 PQclear( hResult );329 OGRPGClearResult( hResult ); 328 330 hResult = PQexec(hPGConn, "FETCH ALL in mycursor" ); 329 331 } … … 331 333 if( !hResult || PQresultStatus(hResult) != PGRES_TUPLES_OK ) 332 334 { 335 OGRPGClearResult( hResult ); 336 333 337 CPLError( CE_Failure, CPLE_AppDefined, 334 338 "%s", PQerrorMessage(hPGConn) ); … … 361 365 /* Cleanup */ 362 366 /* -------------------------------------------------------------------- */ 363 PQclear( hResult );367 OGRPGClearResult( hResult ); 364 368 365 369 hResult = PQexec(hPGConn, "CLOSE mycursor"); 366 PQclear( hResult );370 OGRPGClearResult( hResult ); 367 371 368 372 hResult = PQexec(hPGConn, "COMMIT"); 369 PQclear( hResult );373 OGRPGClearResult( hResult ); 370 374 371 375 /* -------------------------------------------------------------------- */ … … 448 452 449 453 hResult = PQexec(hPGConn, "BEGIN"); 450 PQclear( hResult );454 OGRPGClearResult( hResult ); 451 455 452 456 if( bHavePostGIS ) … … 459 463 460 464 hResult = PQexec( hPGConn, szCommand ); 461 PQclear( hResult );465 OGRPGClearResult( hResult ); 462 466 } 463 467 … … 465 469 CPLDebug( "OGR_PG", "PGexec(%s)", szCommand ); 466 470 hResult = PQexec( hPGConn, szCommand ); 467 PQclear( hResult );471 OGRPGClearResult( hResult ); 468 472 469 473 hResult = PQexec(hPGConn, "COMMIT"); 470 PQclear( hResult );474 OGRPGClearResult( hResult ); 471 475 472 476 return OGRERR_NONE; … … 535 539 { 536 540 pszSchemaName = CPLStrdup(PQgetvalue(hResult,0,0)); 537 PQclear( hResult );538 541 } 542 OGRPGClearResult( hResult ); 539 543 } 540 544 … … 605 609 /* -------------------------------------------------------------------- */ 606 610 hResult = PQexec(hPGConn, "BEGIN"); 607 PQclear( hResult ); 608 609 611 OGRPGClearResult( hResult ); 610 612 611 613 if( !bHavePostGIS ) … … 633 635 CPLFree( pszLayerName ); 634 636 CPLFree( pszSchemaName ); 635 PQclear( hResult ); 637 638 OGRPGClearResult( hResult ); 636 639 hResult = PQexec( hPGConn, "ROLLBACK" ); 637 PQclear( hResult );640 OGRPGClearResult( hResult ); 638 641 return NULL; 639 642 } 640 643 641 PQclear( hResult );644 OGRPGClearResult( hResult ); 642 645 643 646 /* -------------------------------------------------------------------- */ … … 669 672 CPLDebug( "OGR_PG", "PQexec(%s)", szCommand ); 670 673 hResult = PQexec(hPGConn, szCommand); 671 PQclear( hResult );674 OGRPGClearResult( hResult ); 672 675 673 676 switch( wkbFlatten(eType) ) … … 725 728 CPLFree( pszSchemaName ); 726 729 727 PQclear( hResult );730 OGRPGClearResult( hResult ); 728 731 729 732 hResult = PQexec(hPGConn, "ROLLBACK"); 730 PQclear( hResult );733 OGRPGClearResult( hResult ); 731 734 732 735 return NULL; 733 736 } 734 737 735 PQclear( hResult );738 OGRPGClearResult( hResult ); 736 739 } 737 740 … … 740 743 /* -------------------------------------------------------------------- */ 741 744 hResult = PQexec(hPGConn, "COMMIT"); 742 PQclear( hResult );745 OGRPGClearResult( hResult ); 743 746 744 747 /* -------------------------------------------------------------------- */ … … 883 886 /* Try looking up in spatial_ref_sys table. */ 884 887 /* -------------------------------------------------------------------- */ 885 PGresult *hResult ;888 PGresult *hResult = NULL; 886 889 char szCommand[1024]; 887 890 OGRSpatialReference *poSRS = NULL; … … 910 913 } 911 914 912 PQclear( hResult );915 OGRPGClearResult( hResult ); 913 916 SoftCommit(); 914 917 … … 936 939 937 940 { 938 PGresult *hResult ;941 PGresult *hResult = NULL; 939 942 char szCommand[10000]; 940 943 char *pszWKT = NULL; 941 int nSRSId ;944 int nSRSId = -1; 942 945 943 946 if( poSRS == NULL ) … … 957 960 /* -------------------------------------------------------------------- */ 958 961 hResult = PQexec(hPGConn, "BEGIN"); 962 OGRPGClearResult( hResult ); 959 963 960 964 sprintf( szCommand, … … 971 975 && PQntuples(hResult) > 0 ) 972 976 { 977 // TODO: mloskot - replace with strtol() function. 978 // atoi does not provide any level of diagnostics. 979 // What about adding CPLAtoi() ? 980 973 981 nSRSId = atoi(PQgetvalue( hResult, 0, 0 )); 974 982 975 PQclear( hResult );983 OGRPGClearResult( hResult ); 976 984 977 985 hResult = PQexec(hPGConn, "COMMIT"); 978 PQclear( hResult );986 OGRPGClearResult( hResult ); 979 987 980 988 return nSRSId; … … 991 999 992 1000 hResult = PQexec(hPGConn, "COMMIT"); 993 PQclear( hResult );1001 OGRPGClearResult( hResult ); 994 1002 995 1003 if( bTableMissing ) … … 1003 1011 /* -------------------------------------------------------------------- */ 1004 1012 hResult = PQexec(hPGConn, "BEGIN"); 1005 PQclear( hResult );1013 OGRPGClearResult( hResult ); 1006 1014 1007 1015 hResult = PQexec(hPGConn, "SELECT MAX(srid) FROM spatial_ref_sys" ); … … 1010 1018 { 1011 1019 nSRSId = atoi(PQgetvalue(hResult,0,0)) + 1; 1012 PQclear( hResult );1020 OGRPGClearResult( hResult ); 1013 1021 } 1014 1022 else 1023 { 1015 1024 nSRSId = 1; 1025 } 1016 1026 1017 1027 /* -------------------------------------------------------------------- */ … … 1043 1053 1044 1054 hResult = PQexec(hPGConn, szCommand ); 1045 PQclear( hResult );1055 OGRPGClearResult( hResult ); 1046 1056 1047 1057 hResult = PQexec(hPGConn, "COMMIT"); 1048 PQclear( hResult );1058 OGRPGClearResult( hResult ); 1049 1059 1050 1060 return nSRSId; … … 1066 1076 if( nSoftTransactionLevel == 1 ) 1067 1077 { 1068 PGresult *hResult;1069 PGconn *hPGConn = GetPGConn();1078 PGresult *hResult = NULL; 1079 PGconn *hPGConn = GetPGConn(); 1070 1080 1071 1081 //CPLDebug( "OGR_PG", "BEGIN Transaction" ); … … 1074 1084 if( !hResult || PQresultStatus(hResult) != PGRES_COMMAND_OK ) 1075 1085 { 1086 OGRPGClearResult( hResult ); 1087 1076 1088 CPLDebug( "OGR_PG", "BEGIN Transaction failed:\n%s", 1077 1089 PQerrorMessage( hPGConn ) ); … … 1079 1091 } 1080 1092 1081 PQclear( hResult );1093 OGRPGClearResult( hResult ); 1082 1094 } 1083 1095 … … 1107 1119 if( nSoftTransactionLevel == 0 ) 1108 1120 { 1109 PGresult *hResult;1110 PGconn *hPGConn = GetPGConn();1121 PGresult *hResult = NULL; 1122 PGconn *hPGConn = GetPGConn(); 1111 1123 1112 1124 //CPLDebug( "OGR_PG", "COMMIT Transaction" ); … … 1115 1127 if( !hResult || PQresultStatus(hResult) != PGRES_COMMAND_OK ) 1116 1128 { 1129 OGRPGClearResult( hResult ); 1130 1117 1131 CPLDebug( "OGR_PG", "COMMIT Transaction failed:\n%s", 1118 1132 PQerrorMessage( hPGConn ) ); 1119 1133 return OGRERR_FAILURE; 1120 1134 } 1121 1122 PQclear( hResult );1135 1136 OGRPGClearResult( hResult ); 1123 1137 } 1124 1138 … … 1144 1158 nSoftTransactionLevel = 0; 1145 1159 1146 PGresult *hResult;1147 PGconn *hPGConn = GetPGConn();1160 PGresult *hResult = NULL; 1161 PGconn *hPGConn = GetPGConn(); 1148 1162 1149 1163 hResult = PQexec(hPGConn, "ROLLBACK"); 1150 1164 1151 1165 if( !hResult || PQresultStatus(hResult) != PGRES_COMMAND_OK ) 1166 { 1167 OGRPGClearResult( hResult ); 1168 1152 1169 return OGRERR_FAILURE; 1153 1154 PQclear( hResult ); 1170 } 1171 1172 OGRPGClearResult( hResult ); 1155 1173 1156 1174 return OGRERR_NONE; … … 1211 1229 { 1212 1230 const char *pszLayerName = pszSQLCommand + 9; 1213 int iLayer;1214 1231 1215 1232 while( *pszLayerName == ' ' ) 1216 1233 pszLayerName++; 1217 1234 1218 for( i Layer = 0; iLayer < nLayers; iLayer++ )1235 for( int iLayer = 0; iLayer < nLayers; iLayer++ ) 1219 1236 { 1220 1237 if( EQUAL(papoLayers[iLayer]->GetLayerDefn()->GetName(), … … 1231 1248 /* Execute the statement. */ 1232 1249 /* -------------------------------------------------------------------- */ 1233 PGresult *hResult = NULL;1250 PGresult *hResult = NULL; 1234 1251 1235 1252 FlushSoftTransaction(); … … 1268 1285 } 1269 1286 1270 if( hResult ) 1271 PQclear( hResult ); 1287 OGRPGClearResult( hResult ); 1272 1288 1273 1289 FlushSoftTransaction(); … … 1294 1310 { 1295 1311 char *pszSafeName = CPLStrdup( pszSrcName ); 1296 int i; 1297 1298 for( i = 0; pszSafeName[i] != '\0'; i++ ) 1312 1313 for( int i = 0; pszSafeName[i] != '\0'; i++ ) 1299 1314 { 1300 1315 pszSafeName[i] = (char) tolower( pszSafeName[i] ); branches/1.4/gdal/ogr/ogrsf_frmts/pg/ogrpglayer.cpp
r10874 r11225 30 30 ****************************************************************************/ 31 31 32 #include "ogr_pg.h" 33 #include "ogrpgutility.h" 32 34 #include "cpl_conv.h" 33 #include "ogr_pg.h"34 35 #include "cpl_string.h" 35 36 … … 124 125 if( hCursorResult != NULL ) 125 126 { 126 PQclear( hCursorResult );127 OGRPGClearResult( hCursorResult ); 127 128 128 129 if( bCursorActive ) … … 131 132 132 133 hCursorResult = PQexec(hPGConn, szCommand); 133 PQclear( hCursorResult );134 OGRPGClearResult( hCursorResult ); 134 135 } 135 136 … … 525 526 526 527 hCursorResult = PQexec(hPGConn, osCommand ); 527 PQclear( hCursorResult );528 OGRPGClearResult( hCursorResult ); 528 529 529 530 osCommand.Printf( "FETCH %d in %s", CURSOR_PAGE, pszCursorName ); … … 541 542 || PQresultStatus(hCursorResult) != PGRES_TUPLES_OK ) 542 543 { 544 CPLDebug( "OGR_PG", "PQclear() on an error condition"); 545 546 OGRPGClearResult( hCursorResult ); 547 543 548 iNextShapeId = MAX(1,iNextShapeId); 544 549 return NULL; … … 551 556 && bCursorActive ) 552 557 { 553 PQclear( hCursorResult );558 OGRPGClearResult( hCursorResult ); 554 559 555 560 osCommand.Printf( "FETCH %d in %s", CURSOR_PAGE, pszCursorName ); … … 565 570 if( nResultOffset >= PQntuples(hCursorResult) ) 566 571 { 567 PQclear( hCursorResult );572 OGRPGClearResult( hCursorResult ); 568 573 569 574 if( bCursorActive ) … … 572 577 573 578 hCursorResult = PQexec(hPGConn, osCommand); 574 PQclear( hCursorResult );579 OGRPGClearResult( hCursorResult ); 575 580 } 576 581 … … 604 609 605 610 { 606 /* This should be implemented! */ 611 /* 612 * TODO: This should be implemented! 613 * See related Bug 1445 614 * http://bugzilla.remotesensing.org/show_bug.cgi?id=1445 615 */ 607 616 608 617 return NULL; branches/1.4/gdal/ogr/ogrsf_frmts/pg/ogrpgtablelayer.cpp
r10874 r11225 28 28 ****************************************************************************/ 29 29 30 #include "ogr_pg.h" 31 #include "ogrpgutility.h" 30 32 #include "cpl_conv.h" 31 33 #include "cpl_string.h" 32 34 #include "cpl_error.h" 33 #include "ogr_pg.h"34 35 35 36 CPL_CVSID("$Id$"); … … 131 132 osCurrentSchema = PQgetvalue(hResult,0,0); 132 133 133 PQclear( hResult );134 OGRPGClearResult( hResult ); 134 135 } 135 136 … … 166 167 if( hResult && PQresultStatus(hResult) == PGRES_COMMAND_OK ) 167 168 { 168 PQclear( hResult );169 OGRPGClearResult( hResult ); 169 170 170 171 CPLString osSchemaClause; … … 189 190 if( hResult && PQresultStatus(hResult) == PGRES_COMMAND_OK ) 190 191 { 191 PQclear( hResult );192 OGRPGClearResult( hResult ); 192 193 hResult = PQexec(hPGConn, "FETCH ALL in mycursor" ); 193 194 } … … 195 196 if( !hResult || PQresultStatus(hResult) != PGRES_TUPLES_OK ) 196 197 { 198 OGRPGClearResult( hResult ); 199 197 200 CPLError( CE_Failure, CPLE_AppDefined, 198 201 "%s", PQerrorMessage(hPGConn) ); … … 202 205 if( PQntuples(hResult) == 0 ) 203 206 { 204 PQclear( hResult ); 207 OGRPGClearResult( hResult ); 208 205 209 hResult = PQexec(hPGConn, "CLOSE mycursor"); 206 PQclear( hResult );210 OGRPGClearResult( hResult ); 207 211 208 212 hResult = PQexec(hPGConn, "COMMIT"); 209 PQclear( hResult );213 OGRPGClearResult( hResult ); 210 214 211 215 CPLError( CE_Failure, CPLE_AppDefined, … … 238 242 for( iRecord = 0; iRecord < PQntuples(hResult); iRecord++ ) 239 243 { 240 const char *pszType, *pszFormatType; 244 const char *pszType = NULL; 245 const char *pszFormatType = NULL; 241 246 OGRFieldDefn oField( PQgetvalue( hResult, iRecord, 0 ), OFTString); 242 247 … … 353 358 } 354 359 355 PQclear( hResult );360 OGRPGClearResult( hResult ); 356 361 357 362 hResult = PQexec(hPGConn, "CLOSE mycursor"); 358 PQclear( hResult );363 OGRPGClearResult( hResult ); 359 364 360 365 hResult = PQexec(hPGConn, "COMMIT"); 361 PQclear( hResult );366 OGRPGClearResult( hResult ); 362 367 363 368 // get layer geometry type (for PostGIS dataset) … … 369 374 370 375 hResult = PQexec(hPGConn,osCommand); 376 371 377 if ( hResult && PQntuples(hResult) == 1 && !PQgetisnull(hResult,0,0) ) 372 378 { … … 400 406 401 407 poDefn->SetGeomType( nGeomType ); 402 403 PQclear( hResult ); 404 }408 } 409 410 OGRPGClearResult( hResult ); 405 411 } 406 412 … … 519 525 520 526 { 521 int i, nSize; 522 char *pszFieldList; 527 int i = 0; 528 int nSize = 0; 529 char *pszFieldList = NULL; 523 530 524 531 nSize = 25; … … 609 616 610 617 { 611 PGconn *hPGConn = poDS->GetPGConn();612 PGresult *hResult;613 CPLString osCommand;618 PGconn *hPGConn = poDS->GetPGConn(); 619 PGresult *hResult = NULL; 620 CPLString osCommand; 614 621 615 622 /* -------------------------------------------------------------------- */ … … 634 641 635 642 /* -------------------------------------------------------------------- */ 636 /* Execute the insert. */643 /* Execute the delete. */ 637 644 /* -------------------------------------------------------------------- */ 638 645 OGRErr eErr; … … 652 659 PQerrorMessage(hPGConn) ); 653 660 654 PQclear( hResult );661 OGRPGClearResult( hResult ); 655 662 656 663 poDS->SoftRollback(); 657 658 return OGRERR_FAILURE; 659 } 660 661 return poDS->SoftCommit(); 664 eErr = OGRERR_FAILURE; 665 } 666 else 667 { 668 OGRPGClearResult( hResult ); 669 670 eErr = poDS->SoftCommit(); 671 } 672 673 return eErr; 662 674 } 663 675 … … 986 998 PQerrorMessage(hPGConn), osCommand.c_str() ); 987 999 988 PQclear( hResult );1000 OGRPGClearResult( hResult ); 989 1001 990 1002 poDS->SoftRollback(); … … 999 1011 printf( "nNewOID = %d\n", (int) nNewOID ); 1000 1012 #endif 1001 PQclear( hResult ); 1013 1014 OGRPGClearResult( hResult ); 1002 1015 1003 1016 return poDS->SoftCommit(); … … 1244 1257 { 1245 1258 PGconn *hPGConn = poDS->GetPGConn(); 1246 PGresult *hResult ;1259 PGresult *hResult = NULL; 1247 1260 CPLString osCommand; 1248 1261 char szFieldType[256]; … … 1337 1350 poDS->FlushSoftTransaction(); 1338 1351 hResult = PQexec(hPGConn, "BEGIN"); 1339 PQclear( hResult );1352 OGRPGClearResult( hResult ); 1340 1353 1341 1354 osCommand.Printf( "ALTER TABLE %s ADD COLUMN \"%s\" %s", … … 1349 1362 PQerrorMessage(hPGConn) ); 1350 1363 1351 PQclear( hResult ); 1364 OGRPGClearResult( hResult ); 1365 1352 1366 hResult = PQexec( hPGConn, "ROLLBACK" ); 1353 PQclear( hResult );1367 OGRPGClearResult( hResult ); 1354 1368 1355 1369 return OGRERR_FAILURE; 1356 1370 } 1357 1371 1358 PQclear( hResult );1372 OGRPGClearResult( hResult ); 1359 1373 1360 1374 hResult = PQexec(hPGConn, "COMMIT"); 1361 PQclear( hResult );1375 OGRPGClearResult( hResult ); 1362 1376 1363 1377 poFeatureDefn->AddFieldDefn( &oField ); … … 1385 1399 /* -------------------------------------------------------------------- */ 1386 1400 OGRFeature *poFeature = NULL; 1387 PGresult *hResult ;1401 PGresult *hResult = NULL; 1388 1402 PGconn *hPGConn = poDS->GetPGConn(); 1389 1403 char *pszFieldList = BuildFields(); … … 1405 1419 if( hResult && PQresultStatus(hResult) == PGRES_COMMAND_OK ) 1406 1420 { 1407 PQclear( hResult ); 1421 OGRPGClearResult( hResult ); 1422 1408 1423 hResult = PQexec(hPGConn, "FETCH ALL in getfeaturecursor" ); 1409 1424 … … 1419 1434 /* Cleanup */ 1420 1435 /* -------------------------------------------------------------------- */ 1421 PQclear( hResult );1436 OGRPGClearResult( hResult ); 1422 1437 1423 1438 hResult = PQexec(hPGConn, "CLOSE getfeaturecursor"); 1424 PQclear( hResult );1439 OGRPGClearResult( hResult ); 1425 1440 1426 1441 poDS->FlushSoftTransaction(); 1427 1428 1442 1429 1443 return poFeature; … … 1456 1470 /* -------------------------------------------------------------------- */ 1457 1471 PGconn *hPGConn = poDS->GetPGConn(); 1458 PGresult *hResult ;1472 PGresult *hResult = NULL; 1459 1473 CPLString osCommand; 1460 1474 int nCount = 0; … … 1462 1476 poDS->FlushSoftTransaction(); 1463 1477 hResult = PQexec(hPGConn, "BEGIN"); 1464 PQclear( hResult );1478 OGRPGClearResult( hResult ); 1465 1479 1466 1480 osCommand.Printf( … … 1474 1488 1475 1489 hResult = PQexec(hPGConn, osCommand); 1476 PQclear( hResult );1490 OGRPGClearResult( hResult ); 1477 1491 1478 1492 hResult = PQexec(hPGConn, "FETCH ALL in countCursor"); … … 1481 1495 else 1482 1496 CPLDebug( "OGR_PG", "%s; failed.", osCommand.c_str() ); 1483 PQclear( hResult );1497 OGRPGClearResult( hResult ); 1484 1498 1485 1499 hResult = PQexec(hPGConn, "CLOSE countCursor"); 1486 PQclear( hResult );1500 OGRPGClearResult( hResult ); 1487 1501 1488 1502 hResult = PQexec(hPGConn, "COMMIT"); 1489 PQclear( hResult );1503 OGRPGClearResult( hResult ); 1490 1504 1491 1505 return nCount; … … 1505 1519 if( nSRSId == -2 ) 1506 1520 { 1507 PGconn *hPGConn = poDS->GetPGConn();1508 PGresult *hResult;1509 char szCommand[1024];1521 PGconn *hPGConn = poDS->GetPGConn(); 1522 PGresult *hResult = NULL; 1523 char szCommand[1024]; 1510 1524 1511 1525 nSRSId = -1; … … 1527 1541 else // I think perhaps an older version used f_schema_name. 1528 1542 { 1529 PQclear( hResult ); 1543 OGRPGClearResult( hResult ); 1544 1530 1545 poDS->SoftCommit(); 1531 1546 poDS->SoftStartTransaction(); 1547 1532 1548 sprintf( szCommand, 1533 1549 "SELECT srid FROM geometry_columns " … … 1543 1559 } 1544 1560 1545 PQclear( hResult );1561 OGRPGClearResult( hResult ); 1546 1562 1547 1563 poDS->SoftCommit(); … … 1565 1581 if ( bHasPostGISGeometry ) 1566 1582 { 1567 PGconn *hPGConn = poDS->GetPGConn();1568 PGresult *hResult;1569 CPLString osCommand;1583 PGconn *hPGConn = poDS->GetPGConn(); 1584 PGresult *hResult = NULL; 1585 CPLString osCommand; 1570 1586 1571 1587 osCommand.Printf( "SELECT Extent(\"%s\") FROM %s", … … 1575 1591 if( ! hResult || PQresultStatus(hResult) != PGRES_TUPLES_OK || PQgetisnull(hResult,0,0) ) 1576 1592 { 1577 PQclear( hResult );1593 OGRPGClearResult( hResult ); 1578 1594 CPLDebug("OGR_PG","Unable to get extent by PostGIS. Using standard OGRLayer method."); 1579 1595 return OGRPGLayer::GetExtent( psExtent, bForce ); … … 1597 1613 "Bad extent representation: '%s'", pszBox); 1598 1614 CSLDestroy(papszTokens); 1599 PQclear(hResult); 1615 1616 OGRPGClearResult( hResult ); 1600 1617 return OGRERR_FAILURE; 1601 1618 } … … 1613 1630 1614 1631 CSLDestroy(papszTokens); 1615 1616 PQclear( hResult ); 1632 OGRPGClearResult( hResult ); 1633 1617 1634 return OGRERR_NONE; 1618 1635 } … … 1657 1674 bCopyActive = TRUE; 1658 1675 1659 PQclear( hResult );1676 OGRPGClearResult( hResult ); 1660 1677 CPLFree( pszCommand ); 1661 1678 … … 1681 1698 1682 1699 bCopyActive = FALSE; 1683 1684 1700 1685 1701 /* This is for postgresql 7.4 and higher */ … … 1722 1738 } 1723 1739 1724 PQclear(hResult);1740 OGRPGClearResult( hResult ); 1725 1741 1726 1742 bUseCopy = USE_COPY_UNSET; … … 1735 1751 char *OGRPGTableLayer::BuildCopyFields() 1736 1752 { 1737 int i, nSize; 1738 char *pszFieldList; 1753 int i = 0; 1754 int nSize = 0; 1755 char *pszFieldList; 1739 1756 1740 1757 nSize = 25;
