Wedge
Public area => Bug reports => The Pub => Archived fixes => Topic started by: live627 on August 23rd, 2013, 04:13 PM
-
I need to specify my own size fur floats (18,15) and cannot rely on the defaults (10,2).
/Sources/Class-DBPackages.php (working copy)
@@ -88,8 +88,16 @@
$default = '';
// Sort out the size... and stuff...
- $column['size'] = isset($column['size']) && is_numeric($column['size']) ? $column['size'] : null;
+ if (isset($column['size']))
+ {
+ $s = array_filter(explode(',', $column['size']), 'is_numeric');
+ if (!empty($s))
+ $column['size'] = implode(',', $s);
+ else
+ $column['size'] = null;
+ }
+
// Allow unsigned integers
$unsigned = in_array($column['type'], array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && !empty($column['unsigned']) ? 'unsigned ' : '';
@@ -141,8 +149,16 @@
if (!isset($current_columns[$column['name']]))
{
// The column is new, add it to the list of columns to be added
- $column['size'] = isset($column['size']) && is_numeric($column['size']) ? $column['size'] : null;
+ if (isset($column['size']))
+ {
+ $s = array_filter(explode(',', $column['size']), 'is_numeric');
+ if (!empty($s))
+ $column['size'] = implode(',', $s);
+ else
+ $column['size'] = null;
+ }
+
// Allow unsigned integers
$unsigned = in_array($column['type'], $numeric_types) && !empty($column['unsigned']) ? 'unsigned ' : '';
@@ -160,8 +176,16 @@
else
{
// The column already exists, does it need changing?
- $column['size'] = isset($column['size']) && is_numeric($column['size']) ? $column['size'] : null;
+ if (isset($column['size']))
+ {
+ $s = array_filter(explode(',', $column['size']), 'is_numeric');
+ if (!empty($s))
+ $column['size'] = implode(',', $s);
+ else
+ $column['size'] = null;
+ }
+
// Allow unsigned integers
$unsigned = in_array($column['type'], $numeric_types) && !empty($column['unsigned']) ? 'unsigned ' : '';
The above code does not break anything as per my tests.
Before, only numeric type sizes were allowed. Now, the same is allowed within any number of commas.
-
There's a reason that such things are excluded.
What are you doing with floats of that precision? Are you doing maths on them? Do you worry about loss of precision?
-
I'm storing latitude and longitude of pins on a Google map. Needs precision, as you may imagine. Also, not doing any math, other than looking for exact matches.
-
Then use a string column.
ETA: As a general rule, only store numbers when you need them to be numbers because you're doing work on them in some fashion. For example counts of things, or numeric ids (because they are still a mathematical concept at that point)
When I built it for Crossing Overland, that's exactly what I did, stored them as varchars. There's no risk of loss of accuracy.