fix lockups in script execution. support COPY data in uploaded scripts - cool
authorchriskl <chriskl>
Sun, 23 May 2004 15:55:04 +0000 (15:55 +0000)
committerchriskl <chriskl>
Sun, 23 May 2004 15:55:04 +0000 (15:55 +0000)
BUGS
classes/database/Postgres.php

diff --git a/BUGS b/BUGS
index 9bb473f873fbb97df18ff800e68409dd6706c794..0e6765455ad72aa8f0d4c8609cc6df901dc29ddf 100644 (file)
--- a/BUGS
+++ b/BUGS
@@ -1,4 +1,4 @@
-Internal Bugs List
+       Internal Bugs List
 ------------------
 
 This file is used to track current working tasks - just ignore it!
@@ -24,10 +24,10 @@ NEEDS TESTING
 -------------
 
 * Import
-* Script execution
-* Create view wizard looks buggy
+* Script execution needs to support error handling - make it pass thru adodb layer
+* COPY should work in normal sql screen and sql popup window
+* Create view wizard is buggy
 * alter function on < 7.2 needs testing
 * error on viewing reports page
 * highlight things on the info stats page
 * advanced stats functions
-
index 24625cf162ed5a57716b1c91028dc99dce7400c3..e493e3d91cea346dae3e7cc26b3705442d05e7be 100755 (executable)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres.php,v 1.210 2004/05/23 04:10:19 chriskl Exp $
+ * $Id: Postgres.php,v 1.211 2004/05/23 15:55:04 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -3770,6 +3770,10 @@ class Postgres extends BaseDB {
         * @return Result of final query, false on any failure.
         */
        function executeScript($name) {
+               global $data;
+               
+               // This whole function isn't very encapsulated, but hey...
+               $conn = $data->conn->_connectionID;
                if (!is_uploaded_file($_FILES[$name]['tmp_name'])) return false;
 
                $fd = fopen($_FILES[$name]['tmp_name'], 'r');
@@ -3777,10 +3781,22 @@ class Postgres extends BaseDB {
                
                // Loop over each line in the file
                while (!feof($fd)) {
-                 $sql = fgets($fd, 32768);
-                 // Execute the query, ignoring errors for the time being
-                 // XXX: This needs to handle COPY to and from
-                 $res = @pg_query($sql);
+                       $sql = fgets($fd, 32768);
+                       // Check that the query is something...
+                       if (trim($sql) == '') continue;
+                       // Execute the query
+                       $res = pg_query($conn, $sql);
+                       // Check for COPY request
+                       if (pg_result_status($res) == 4) { // 4 == PGSQL_COPY_FROM
+                               while (!feof($fd)) {
+                                       $copy = fgets($fd, 32768);
+                                       pg_put_line($conn, $copy);
+                                       if ($copy == "\\.\n" || $copy == "\\.\r\n") {
+                                               pg_end_copy($conn);
+                                               break;
+                                       }
+                               }
+                       }
                }
                
                fclose($fd);