From: moodler Date: Fri, 24 Jan 2003 07:51:55 +0000 (+0000) Subject: Fixes to insert_record for inserting null values. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=9223049919b324c028e6f62932b3d405a9587f2a;p=moodle.git Fixes to insert_record for inserting null values. Also some unfinished changes to table_column ... not recommended for use right now --- diff --git a/lib/datalib.php b/lib/datalib.php index f379c7d7a9..b616b2292f 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -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]; } }