laravel-db2
laravel-db2 copied to clipboard
Problem sending query that contains § char
Hi,
I have a problem running querys that contains char §.
The DB2 instance contins table with column names that contains § char for example CLM$§1
.
when i try to execute the query the following query, laravel returns sql error
DB::connection('ibmi')
->table('ST3SFA.TSTCLM$F')
->selectRaw('
TRIM(CAST(CLM$§1 AS VARCHAR(255))) AS id
,TRIM(CAST(CLM$02 AS VARCHAR(255))) AS description
,TRIM(CAST(ECLM05 AS VARCHAR(255))) AS super_calss_id
,CASE WHEN TRIM(CAST(CLM$96 AS VARCHAR(255))) = \'\' THEN CAST(NULL as VARCHAR(255)) ELSE CURRENT_TIMESTAMP END AS deleted_at
')
->orderByRaw('TRIM(CAST(CLM$§1 AS VARCHAR(255)))')
->chunk(10, function ($lines) {
foreach ($lines as $line) {
$result = [
'id'=>ucfirst(strtolower($line->id)),
'description'=>ucfirst(strtolower($line->description)),
'super_calss_id'=>ucfirst(strtolower($line->super_calss_id)),
'deleted_at'=>$line->deleted_at,
];
dump($result);
}
});
Error:
Illuminate\Database\QueryException
SQLSTATE[42000]: Syntax error or access violation: 0 (SQLPrepare[0] at /builddir/build/BUILD/php-7.3.14/ext/pdo_odbc/odbc_driver.c:204) (SQL: select TRIM(CAST(CLM$§1 AS VARCHAR(255))) AS id ,TRIM(CAST(CLM$02 AS VARCHAR(255))) AS description ,TRIM(CAST(ECLM05 AS VARCHAR(255))) AS super_calss_id ,CASE WHEN TRIM(CAST(CLM$96 AS VARCHAR(255))) = '' THEN CAST(NULL as VARCHAR(255)) ELSE CURRENT_TIMESTAMP END AS deleted_at from ST3SFA.TSTCLM$F order by TRIM(CAST(CLM$§1 AS VARCHAR(255))) FETCH FIRST 10 ROWS ONLY)
I have tried to enable 'UNICODESQL' => 1,
and 'DEBUG' => 65536,
in the cfg but without success.
If i try to execute the same query wituout specifying column names and using the *
DB::connection('ibmi')
->table('ST3SFA.TSTCLM$F')
->selectRaw('*')
->get();
the result is returned but the colun is not accessible sing it contains $ in the name. Anyone has faced this kind of problem before? Thanks in advance Riccardo
Hi, I have the same problem with (Ñ) character, my temporal solution is add utf8_decode(COLUMN) in my where method:
Wodetal2::where('WDSERV','BAS') ->where(utf8_decode('WDCURÑ'),'2') ->where('WDMRC$','>',0) ->get();
i think this is a problem with driver, in other librarys like adodb php i have to do the same utf8_decode in my sql instrucction to work.
if you have a other best solution i want to know.