Skip to content

Bug: The selected data type from Entity or QueryBuilder is defferent from DB field type. #7259

Description

@kai890707

PHP Version

8.1

CodeIgniter4 Version

4.1.5

CodeIgniter4 Installation Method

Git

Which operating systems have you tested for this bug?

Linux

Which server did you use?

cli

Database

MariaDB 10.1

What happened?

The data type selected is different from the DB field type.
For example, if you use a migrate file to define a field type as INTEGER or FLOAT, and then execute php spark migrate on the database to create a table, the data type returned using Query Builder will be different from the type initially set.

Steps to Reproduce

  1. Use Migration make a migrate file.
  2. addField into mugrate file.
          $this->forge->addField([
            'is_string'    => [
                'type'           => 'VARCHAR',
                'constraint'     => 30,
                'comment'        => "is_string"
            ],
            'is_integer'   => [
                'type'           => 'INT',
                'constraint'     => 30,
                'comment'        => "is_integer"
            ],
            'is_float'   => [
                'type'           => 'FLOAT',
                'comment'        => "is_float"
            ],
        ]);
        $this->forge->addKey('is_string', true);
        $this->forge->createTable('CastTable');
  1. Use db query in Controller to get data
$db = \Config\Database::connect();
$queryData = $db->table('CastTable')->get()->getResult();
var_dump($queryData);

4.Get data of the wrong type

array(1) {
  [0]=>
  object(stdClass)#57 (3) {
    ["is_string"]=>
    string(17) "Hi CodeIgniter4 !"
    ["is_integer"]=>
    string(3) "999"
    ["is_float"]=>
    string(5) "9.999"
  }
}

Expected Output

array(1) {
  [0]=>
  object(stdClass)#57 (3) {
    ["is_string"]=>
    string(17) "Hi CodeIgniter4 !"
    ["is_integer"]=>
    int(999)
    ["is_float"]=>
    float(9.999)
  }
}

Anything else?

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions