]> git.mjollnir.org Git - moodle.git/commitdiff
Fixes to insert_record for inserting null values.
authormoodler <moodler>
Fri, 24 Jan 2003 07:51:55 +0000 (07:51 +0000)
committermoodler <moodler>
Fri, 24 Jan 2003 07:51:55 +0000 (07:51 +0000)
Also some unfinished changes to table_column ... not recommended for use right now

lib/datalib.php

index f379c7d7a9b406371ba130e343eb90d6cf80bfdd..b616b2292feb3027687a8421304414fcdd4d22f4 100644 (file)
@@ -65,8 +65,8 @@ function modify_database($sqlfile) {
 
 /// FUNCTIONS TO MODIFY TABLES ////////////////////////////////////////////
 
-function table_column($table, $oldfield, $field, $type="INTEGER", 
-                      $signed="UNSIGNED", $default="0", $null="NOT NULL", $after="") {
+function table_column($table, $oldfield, $field, $type="integer", $size="10",
+                      $signed="unsigned", $default="0", $null="not null", $after="") {
 /// Add a new field to a table, or modify an existing one (if oldfield is defined).
     global $CFG;
 
@@ -76,14 +76,11 @@ function table_column($table, $oldfield, $field, $type="INTEGER",
         case "mysqlt":
 
             switch (strtolower($type)) {
-                case "smallint":
-                    $type = "SMALLINT(6)";
-                    break;
                 case "integer":
-                    $type = "INT(10)";
+                    $type = "INTEGER($size)";
                     break;
-                case "bigint":
-                    $type = "INT(10)";
+                case "varchar":
+                    $type = "VARCHAR($size)";
                     break;
             }
 
@@ -106,11 +103,12 @@ function table_column($table, $oldfield, $field, $type="INTEGER",
 
         default:
             switch (strtolower($type)) {
-                case "tinyint":
                 case "integer":
-                case "bigint":
                     $type = "INTEGER";
                     break;
+                case "varchar":
+                    $type = "VARCHAR";
+                    break;
             }
 
             $default = "DEFAULT '$default'";
@@ -489,13 +487,13 @@ function insert_record($table, $dataobject, $returnid=true) {
     foreach ($columns as $column) {
         if ($column->name <> "id") {
             if (isset($data[$column->name])) { 
-                if ($data[$column->name] == "" and !empty($column->has_default)) {
+                if ($data[$column->name] == "" and !empty($column->has_default) and !empty($column->default_value)) {
                     $ddd[$column->name] = $column->default_value;
                 } else {
                     $ddd[$column->name] = $data[$column->name];
                 }
             } else {
-                if (!empty($column->has_default)) {
+                if (!empty($column->has_default) and !empty($column->default_value)) {
                     $ddd[$column->name] = $column->default_value;
                 } 
             }
@@ -570,7 +568,7 @@ function update_record($table, $dataobject) {
 
     // Pull out data matching these fields
     foreach ($columns as $column) {
-        if ($column->name <> "id" && isset($data[$column->name]) ) {
+        if ($column->name <> "id" and isset($data[$column->name]) ) {
             $ddd[$column->name] = $data[$column->name];
         }
     }