]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-17129 dml/ddl: improved ddl exceptions when changing db structure
authorskodak <skodak>
Wed, 5 Nov 2008 10:45:45 +0000 (10:45 +0000)
committerskodak <skodak>
Wed, 5 Nov 2008 10:45:45 +0000 (10:45 +0000)
lib/ddl/database_manager.php
lib/ddllib.php
lib/dml/moodle_database.php

index 6de10698b7a1933f698b26ebc20d949b92a27a86..56a42157d33f91e0d28446b2cb7fb4f309445a85 100644 (file)
@@ -77,11 +77,12 @@ class database_manager {
      * @exception ddl_exception if error found
      *
      * @param string $command The sql string you wish to be executed.
-     * @return vaoid
+     * @return void
      */
     protected function execute_sql($sql) {
         if (!$this->mdb->change_database_structure($sql)) {
-            throw new ddl_exception('ddlexecuteerror', NULL, $this->mdb->get_last_error());
+            // in case driver does not throw exceptions yet ;-)
+            throw new ddl_change_structure_exception($this->mdb->get_last_error(), $sql);
         }
     }
 
index ea8b9daa088463a54401a75365dfca8eb92af189..a8dc6a02b9b3dc4d0dae2ddeb794831348f2833c 100644 (file)
@@ -84,4 +84,19 @@ class ddl_field_missing_exception extends ddl_exception {
         $a->tablename = $tablename;
         parent::__construct('ddlfieldnotexist', $a, $debuginfo);
     }
-}
\ No newline at end of file
+}
+
+/**
+ * Error during changing db structure
+ */
+class ddl_change_structure_exception extends ddl_exception {
+    public $error;
+    public $sql;
+
+    function __construct($error, $sql=null) {
+        $this->error = $error;
+        $this->sql   = $sql;
+        $errorinfo   = s($error).'<br /><br />'.s($sql);
+        parent::__construct('ddlexecuteerror', NULL, $errorinfo);
+    }
+}
index 6a33192acdf7301044eea4077a2a01867a47717d..4c4fa7437329e84307bd3a5899e480d29e47e352 100644 (file)
@@ -285,8 +285,10 @@ abstract class moodle_database {
                 throw new dml_read_exception($this->get_last_error(), $this->last_sql, $this->last_params);
             case SQL_QUERY_INSERT:
             case SQL_QUERY_UPDATE:
-            case SQL_QUERY_STRUCTURE:
                 throw new dml_write_exception($this->get_last_error(), $this->last_sql, $this->last_params);
+            case SQL_QUERY_STRUCTURE:
+                $this->get_manager(); // includes ddl exceptions classes ;-)
+                throw new ddl_change_structure_exception($this->get_last_error(), $this->last_sql);
         }
     }