Revision: 1395
http://mrbs.svn.sourceforge.net/mrbs/?rev=1395&view=rev
Author: cimorrison
Date: 2010-07-27 10:16:41 +0000 (Tue, 27 Jul 2010)
Log Message:
-----------
Improved the fix for the Rev 1387 problem. A new key, 'is_nullable', has been
added to the array returned by sql_field_info() and this is used to determine
whether NULL or 0 should be written out to the database for integer custom
fields where the user has given no input.
Revision Links:
--------------
http://mrbs.svn.sourceforge.net/mrbs/?rev=1387&view=rev
Modified Paths:
--------------
mrbs/branches/custom_entry_fields/web/dbsys.inc
mrbs/branches/custom_entry_fields/web/mrbs_sql.inc
mrbs/branches/custom_entry_fields/web/mysql.inc
mrbs/branches/custom_entry_fields/web/pgsql.inc
Modified: mrbs/branches/custom_entry_fields/web/dbsys.inc
===================================================================
--- mrbs/branches/custom_entry_fields/web/dbsys.inc 2010-07-26 15:49:33 UTC
(rev 1394)
+++ mrbs/branches/custom_entry_fields/web/dbsys.inc 2010-07-27 10:16:41 UTC
(rev 1395)
@@ -568,6 +568,7 @@
// differences between MySQL and PostgreSQL type names.
// 'length' the maximum length of the field in bytes, octets or
characters
// (Note: this could be NULL)
+// 'is_nullable' whether the column can be set to NULL (boolean)
//
// NOTE: the type mapping is incomplete and just covers the types commonly
// used by MRBS
Modified: mrbs/branches/custom_entry_fields/web/mrbs_sql.inc
===================================================================
--- mrbs/branches/custom_entry_fields/web/mrbs_sql.inc 2010-07-26 15:49:33 UTC
(rev 1394)
+++ mrbs/branches/custom_entry_fields/web/mrbs_sql.inc 2010-07-27 10:16:41 UTC
(rev 1395)
@@ -299,17 +299,10 @@
case 'integer':
if (!isset($data['custom_fields'][$key]) ||
($data['custom_fields'][$key] === ''))
{
- // If the field length is greater than 2 bytes then this is a
genuine
- // integer and we will write NULL to the database. We need
to do this
- // because in many cases we will want to distinguish between
NULL (no
- // value has yet been assigned) and 0 (no units of this
resource are
- // required.
- //
- // However if the field length is 2 bytes or less then it is
to be treated
- // as a boolean and we only represent the values TRUE (1) or
FALSE (0).
- // So we will write out the value 0 rather than NULL in case
the database
- // field has been set to "NOT NULL".
- $value = ($field['length'] > 2) ? 'NULL' : 0;
+ // Try and set it to NULL when we can because there will be
cases when we
+ // want to distinguish between NULL and 0 - especially when
the field
+ // is a genuine integer.
+ $value = ($field['is_nullable']) ? 'NULL' : 0;
}
else
{
Modified: mrbs/branches/custom_entry_fields/web/mysql.inc
===================================================================
--- mrbs/branches/custom_entry_fields/web/mysql.inc 2010-07-26 15:49:33 UTC
(rev 1394)
+++ mrbs/branches/custom_entry_fields/web/mysql.inc 2010-07-27 10:16:41 UTC
(rev 1395)
@@ -340,6 +340,7 @@
// differences between MySQL and PostgreSQL type names.
// 'length' the maximum length of the field in bytes, octets or
characters
// (Note: this could be NULL)
+// 'is_nullable' whether the column can be set to NULL (boolean)
//
// NOTE: the type mapping is incomplete and just covers the types commonly
// used by MRBS
@@ -403,11 +404,14 @@
{
$length = NULL;
}
+ // Convert the is_nullable field to a boolean
+ $is_nullable = (strtolower($row['Null']) == 'yes') ? TRUE : FALSE;
$fields[$i]['name'] = $name;
$fields[$i]['type'] = $type;
$fields[$i]['nature'] = $nature;
$fields[$i]['length'] = $length;
+ $fields[$i]['is_nullable'] = $is_nullable;
}
}
return $fields;
Modified: mrbs/branches/custom_entry_fields/web/pgsql.inc
===================================================================
--- mrbs/branches/custom_entry_fields/web/pgsql.inc 2010-07-26 15:49:33 UTC
(rev 1394)
+++ mrbs/branches/custom_entry_fields/web/pgsql.inc 2010-07-27 10:16:41 UTC
(rev 1395)
@@ -374,6 +374,7 @@
// differences between MySQL and PostgreSQL type names.
// 'length' the maximum length of the field in bytes, octets or
characters
// (Note: this could be NULL)
+// 'is_nullable' whether the column can be set to NULL (boolean)
//
// NOTE: the type mapping is incomplete and just covers the types commonly
// used by MRBS
@@ -395,7 +396,8 @@
$fields = array();
$res = sql_pgsql_query("SELECT column_name, data_type, numeric_precision,
- character_maximum_length,
character_octet_length
+ character_maximum_length,
character_octet_length,
+ is_nullable
FROM information_schema.columns
WHERE table_name ='$table'
ORDER BY ordinal_position");
@@ -420,11 +422,14 @@
{
$length = $row['character_octet_length'];
}
+ // Convert the is_nullable field to a boolean
+ $is_nullable = (strtolower($row['is_nullable']) == 'yes') ? TRUE : FALSE;
$fields[$i]['name'] = $name;
$fields[$i]['type'] = $type;
$fields[$i]['nature'] = $nature;
$fields[$i]['length'] = $length;
+ $fields[$i]['is_nullable'] = $is_nullable;
}
}
return $fields;
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
http://ad.doubleclick.net/clk;226879339;13503038;l?
http://clk.atdmt.com/CRS/go/247765532/direct/01/
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits