sebastianbergmann / dbunit

DbUnit port for PHP/PHPUnit.
https://phpunit.de/
Other
225 stars 186 forks source link

Insert through DbUnit_ArrayDataSet with Oracle #165

Closed ElodieBergonnier closed 6 years ago

ElodieBergonnier commented 9 years ago

Hello,

I am trying to initialize an Oracle XE database using a DbUnit_ArrayDataSet into the getDataSet() function.

The table is created using the query below:

CREATE TABLE s_com_pop (
  com varchar(5) DEFAULT '',
  cataeu99 varchar(1) DEFAULT NULL,
  cataeu10 varchar(3) DEFAULT NULL,
  superf FLOAT,
  PRIMARY KEY (com)
) ;

The code below gives the initialization of the table s_com_pop :

    protected function getDataSet ()
    {
        return new Test_DbUnit_ArrayDataSet (
            array(
                's_com_pop' => array(
                    array('com' => '31555', 'cataeu99' => '1', 'cataeu10' => '111', 'superf' => 118.3),
                ),
            )
        );

During the execution, this error is displayed:

COMPOSITE[INSERT] operation failed on query: 
                INSERT INTO s_com_pop
                (com, cataeu99, cataeu10, superf)
                VALUES
                (?, ?, ?, ?)
             using args: Array
(
    [0] => 31555
    [1] => 1
    [2] => 111
    [3] => 118.3
)
 [SQLSTATE[HY000]: General error: 1722 OCIStmtExecute: ORA-01722: invalid number
 (ext\pdo_oci\oci_statement.c:148)]

So far, I have been able to track the issue to the 118.3 value. When I use an integer value (ex : 118), the query is correctly executed. So my guess is that the float value 118.3 is somehow converted to string during the process.

Some other clues:

Best regards,

elazar commented 9 years ago

Offhand, I'm not seeing any reason why the float would be cast to a string. If you pass the values of $query and $args to var_dump() around this line, you should be able to double-check the data type. Please include that output here and we can proceed from there.

ElodieBergonnier commented 9 years ago

Thank you for your quick answer.

Here is the output:

query = 
                INSERT INTO s_com_pop
                (com, cataeu99, cataeu10, superf)
                VALUES
                (?, ?, ?, ?)

args = array(4) {
  [0]=>
  string(5) "31555"
  [1]=>
  string(1) "1"
  [2]=>
  string(3) "111"
  [3]=>
  float(118.3)
}

The 118.3 value is correctly stored as float. The problem should be elsewhere...

stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had activity within the last 60 days. It will be closed after 7 days if no further activity occurs. Thank you for your contributions.

stale[bot] commented 6 years ago

This issue has been automatically closed because it has not had activity since it was marked as stale. Thank you for your contributions.