1818use PhpMyAdmin \Util ;
1919
2020use function __ ;
21+ use function array_slice ;
2122use function in_array ;
2223use function substr ;
24+ use function usort ;
2325
2426/**
2527 * Represents a database node in the navigation tree
@@ -350,9 +352,13 @@ private function getTablesOrViews(string $which, int $pos, string $searchClause)
350352 }
351353
352354 $ query .= 'ORDER BY `TABLE_NAME` ASC ' ;
353- $ query .= ' LIMIT ' . $ pos . ' , ' . $ maxItems ;
355+ $ retval = $ dbi -> fetchResult ( $ query ) ;
354356
355- return $ dbi ->fetchResult ($ query );
357+ if ($ config ->settings ['NaturalOrder ' ]) {
358+ usort ($ retval , 'strnatcasecmp ' );
359+ }
360+
361+ return array_slice ($ retval , $ pos , $ maxItems );
356362 }
357363
358364 $ query = ' SHOW FULL TABLES FROM ' ;
@@ -368,20 +374,14 @@ private function getTablesOrViews(string $which, int $pos, string $searchClause)
368374 $ retval = [];
369375 $ handle = $ dbi ->tryQuery ($ query );
370376 if ($ handle !== false ) {
371- $ count = 0 ;
372- if ($ handle ->seek ($ pos )) {
373- while ($ arr = $ handle ->fetchRow ()) {
374- if ($ count >= $ maxItems ) {
375- break ;
376- }
377-
378- $ retval [] = $ arr [0 ];
379- $ count ++;
380- }
381- }
377+ $ retval = $ handle ->fetchAllColumn ();
382378 }
383379
384- return $ retval ;
380+ if ($ config ->settings ['NaturalOrder ' ]) {
381+ usort ($ retval , 'strnatcasecmp ' );
382+ }
383+
384+ return array_slice ($ retval , $ pos , $ maxItems );
385385 }
386386
387387 /**
@@ -438,9 +438,13 @@ private function getRoutines(string $routineType, int $pos, string $searchClause
438438 }
439439
440440 $ query .= 'ORDER BY `ROUTINE_NAME` ASC ' ;
441- $ query .= ' LIMIT ' . $ pos . ' , ' . $ maxItems ;
441+ $ retval = $ dbi -> fetchResult ( $ query ) ;
442442
443- return $ dbi ->fetchResult ($ query );
443+ if ($ config ->settings ['NaturalOrder ' ]) {
444+ usort ($ retval , 'strnatcasecmp ' );
445+ }
446+
447+ return array_slice ($ retval , $ pos , $ maxItems );
444448 }
445449
446450 $ query = 'SHOW ' . $ routineType . ' STATUS WHERE `Db`= ' . $ dbi ->quoteString ($ this ->realName ) . ' ' ;
@@ -454,20 +458,16 @@ private function getRoutines(string $routineType, int $pos, string $searchClause
454458 $ retval = [];
455459 $ handle = $ dbi ->tryQuery ($ query );
456460 if ($ handle !== false ) {
457- $ count = 0 ;
458- if ($ handle ->seek ($ pos )) {
459- while ($ arr = $ handle ->fetchAssoc ()) {
460- if ($ count >= $ maxItems ) {
461- break ;
462- }
463-
464- $ retval [] = $ arr ['Name ' ];
465- $ count ++;
466- }
461+ while ($ arr = $ handle ->fetchAssoc ()) {
462+ $ retval [] = $ arr ['Name ' ];
467463 }
468464 }
469465
470- return $ retval ;
466+ if ($ config ->settings ['NaturalOrder ' ]) {
467+ usort ($ retval , 'strnatcasecmp ' );
468+ }
469+
470+ return array_slice ($ retval , $ pos , $ maxItems );
471471 }
472472
473473 /**
@@ -522,9 +522,13 @@ private function getEvents(int $pos, string $searchClause): array
522522 }
523523
524524 $ query .= 'ORDER BY `EVENT_NAME` ASC ' ;
525- $ query .= 'LIMIT ' . $ pos . ', ' . $ maxItems ;
525+ $ retval = $ dbi ->fetchResult ($ query );
526+
527+ if ($ config ->settings ['NaturalOrder ' ]) {
528+ usort ($ retval , 'strnatcasecmp ' );
529+ }
526530
527- return $ dbi -> fetchResult ( $ query );
531+ return array_slice ( $ retval , $ pos , $ maxItems );
528532 }
529533
530534 $ query = 'SHOW EVENTS FROM ' . Util ::backquote ($ this ->realName ) . ' ' ;
@@ -538,20 +542,16 @@ private function getEvents(int $pos, string $searchClause): array
538542 $ retval = [];
539543 $ handle = $ dbi ->tryQuery ($ query );
540544 if ($ handle !== false ) {
541- $ count = 0 ;
542- if ($ handle ->seek ($ pos )) {
543- while ($ arr = $ handle ->fetchAssoc ()) {
544- if ($ count >= $ maxItems ) {
545- break ;
546- }
547-
548- $ retval [] = $ arr ['Name ' ];
549- $ count ++;
550- }
545+ while ($ arr = $ handle ->fetchAssoc ()) {
546+ $ retval [] = $ arr ['Name ' ];
551547 }
552548 }
553549
554- return $ retval ;
550+ if ($ config ->settings ['NaturalOrder ' ]) {
551+ usort ($ retval , 'strnatcasecmp ' );
552+ }
553+
554+ return array_slice ($ retval , $ pos , $ maxItems );
555555 }
556556
557557 /**
0 commit comments