Piotr Pokora schrieb:
Piotr Pokora <[EMAIL PROTECTED]> wrote:
DB: 80.3, Midgard value: 80,300003
DB: 1736.40649, Midgard value: 1736.406494
The dbtype of the property is double, the type is float. The same thing
happens when both dbtype and type are set to float. Plus, it happens
with straight Midgard objects (on 1.8.4, PHP5.2, Debian Testing and
openSuse 10.2), i.e. it doesn't seem to have anything to do with MidCOM.
Can you describe table?
XML:
<type name="de_ccb_presets_currency" table="de_ccb_presets_currency_db">
<property name="id" type="integer" primaryfield="id" />
<property name="title" type="text" />
<property name="symbol" type="text" />
<property name="rate" type="float" dbtype="double" />
</type>
SQL:
CREATE TABLE de_ccb_presets_currency_db
(
id INT(11) NOT NULL auto_increment,
title VARCHAR(255) NOT NULL DEFAULT '',
symbol VARCHAR(255) NOT NULL DEFAULT '',
rate DOUBLE NOT NULL DEFAULT '0',
sitegroup INT(11) NOT NULL default 0,
guid varchar(80) NOT NULL default '',
PRIMARY KEY (id)
);
Did you try to debug queries to see if value used in SQL is correct?
I ran the following code:
<?php
$c = new de_ccb_presets_currency();
$c->title = "test";
$c->symbol = "T";
$c->rate = 1736.40649;
mgd_debug_start();
$c->create();
mgd_debug_stop();
?>
and got this debug output:
midgard-php (pid:4450):(info): create(...)
midgard-core (pid:4450):(DEBUG): query=SELECT limit_sg_records, sg_records
FROM quota WHERE typename='' and sitegroup=1
midgard-core (pid:4450):(DEBUG): query=INSERT INTO de_ccb_presets_currency_db
SET title='test', symbol='T', rate=1736.406494,
guid='1dc5f97be2a0d3a5f9711dcb16523d5537e3b8c3b8c',sitegroup=1,metadata_creator='1dc33aa5751512c33aa11dc8da7a5c425fb49a449a4',
metadata_created='2007-09-10 12:17:04+0000', metadata_revised='2007-09-10
12:17:04+0000', metadata_revision=0,
metadata_revisor='1dc33aa5751512c33aa11dc8da7a5c425fb49a449a4',
metadata_size=90 ,metadata_locker='' ,metadata_locked='' ,metadata_approver='' ,metadata_approved='' ,metadata_authors='' ,metadata_owner='' ,metadata_schedule_start='' ,metadata_schedule_end='' ,metadata_hidden=0 ,metadata_nav_noentry=0 ,metadata_published='2007-09-10
12:17:04+0000' ,metadata_score=0
midgard-core (pid:4450):(DEBUG): query=SELECT metadata_size FROM
de_ccb_presets_currency_db WHERE id=5 AND sitegroup=1
midgard-core (pid:4450):(DEBUG): query=SELECT limit_sg_size, sg_size FROM
quota WHERE typename='' and sitegroup=1
midgard-core (pid:4450):(DEBUG): query=INSERT INTO repligard SET
realm='de_ccb_presets_currency_db',
guid='1dc5f97be2a0d3a5f9711dcb16523d5537e3b8c3b8c', changed=NULL,
action='create', typename='de_ccb_presets_currency', id=5, sitegroup=1,
object_action = 3
midgard-core (pid:4450):(DEBUG): Object de_ccb_presets_currency created with
id=5
Quote from MySQL docs (
http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html ):
"For example, a column defined as FLOAT(7,4) will look like -999.9999 when
displayed.
MySQL performs rounding when storing values, so if you insert 999.00009 into
a FLOAT(7,4)
column, the approximate result is 999.0001."
OK, but in that case it's clear: The value they enter is one digit
longer than the precision for the field, so the excess gets rounded, but
my problem is that my numbers don't get shorter when they are saved, but
longer instead. F.x. when I enter 1736.40649 in a field which has FLOAT
defined, it gets rounded to 1736.41 in the database, which is ok. But
then, when I read the Midgard object, it becomes 1736.410034, which
doesn't really make sense.
When I enter 1736.40649 in a field with the type DOUBLE, it becomes
1736.406494, which is also not rounded, but simply slightly different.
Out of curiosity, I tried entering 1736.40649 in phpMyAdmin, and there,
it is saved and displayed correctly, so it doesn't seem to be a general PHP
problem. And when I then display the value in Midgard, it becomes 1736.406494
again
Can you also try to alter table so it should modify this column to
FLOAT(7,7) ?
I tried, but I seem to have messed something up, because with FLOAT(7,7), I
cannot save values greater than one. Midgard doesn't do anything and in
phpMyAdmin I get "Warning: #1264 Out of range value adjusted for
column 'rate' at row 1"
Bye,
Andreas
Piotras
_______________________________________________
user mailing list
[email protected]
http://lists.midgard-project.org/mailman/listinfo/user
_______________________________________________
user mailing list
[email protected]
http://lists.midgard-project.org/mailman/listinfo/user