Welcome Guest, Not a member yet? Register   Sign In
$this->db->field_data() max_length
#1

[eluser]jtkendall[/eluser]
Hi,

I'm working on a application that uses $this->db->field_data() to get the field meta-data of a MySQL table (MyISAM storage engine). However when I check the results, max_length is always 0 even though my fields have lengths (at least for blob, string, and int types (as returned by the function), I haven't tested any others).

I could be completely wrong in my understanding of how this works (script or DB wise), but if I have a length set for my fields, shouldn't it show up in the returned data? I've never used this function (or even attempted the same thing outside of CI).

I've attached a screen-shot of my table's setup.
#2

[eluser]jtkendall[/eluser]
I just noticed it's also not returning the defaults.
#3

[eluser]Randy Casburn[/eluser]
Let's see the code.
#4

[eluser]jtkendall[/eluser]
I'm just doing the same thing as what's in the user guide. Though in the user guide it doesn't state that the field's default will be in the meta data, even though when I print the object it's there.

This is just a quick example of the code. All I do after this step is run a foreach on the fields variable and send the field metadata to another method. But that doesn't effect the object.

Code:
public function test()
{
    $fields = $this->db->field_data('test');
    echo '<pre>';
    print_r($fields);    
    echo '</pre>';
}

I was testing to see what each field type (name key in this case) returned as it's actual type and this is what's returned:

Code:
Array
(
    [0] => stdClass Object
        (
            [name] => id
            [type] => int
            [default] =>
            [max_length] => 0
            [primary_key] => 1
        )

    [1] => stdClass Object
        (
            [name] => tinyint
            [type] => int
            [default] =>
            [max_length] => 0
            [primary_key] => 0
        )

    [2] => stdClass Object
        (
            [name] => smallint
            [type] => int
            [default] =>
            [max_length] => 0
            [primary_key] => 0
        )

    [3] => stdClass Object
        (
            [name] => mediumint
            [type] => int
            [default] =>
            [max_length] => 0
            [primary_key] => 0
        )

    [4] => stdClass Object
        (
            [name] => int
            [type] => int
            [default] =>
            [max_length] => 0
            [primary_key] => 0
        )

    [5] => stdClass Object
        (
            [name] => bigint
            [type] => int
            [default] =>
            [max_length] => 0
            [primary_key] => 0
        )

    [6] => stdClass Object
        (
            [name] => float
            [type] => real
            [default] =>
            [max_length] => 0
            [primary_key] => 0
        )

    [7] => stdClass Object
        (
            [name] => decimal
            [type] => real
            [default] =>
            [max_length] => 0
            [primary_key] => 0
        )

    [8] => stdClass Object
        (
            [name] => double
            [type] => real
            [default] =>
            [max_length] => 0
            [primary_key] => 0
        )

    [9] => stdClass Object
        (
            [name] => date
            [type] => date
            [default] =>
            [max_length] => 0
            [primary_key] => 0
        )

    [10] => stdClass Object
        (
            [name] => datetime
            [type] => datetime
            [default] =>
            [max_length] => 0
            [primary_key] => 0
        )

    [11] => stdClass Object
        (
            [name] => timestamp
            [type] => timestamp
            [default] =>
            [max_length] => 0
            [primary_key] => 0
        )

    [12] => stdClass Object
        (
            [name] => time
            [type] => time
            [default] =>
            [max_length] => 0
            [primary_key] => 0
        )

    [13] => stdClass Object
        (
            [name] => year
            [type] => year
            [default] =>
            [max_length] => 0
            [primary_key] => 0
        )

    [14] => stdClass Object
        (
            [name] => char
            [type] => string
            [default] =>
            [max_length] => 0
            [primary_key] => 0
        )

    [15] => stdClass Object
        (
            [name] => varchar
            [type] => string
            [default] =>
            [max_length] => 0
            [primary_key] => 0
        )

    [16] => stdClass Object
        (
            [name] => tinyblob
            [type] => blob
            [default] =>
            [max_length] => 0
            [primary_key] => 0
        )

    [17] => stdClass Object
        (
            [name] => blob
            [type] => blob
            [default] =>
            [max_length] => 0
            [primary_key] => 0
        )

    [18] => stdClass Object
        (
            [name] => text
            [type] => blob
            [default] =>
            [max_length] => 0
            [primary_key] => 0
        )

    [19] => stdClass Object
        (
            [name] => mediumblob
            [type] => blob
            [default] =>
            [max_length] => 0
            [primary_key] => 0
        )

    [20] => stdClass Object
        (
            [name] => mediumtext
            [type] => blob
            [default] =>
            [max_length] => 0
            [primary_key] => 0
        )

    [21] => stdClass Object
        (
            [name] => longblob
            [type] => blob
            [default] =>
            [max_length] => 0
            [primary_key] => 0
        )

    [22] => stdClass Object
        (
            [name] => longtext
            [type] => blob
            [default] =>
            [max_length] => 0
            [primary_key] => 0
        )

    [23] => stdClass Object
        (
            [name] => enum
            [type] => string
            [default] =>
            [max_length] => 0
            [primary_key] => 0
        )

    [24] => stdClass Object
        (
            [name] => set
            [type] => string
            [default] =>
            [max_length] => 0
            [primary_key] => 0
        )

)

As you can see default is empty and max_length is 0. I've set defaults on a few of the fields and all of the string and int fields have a length.
#5

[eluser]Randy Casburn[/eluser]
Don't know...I'm perplexed. What version of MySQL?
#6

[eluser]Randy Casburn[/eluser]
Ah...something else just crossed my mind too. This might be a privilege problem. Is this a production Db server or development? Are you controlling privs? Does the DB user have ALL or restricted. I'm thinking, off the top of my head, that SHOW is likely required. I'll check.

Randy
#7

[eluser]Randy Casburn[/eluser]
Nope...not a privileges issues. All you need is select. Still unsure about the version. I will confirm that you what you have is correct and that CI is working correctly.

MySQL, it seems, is not returning the expected results for some reason. I'm not sure all the information needed has been exposed quite yet. As in, this may be a MySQL configuration issue.

Randy
#8

[eluser]jtkendall[/eluser]
It's a local development server running on my MacBook. MySQL version is 5.0.51b. I'm logged in as root, and I have every available privilege set. I just did a quick test on one of my production servers (running MySQL 5.0) and same results. No defaults and 0 for a max_length.
#9

[eluser]Randy Casburn[/eluser]
Running in strict mode?
#10

[eluser]jtkendall[/eluser]
Nope, not running in strict mode.




Theme © iAndrew 2016 - Forum software by © MyBB