@@ -1028,45 +1028,47 @@ protected function applyScoutSearch(string $search_keyword): bool
10281028 protected function applyFixedOrderingToQuery (string $ keyName , array $ orderedKeys )
10291029 {
10301030 $ connection = $ this ->getConnection ();
1031- $ driver_name = $ connection ->getDriverName ();
1031+ $ driverName = $ connection ->getDriverName ();
10321032
10331033 // Escape keyName and orderedKeys
1034- $ rawKeyName = $ keyName ;
1035- $ keyName = $ connection ->escape ($ keyName );
1034+ $ keyName = $ connection ->getQueryGrammar ()->wrap ($ keyName );
10361035 $ orderedKeys = collect ($ orderedKeys )
10371036 ->map (function ($ value ) use ($ connection ) {
10381037 return $ connection ->escape ($ value );
10391038 });
10401039
1041- switch ($ driver_name ) {
1040+ switch ($ driverName ) {
10421041 case 'mysql ' :
1043- // MySQL / MariaDB
10441042 $ this ->query ->orderByRaw ("FIELD( $ keyName, " .$ orderedKeys ->implode (', ' ).') ' );
1043+
10451044 return true ;
10461045
1047- /*
1048- TODO: test implementations, fix if necessary and uncomment
1049- case 'pgsql':
1050- // PostgreSQL
1051- $this->query->orderByRaw("array_position(ARRAY[" . $orderedKeys->implode(',') . "], $keyName)");
1052- return true;
1046+ case 'pgsql ' :
1047+ case 'oracle ' :
1048+ $ this ->query ->orderByRaw (
1049+ 'CASE '
1050+ .
1051+ $ orderedKeys
1052+ ->map (fn ($ value , $ index ) => "WHEN $ keyName= $ value THEN $ index " )
1053+ ->implode (' ' )
1054+ .
1055+ ' END '
1056+ );
10531057
1054- */
1058+ return true ;
10551059
10561060 case 'sqlite ' :
10571061 case 'sqlsrv ' :
1058- // SQLite & Microsoft SQL Server
1059- // Compatible with all SQL drivers (but ugly solution)
1060-
10611062 $ this ->query ->orderByRaw (
1062- "CASE ` $ rawKeyName ` "
1063+ "CASE $ keyName "
10631064 .
10641065 $ orderedKeys
1065- ->map (fn ($ value , $ index ) => "WHEN $ value THEN $ index " )
1066+ ->map (fn ($ value , $ index ) => "WHEN $ value THEN $ index " )
10661067 ->implode (' ' )
10671068 .
1068- " END "
1069+ ' END '
10691070 );
1071+
10701072 return true ;
10711073
10721074 default :
0 commit comments