MedicOneSystems / livewire-datatables

Advanced datatables using Laravel, Livewire, Tailwind CSS and Alpine JS
https://livewire-datatables.com/
MIT License
1.19k stars 258 forks source link

SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type bigint: "" #345

Open aswin-ghosh-chenattil opened 2 years ago

aswin-ghosh-chenattil commented 2 years ago

I got the error - 'SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type bigint: "" ' while adding callback with multiple values

This gives error
------------------------
Column::callback(['name', 'test_id'], function ($name, $test_id) {
    return view('companies::livewire.companies-table-edit-action', [
        'name' => $name,
        'test_id' => $test_id
]);
This works fine
-------------------------
Column::callback(['name', 'address'], function ($name, $address) {
    return view('companies::livewire.companies-table-edit-action', [
        'name' => $name,
        'address' => $address
]);
This works fine
-------------------------
Column::callback(['test_id'], function ($test_id) {
    return view('companies::livewire.companies-table-edit-action', [
        'test_id' => $test_id
]);
miroc commented 2 years ago

I have the same problem, the problem occurs when I query ID column in postgre DB:

Column::callback(["id", 'name'], function ($id, $name) {
                return view('datatables::link', [
                    'href' => "/" . (string) $id,     
                    'slot' => ucfirst($name)
                ]);
            })

When I query id column alone, it works.

carlinchisart commented 1 year ago

Hi all, i found a solution for this, the problem is in postgresql, i search the function when create the CONCAT_WS and evaluate the id field to put a number , not a empty string in the coalesce function.

the file is: vendor/mediconesystems/livewire-datatables/src/Http/Livewire/LivewireDatatable.php

the line is: 351

return $selects->count() > 1
            ? new Expression("CONCAT_WS('" . static::SEPARATOR . "' ," .
            collect($selects)->map(function ($select) {
                $second = '';
                if(strpos($select,'.id') != false){
                    $second = '0';
                }
                return 'COALESCE(' . $this->tablePrefix . $select . ', \''.$second.'\')';
            })->join(', ') . ')')
            : $selects->first();

this solution work but is very bad, i think the best solution is check de type of column.