rfc:debugging_pdo_prepared_statement_emulation

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
rfc:debugging_pdo_prepared_statement_emulation [2016/10/26 19:04] – reduce to single proposal adambaratzrfc:debugging_pdo_prepared_statement_emulation [2016/11/16 23:03] – fix formatting around discussion links adambaratz
Line 1: Line 1:
 ====== PHP RFC: Debugging PDO Prepared Statement Emulation ====== ====== PHP RFC: Debugging PDO Prepared Statement Emulation ======
-  * Version: 0.3+  * Version: 0.4
   * Date: 2016-10-17   * Date: 2016-10-17
   * Author: Adam Baratz adambaratz@php.net   * Author: Adam Baratz adambaratz@php.net
-  * Status: Under Discussion+  * Status: In Discussion
   * First Published at: https://wiki.php.net/rfc/debugging_pdo_prepared_statement_emulation   * First Published at: https://wiki.php.net/rfc/debugging_pdo_prepared_statement_emulation
  
Line 14: Line 14:
  
 ===== Proposal ===== ===== Proposal =====
-People who use emulated prepared statements should be able to debug them within userland, without using additional tools. PDO already provides some debug functionality in the form of ''PDOStatement::debugDumpParams()''The goal would be to offer another slice on PDO internals, not to create another path for developers to communicate with a database. I propose a new method, ''PDOStatement::activeQueryString()'':+People who use emulated prepared statements should be able to debug them within userland, without using additional tools. PDO already provides some debug functionality in the form of ''PDOStatement::debugDumpParams()''This method would be extended to include the parsed query string:
  
 <code php> <code php>
-$db new PDO(...);+/* Execute a prepared statement by binding PHP variables */ 
 +$calories 150; 
 +$colour = 'red';
  
-// works with statements without bound values +$sth = $dbh->prepare('SELECT name, colour, calories 
-$stmt = $db->query('SELECT 1'); +    FROM fruit 
-var_dump($stmt->activeQueryString()); // =string(8"SELECT 1"+    WHERE calories < ? AND colour = ?'); 
 +$sth->bindParam(1, $calories, PDO::PARAM_INT); 
 +$sth->bindValue(2, $colour, PDO::PARAM_STR); 
 +$sth->execute();
  
-$stmt = $db->prepare('SELECT :string'); +$sth->debugDumpParams();
-$stmt->bindValue(':string', 'foo');+
  
-// returns unparsed query before execution +/*
-var_dump($stmt->activeQueryString()); // => string(14) "SELECT :string"+
  
-// returns parsed query after execution +Output: 
-$stmt->execute(); + 
-var_dump($stmt->activeQueryString()); // => string(11) "SELECT 'foo'"+SQL: [82] SELECT name, colour, calories 
 +    FROM fruit 
 +    WHERE calories < ? AND colour 
 +Parsed SQL: [88] SELECT name, colour, calories 
 +    FROM fruit 
 +    WHERE calories < 150 AND colour = 'red' 
 +Params: 
 +Key: Position #0: 
 +paramno=0 
 +name=[0] "
 +is_param=1 
 +param_type=1 
 +Key: Position #1: 
 +paramno=1 
 +name=[0] "" 
 +is_param=1 
 +param_type=2 
 + 
 +*/
 </code> </code>
  
-Since this would be a debug tool, the method shouldn't affect the state of the ''PDOStatement'' instance. For example, this method shouldn't trigger parsing or errors. You usually don't know something went wrong with the parsing until after execution, anyway. This means the method simply retrieves a value that already exists in memory.+The "Parsed SQL" section will only be shown if the prepared statement emulation is enabled.
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
Line 43: Line 64:
  
 ===== Future Scope ===== ===== Future Scope =====
-It's been suggested that PDO shouldn't allow prepare statement emulation. Since the mssql extension was deprecated in PHP 7 in favor of pdo_dblib, I don't think this is possible. +It's been suggested that PDO shouldn't allow prepare statement emulation. This new functionality would only engage if emulation is enabledso it will self-destruct if emulation is dropped.
- +
-It's been suggested that this change would turn PDO into a leaky (or leakier) abstraction. I'd counter that this is strictly a tool that allows tests to expand their code coverage. If emulated prepared statements are being kept in PDOwe should be able to test the >700 LoC in the associated query parser.+
  
 ===== Proposed Voting Choices ===== ===== Proposed Voting Choices =====
 This project requires a 50%+1 majority. This project requires a 50%+1 majority.
  
-===== Patches and Tests ===== +<doodle title="Debugging PDO Prepared Statement Emulation v0.4" auth="abaratz" voteType="single" closed="false"> 
-A working implementation with tests: https://github.com/php/php-src/pull/2159+   * Yes 
 +   * No 
 +</doodle>
  
 ===== References ===== ===== References =====
-Initial discussion of this proposal on the internals mailing list: http://marc.info/?l=php-internals&m=147638162506291&w=2+Initial discussion of this proposal on the internals mailing list: 
 +  * http://marc.info/?l=php-internals&m=147638162506291&w=2 
 +  * http://marc.info/?l=php-internals&m=147734024403899&w=2 
 +  * http://marc.info/?l=php-internals&m=147673258418764&w=2
rfc/debugging_pdo_prepared_statement_emulation.txt · Last modified: 2018/03/01 23:27 by carusogabriel