bgultekin / laravel4-datatables-package

Server-side handler of DataTables Jquery Plugin for Laravel 4
267 stars 108 forks source link

Postgress cast statement missing quotes for table.colum notation ( with solution ) #94

Closed reneweteling closed 6 years ago

reneweteling commented 10 years ago

Hey there,

On Datatables.php:403 you have this

 if( DB::getDriverName() === 'pgsql') {
                            $cast_begin = "CAST(";
                            $cast_end = " as TEXT)";
                        }

only this results in postress errors when you have a column defined like table.field.

 select count(*) as aggregate from (select '1' as row from "user" inner join "user_role" on "user"."id" = "user_role"."user_id" where "user"."deleted_at" is null and "user_role"."office_id" = $1 and "role_id" = $2 and (CAST(user.givenname as TEXT) LIKE $3 or CAST(insertions as TEXT) LIKE $4 or CAST(surname as TEXT) LIKE $5 or CAST(email as TEXT) LIKE $6)) AS count_row_table

if you add come quotes all is well like this

 if( DB::getDriverName() === 'pgsql') {
                            $cast_begin = "CAST('";
                            $cast_end = "' as TEXT)";
                        }

Thanks!

reneweteling commented 10 years ago

added pull, so closing the issue

MarkVaughn commented 10 years ago

Did you test if this breaks mysql?

Mark Vaughn Mobile: +1 (770) 533-2274

On Tue, Apr 15, 2014 at 11:15 AM, Rene Weteling notifications@github.comwrote:

Closed #94https://github.com/bllim/laravel4-datatables-package/issues/94 .

— Reply to this email directly or view it on GitHubhttps://github.com/bllim/laravel4-datatables-package/issues/94 .

reneweteling commented 10 years ago

@MarkVaughn sorry the problem is that the items arent quotet the right way

i ended up using the fix below ( its in the psql section so no harm to other databases )

 if( DB::getDriverName() === 'pgsql') {
                            $cast_begin = 'CAST(';
                            $cast_end = ' as TEXT)';

                            // put the column name in quotes
                            $column = join('.', array_map( function($n){ return '"'.$n.'"'; }, explode('.', $column) ));

                        }
ktunkiewicz commented 10 years ago

There is a related PR #114 about adding escaping column names in mySQL. I will work on this.

ktunkiewicz commented 10 years ago

Added to TO DO list for 1.4.1 release #122

reneweteling commented 6 years ago

Closing due to inactivity