Details
-
Type:
Improvement
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 2.0.5
-
Fix Version/s: None
-
Component/s: Drivers
-
Labels:None
Description
SQL statements may contain question marks in strings, inline comments or comment blocks. The current implementation of the method "convertPositionalToNamedPlaceholders()" doesn't consider these implications and falsely replaces them by named bind variables.
Replacement code with example:
<?php $s = '-- Testkomm?ntar select /* ? *//* ??? */ ?||\'H"al?l"o?\' as "h?""llo" union /* "? Kommentar" \' */ /* ?" */ select \'/*Hallo\'||to_char( ? ) union select \'--Welt\' union-- select ?'; echo 'In: ' . $s . PHP_EOL; $bind = 0; $skip = array( '--' => PHP_EOL, '/*' => '*/', '"' => '"', "'" => "'" ); for( $i = 0; $i < strlen( $s ) /* size of string might change! */; /* yes, no increment here! */ ) { // Skipping comments and literals foreach( $skip as $begin => $end ) { $matches = substr_compare( $s, $begin, $i, strlen( $begin ) ); if( $matches !== false && $matches == 0 ) { $pos = strpos( $s, $end, $i+strlen( $begin ) ); // echo "Found $begin, skipping at $i to $end at $pos" . PHP_EOL; if( $pos === false ) { // No more data or illegal statement - anyway: no more replacements! // echo "EOD" . PHP_EOL; break 2; } $i = $pos + strlen( $end ); continue 2; // Ensure we match /*..*//*..*/, '''' or """" - that's why we don't ++$i in the for-loop! } } if( $s[$i] == "?" ) { // Positional to named // echo "Replace $bind" . PHP_EOL; $r = ':name' . ++$bind; $s = substr_replace( $s, $r, $i, 1 ); $i += strlen( $r ); } ++$i; } echo 'Out: ' . $s . PHP_EOL;
Activity
Benjamin Eberlei
made changes -
| Field | Original Value | New Value |
|---|---|---|
| Workflow | jira [ 12654 ] | jira-feedback2 [ 17574 ] |
Benjamin Eberlei
made changes -
| Workflow | jira-feedback2 [ 17574 ] | jira-feedback3 [ 19928 ] |
This list may be incomplete, as errors occurred whilst retrieving source from linked applications:
- Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DBAL-124, expand=changesets[-21:-1].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)
This algorithmus is painfully slow. There has to be something better, why do you need to foreach the loop inside the for?