yajra / laravel-oci8

Oracle DB driver for Laravel via OCI8
https://yajrabox.com/docs/laravel-oci8
MIT License
830 stars 237 forks source link

[5.3] ORA-01438: value larger than specified precision allowed for this column. #248

Closed johdougss closed 1 year ago

johdougss commented 7 years ago

Error:

  1. ORA-01438: value larger than specified precision allowed for this column.
    • The id column generated by migrate number (10)
    • If I increase the size (32) of the column the assigned value is 1971389988927 and not the id 25 image

image

In OracleProcessador.php If I change the code and return only PDO:PARAM_STR the insert works

private function getPdoType( $value ) {
      return PDO::PARAM_STR;
}

or convert values to string in bindValues

private function bindValues( &$values, $statement, $parameter ) {
        $count = count( $values );
        for ( $i = 0; $i < $count; $i++ ) {
            if ( is_object( $values[ $i ] ) ) {
                $values[ $i ] = (string)$values[ $i ];
            }
            if ( is_bool( $values[ $i ] ) ) {
                $values[ $i ] = (string)$values[ $i ];
            }
            if ( is_int( $values[ $i ] ) ) {
                $values[ $i ] = (string)$values[ $i ];
            }
            $type = $this->getPdoType( $values[ $i ] );
            $statement->bindParam( $parameter, $values[ $i ], $type );
            $parameter++;
        }
        return $parameter;
    }

But this is not the correct implementation. Is it missing any configuration in the database to accept the pdo typing?

Migration:

Schema::create( 'schedules', function ( Blueprint $table ) {
    $table->increments( 'id' );
    $table->string( 'name', 63 )->nullable();
} );

Table created: image

Create Sequence:

create sequence schedules_id_seq
minvalue 1
maxvalue 9999999999
start with 1
increment by 1
nocache
cycle;

Model:

class Schedule extends Model {

    protected $table = 'schedules';

    public $sequence = 'schedules_id_seq';

    protected $dates = [
        'updated_at',
        'created_at',
        'previous_planned_run',
        'previous_run',
        'next_planned_run',
    ];

    protected $fillable = [
        'id',
        'name',
        'description',
        'command',
        'cron',
        'filename_log',
        'active',
        'updated_at',
        'created_at',
        'previous_planned_run',
        'previous_run',
        'next_planned_run',
    ];

    protected $casts = [
        'active' => 'boolean',
    ];
    ....

Save model:

$schedule = new Schedule();
$schedule->name = 'xx';
$schedule->save();

Query Generate

 insert into "SCHEDULES4" ("ACTIVE", "ID") values (?, ?) returning "ID" into ?
$binding =  [0,25,2] 

Composer.json:

"laravel/framework": "5.3.*",
    "yajra/laravel-oci8": "5.3.*"

php 5.6.21 extension - php_oci8_11g.dll - File version 5.6.24 Oracle 11.2.0.1.0

yajra commented 7 years ago

I tried to replicate the issue on Laravel 5.4 and it's all working fine on my side. Will try to setup Laravel 5.3 when I had the chance. This might be an issue on 5.3. Thanks!

yajra commented 7 years ago

BTW, if you can, please do not hesitate a PR for a possible fix if this is indeed a bug. Thanks!

sciracioglu commented 7 years ago

do you use zend server?

spsaravananct commented 3 years ago

Same error am also getting @johnathansantos found solution?

khactrung0902 commented 2 years ago

I also got the same error https://github.com/yajra/laravel-oci8/issues/552

khactrung0902 commented 2 years ago

Solved by changing oci8 version from 2.0.10 to 2.0.8

github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 1 year ago

This issue was closed because it has been inactive for 7 days since being marked as stale.