|
22 | 22 | * |
23 | 23 | * |
24 | 24 | * IDENTIFICATION |
25 | | - * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.226 2001/08/2701:09:59 tgl Exp $ |
| 25 | + * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.227 2001/08/2720:33:07 tgl Exp $ |
26 | 26 | * |
27 | 27 | *------------------------------------------------------------------------- |
28 | 28 | */ |
@@ -400,77 +400,105 @@ dumpClasses_dumpData(Archive *fout, char *oid, void *dctxv) |
400 | 400 |
|
401 | 401 | if (fout->remoteVersion >=70100) |
402 | 402 | { |
403 | | -appendPQExpBuffer(q,"SELECT * FROM ONLY %s",fmtId(classname,force_quotes)); |
| 403 | +appendPQExpBuffer(q,"DECLARE _pg_dump_cursor CURSOR FORSELECT * FROM ONLY %s",fmtId(classname,force_quotes)); |
404 | 404 | }else { |
405 | | -appendPQExpBuffer(q,"SELECT * FROM %s",fmtId(classname,force_quotes)); |
| 405 | +appendPQExpBuffer(q,"DECLARE _pg_dump_cursor CURSOR FORSELECT * FROM %s",fmtId(classname,force_quotes)); |
406 | 406 | } |
407 | 407 |
|
408 | 408 | res=PQexec(g_conn,q->data); |
409 | 409 | if (!res|| |
410 | | -PQresultStatus(res)!=PGRES_TUPLES_OK) |
| 410 | +PQresultStatus(res)!=PGRES_COMMAND_OK) |
411 | 411 | { |
412 | 412 | write_msg(NULL,"dumpClasses(): SQL command failed\n"); |
413 | 413 | write_msg(NULL,"Error message from server: %s",PQerrorMessage(g_conn)); |
414 | 414 | write_msg(NULL,"The command was: %s\n",q->data); |
415 | 415 | exit_nicely(); |
416 | 416 | } |
417 | | -for (tuple=0;tuple<PQntuples(res);tuple++) |
418 | | -{ |
419 | | -archprintf(fout,"INSERT INTO %s ",fmtId(classname,force_quotes)); |
420 | | -if (attrNames== true) |
| 417 | + |
| 418 | +do { |
| 419 | +PQclear(res); |
| 420 | + |
| 421 | +res=PQexec(g_conn,"FETCH 100 FROM _pg_dump_cursor"); |
| 422 | +if (!res|| |
| 423 | +PQresultStatus(res)!=PGRES_TUPLES_OK) |
421 | 424 | { |
422 | | -resetPQExpBuffer(q); |
423 | | -appendPQExpBuffer(q,"("); |
424 | | -for (field=0;field<PQnfields(res);field++) |
425 | | -{ |
426 | | -if (field>0) |
427 | | -appendPQExpBuffer(q,","); |
428 | | -appendPQExpBuffer(q,fmtId(PQfname(res,field),force_quotes)); |
429 | | -} |
430 | | -appendPQExpBuffer(q,") "); |
431 | | -archprintf(fout,"%s",q->data); |
| 425 | +write_msg(NULL,"dumpClasses(): SQL command failed\n"); |
| 426 | +write_msg(NULL,"Error message from server: %s",PQerrorMessage(g_conn)); |
| 427 | +write_msg(NULL,"The command was: FETCH 100 FROM _pg_dump_cursor\n"); |
| 428 | +exit_nicely(); |
432 | 429 | } |
433 | | -archprintf(fout,"VALUES ("); |
434 | | -for (field=0;field<PQnfields(res);field++) |
| 430 | + |
| 431 | +for (tuple=0;tuple<PQntuples(res);tuple++) |
435 | 432 | { |
436 | | -if (field>0) |
437 | | -archprintf(fout,","); |
438 | | -if (PQgetisnull(res,tuple,field)) |
| 433 | +archprintf(fout,"INSERT INTO %s ",fmtId(classname,force_quotes)); |
| 434 | +if (attrNames== true) |
439 | 435 | { |
440 | | -archprintf(fout,"NULL"); |
441 | | -continue; |
| 436 | +resetPQExpBuffer(q); |
| 437 | +appendPQExpBuffer(q,"("); |
| 438 | +for (field=0;field<PQnfields(res);field++) |
| 439 | +{ |
| 440 | +if (field>0) |
| 441 | +appendPQExpBuffer(q,","); |
| 442 | +appendPQExpBuffer(q,fmtId(PQfname(res,field),force_quotes)); |
| 443 | +} |
| 444 | +appendPQExpBuffer(q,") "); |
| 445 | +archprintf(fout,"%s",q->data); |
442 | 446 | } |
443 | | -switch (PQftype(res,field)) |
| 447 | +archprintf(fout,"VALUES ("); |
| 448 | +for (field=0;field<PQnfields(res);field++) |
444 | 449 | { |
445 | | -caseINT2OID: |
446 | | -caseINT4OID: |
447 | | -caseOIDOID:/* int types */ |
448 | | -caseFLOAT4OID: |
449 | | -caseFLOAT8OID:/* float types */ |
450 | | -/* These types are printed without quotes */ |
451 | | -archprintf(fout,"%s", |
452 | | -PQgetvalue(res,tuple,field)); |
453 | | -break; |
454 | | -caseBITOID: |
455 | | -caseVARBITOID: |
456 | | -archprintf(fout,"B'%s'", |
457 | | -PQgetvalue(res,tuple,field)); |
458 | | -break; |
459 | | -default: |
460 | | - |
461 | | -/* |
462 | | - * All other types are printed as string literals, |
463 | | - * with appropriate escaping of special characters. |
464 | | - */ |
465 | | -resetPQExpBuffer(q); |
466 | | -formatStringLiteral(q,PQgetvalue(res,tuple,field),CONV_ALL); |
467 | | -archprintf(fout,"%s",q->data); |
468 | | -break; |
| 450 | +if (field>0) |
| 451 | +archprintf(fout,","); |
| 452 | +if (PQgetisnull(res,tuple,field)) |
| 453 | +{ |
| 454 | +archprintf(fout,"NULL"); |
| 455 | +continue; |
| 456 | +} |
| 457 | +switch (PQftype(res,field)) |
| 458 | +{ |
| 459 | +caseINT2OID: |
| 460 | +caseINT4OID: |
| 461 | +caseOIDOID:/* int types */ |
| 462 | +caseFLOAT4OID: |
| 463 | +caseFLOAT8OID:/* float types */ |
| 464 | +/* These types are printed without quotes */ |
| 465 | +archprintf(fout,"%s", |
| 466 | +PQgetvalue(res,tuple,field)); |
| 467 | +break; |
| 468 | +caseBITOID: |
| 469 | +caseVARBITOID: |
| 470 | +archprintf(fout,"B'%s'", |
| 471 | +PQgetvalue(res,tuple,field)); |
| 472 | +break; |
| 473 | +default: |
| 474 | + |
| 475 | +/* |
| 476 | + * All other types are printed as string literals, |
| 477 | + * with appropriate escaping of special characters. |
| 478 | + */ |
| 479 | +resetPQExpBuffer(q); |
| 480 | +formatStringLiteral(q,PQgetvalue(res,tuple,field),CONV_ALL); |
| 481 | +archprintf(fout,"%s",q->data); |
| 482 | +break; |
| 483 | +} |
469 | 484 | } |
| 485 | +archprintf(fout,");\n"); |
470 | 486 | } |
471 | | -archprintf(fout,");\n"); |
| 487 | + |
| 488 | +}while(PQntuples(res)>0 ); |
| 489 | +PQclear(res); |
| 490 | + |
| 491 | +res=PQexec(g_conn,"CLOSE _pg_dump_cursor"); |
| 492 | +if (!res|| |
| 493 | +PQresultStatus(res)!=PGRES_COMMAND_OK) |
| 494 | +{ |
| 495 | +write_msg(NULL,"dumpClasses(): SQL command failed\n"); |
| 496 | +write_msg(NULL,"Error message from server: %s",PQerrorMessage(g_conn)); |
| 497 | +write_msg(NULL,"The command was: CLOSE _pg_dump_cursor\n"); |
| 498 | +exit_nicely(); |
472 | 499 | } |
473 | 500 | PQclear(res); |
| 501 | + |
474 | 502 | destroyPQExpBuffer(q); |
475 | 503 | return1; |
476 | 504 | } |
|