perl-dbi.patch 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. Index: DBD-Pg-1.31/dbdimp.c
  2. --- DBD-Pg-1.31/dbdimp.c.orig 2003-10-27 20:57:02.000000000 +0100
  3. +++ DBD-Pg-1.31/dbdimp.c 2003-11-21 21:10:50.000000000 +0100
  4. @@ -36,6 +36,34 @@
  5. #include "large_object.c"
  6. #include "prescan_stmt.c"
  7. +static int
  8. +_dbd_begin(dbh, imp_dbh)
  9. + SV *dbh;
  10. + imp_dbh_t *imp_dbh;
  11. +{
  12. + PGresult *result = NULL;
  13. + ExecStatusType status;
  14. +
  15. + if (DBIc_has(imp_dbh, DBIcf_AutoCommit))
  16. + return 1;
  17. +
  18. + if (imp_dbh->pg_need_begin == 0)
  19. + return 1;
  20. +
  21. + imp_dbh->pg_need_begin = 0;
  22. +
  23. + /* start new transaction. AutoCommit must be FALSE (see above) */
  24. + result = PQexec(imp_dbh->conn, "begin");
  25. + status = result ? PQresultStatus(result) : -1;
  26. + PQclear(result);
  27. + if (status != PGRES_COMMAND_OK) {
  28. + pg_error(dbh, status, "begin failed\n");
  29. + return 0;
  30. + }
  31. +
  32. + return 1;
  33. +}
  34. +
  35. void
  36. dbd_init (dbistate)
  37. dbistate_t *dbistate;
  38. @@ -219,6 +247,7 @@
  39. #ifdef is_utf8_string
  40. imp_dbh->pg_enable_utf8 = 0; /* initialize pg_enable_utf8 */
  41. #endif
  42. + imp_dbh->pg_need_begin = 1; /* initialize begin state */
  43. DBIc_IMPSET_on(imp_dbh); /* imp_dbh set up now */
  44. DBIc_ACTIVE_on(imp_dbh); /* call disconnect before freeing */
  45. @@ -310,7 +339,7 @@
  46. if (NULL != imp_dbh->conn) {
  47. PGresult* result = 0;
  48. - ExecStatusType commitstatus, beginstatus;
  49. + ExecStatusType commitstatus;
  50. /* execute commit */
  51. result = PQexec(imp_dbh->conn, "commit");
  52. @@ -323,15 +352,8 @@
  53. pg_error(dbh, commitstatus, PQerrorMessage(imp_dbh->conn));
  54. }
  55. - /* start new transaction. AutoCommit must be FALSE, ref. 20 lines up */
  56. - result = PQexec(imp_dbh->conn, "begin");
  57. - beginstatus = result ? PQresultStatus(result) : -1;
  58. - PQclear(result);
  59. - if (beginstatus != PGRES_COMMAND_OK) {
  60. - /* Maybe add some loud barf here? Raising some very high error? */
  61. - pg_error(dbh, beginstatus, "begin failed\n");
  62. - return 0;
  63. - }
  64. + /* mark need for a begin at the start of the next command */
  65. + imp_dbh->pg_need_begin = 1;
  66. /* if the initial COMMIT failed, return 0 now */
  67. if (commitstatus != PGRES_COMMAND_OK) {
  68. @@ -361,6 +383,10 @@
  69. if (NULL != imp_dbh->conn) {
  70. PGresult* result = 0;
  71. ExecStatusType status;
  72. +
  73. + /* no rollback is needed if we are not already in a transaction */
  74. + if (imp_dbh->pg_need_begin)
  75. + return 1;
  76. /* execute rollback */
  77. result = PQexec(imp_dbh->conn, "rollback");
  78. @@ -375,14 +401,8 @@
  79. return 0;
  80. }
  81. - /* start new transaction. AutoCommit must be FALSE, ref. 20 lines up */
  82. - result = PQexec(imp_dbh->conn, "begin");
  83. - status = result ? PQresultStatus(result) : -1;
  84. - PQclear(result);
  85. - if (status != PGRES_COMMAND_OK) {
  86. - pg_error(dbh, status, "begin failed\n");
  87. - return 0;
  88. - }
  89. + /* mark need for a begin at the start of the next command */
  90. + imp_dbh->pg_need_begin = 1;
  91. return 1;
  92. }
  93. @@ -409,7 +429,8 @@
  94. if (NULL != imp_dbh->conn) {
  95. /* rollback if AutoCommit = off */
  96. - if (DBIc_has(imp_dbh, DBIcf_AutoCommit) == FALSE) {
  97. + if ((imp_dbh->pg_need_begin == 0)
  98. + && (DBIc_has(imp_dbh, DBIcf_AutoCommit) == FALSE)) {
  99. PGresult* result = 0;
  100. ExecStatusType status;
  101. result = PQexec(imp_dbh->conn, "rollback");
  102. @@ -485,16 +506,7 @@
  103. if (dbis->debug >= 2) { PerlIO_printf(DBILOGFP, "dbd_db_STORE: switch AutoCommit to on: commit\n"); }
  104. } else if ((oldval != FALSE && newval == FALSE) || (oldval == FALSE && newval == FALSE && imp_dbh->init_commit)) {
  105. if (NULL != imp_dbh->conn) {
  106. - /* start new transaction */
  107. - PGresult* result = 0;
  108. - ExecStatusType status;
  109. - result = PQexec(imp_dbh->conn, "begin");
  110. - status = result ? PQresultStatus(result) : -1;
  111. - PQclear(result);
  112. - if (status != PGRES_COMMAND_OK) {
  113. - pg_error(dbh, status, "begin failed\n");
  114. - return 0;
  115. - }
  116. + imp_dbh->pg_need_begin = 1;
  117. }
  118. if (dbis->debug >= 2) { PerlIO_printf(DBILOGFP, "dbd_db_STORE: switch AutoCommit to off: begin\n"); }
  119. }
  120. @@ -899,6 +911,9 @@
  121. pg_error(sth, -1, "statement not prepared\n");
  122. return -2;
  123. }
  124. +
  125. + if (_dbd_begin(sth, imp_dbh) == 0)
  126. + return -2;
  127. max_len = strlen(imp_sth->statement)+1;
  128. /* do we have input parameters ? */
  129. Index: DBD-Pg-1.31/dbdimp.h
  130. --- DBD-Pg-1.31/dbdimp.h.orig 2003-03-31 19:52:39.000000000 +0200
  131. +++ DBD-Pg-1.31/dbdimp.h 2003-11-21 20:53:09.000000000 +0100
  132. @@ -28,6 +28,7 @@
  133. #ifdef is_utf8_string
  134. int pg_enable_utf8; /* should we attempt to make utf8 strings? */
  135. #endif
  136. + int pg_need_begin; /* does a begin need to be sent */
  137. struct {
  138. int major;
  139. int minor;
  140. Index: DBD-Pg-1.31/Makefile.PL
  141. --- DBD-Pg-1.31/Makefile.PL.orig 2003-11-21 20:51:13.000000000 +0100
  142. +++ DBD-Pg-1.31/Makefile.PL 2003-11-21 20:51:13.000000000 +0100
  143. @@ -39,7 +39,7 @@
  144. $POSTGRES_INCLUDE = $pg->inc_dir;
  145. $POSTGRES_LIB = $pg->lib_dir;
  146. } elsif ((!$ENV{POSTGRES_INCLUDE} or !$ENV{POSTGRES_LIB}) and $ENV{POSTGRES_HOME}) {
  147. - $POSTGRES_INCLUDE = "$ENV{POSTGRES_HOME}/include";
  148. + $POSTGRES_INCLUDE = "$ENV{POSTGRES_HOME}/include/postgresql";
  149. $POSTGRES_LIB = "$ENV{POSTGRES_HOME}/lib";
  150. } else {
  151. $POSTGRES_INCLUDE = "$ENV{POSTGRES_INCLUDE}";
  152. Index: DBD-Pg-1.31/t/lib/App/Info/RDBMS/PostgreSQL.pm
  153. --- DBD-Pg-1.31/t/lib/App/Info/RDBMS/PostgreSQL.pm.orig 2003-08-15 02:08:05.000000000 +0200
  154. +++ DBD-Pg-1.31/t/lib/App/Info/RDBMS/PostgreSQL.pm 2003-11-29 14:19:42.000000000 +0100
  155. @@ -251,6 +251,9 @@
  156. @{$self}{qw(version major minor patch)} =
  157. ($version, $x, $y, $z);
  158. ## Beta/devel/release candidate versions are treated as patch level "0"
  159. + } elsif ($version =~ /^(\d+)\.(\d+)$/) {
  160. + @{$self}{qw(version major minor patch)} =
  161. + ($version, $1, $2, 0);
  162. } elsif ($version =~ /(\d+)\.(\d+)\w+\d+/) {
  163. @{$self}{qw(version major minor patch)} =
  164. ($version, $1, $2, 0);