Welcome Guest, Not a member yet? Register   Sign In
DB values returning as wrong types
#1

[eluser]Phil Sturgeon[/eluser]
Values stored in the database as integers or floats are being returned as strings. I can understand why, but it shouldn't happen. It really messes with my function overloading Confusedhut:
#2

[eluser]Derek Allard[/eluser]
What's the bug report? How are you inserting and then removing?
#3

[eluser]Phil Sturgeon[/eluser]
Just any normal Active Record return using get(), do a var_dump on the results and you will see any number from the database returns as a string. I think the database library just assumes everything is a string, and doesn't treat integers, floats, decimals, etc any differently.

I know PHP is not a type-based language, and for most actions this doesn't make any different. But if you are making models that do get_type on the params, and try to act differently according to the type, you will get bumped as any number passed as an argument from the database will show as a string.
#4

[eluser]m4rw3r[/eluser]
I think that the PHP extensions that handle the database connections always returns strings.
But I'm not sure.
#5

[eluser]Derek Allard[/eluser]
Hm, can you typecast?

Code:
$mynumber = (int)$this->db->get('table')->row()->number_field;
#6

[eluser]Phil Sturgeon[/eluser]
Yea that's what I'm doing at the moment, but it's not too sexy in my controllers. The reason I was trying type based function parameters was to keep controller code down to a minimum.

It's not a major issue, just wondering if it can be easily addressed.
#7

[eluser]Phil Sturgeon[/eluser]
And yea after looking into it is a "bug" in mysql_fetch_object(). Looks like the only way to do it would be to look through every field, check the type then overwrite it after a typecast... not fun on the CPU, sod that.




Theme © iAndrew 2016 - Forum software by © MyBB