[TYPO3-core] RFC #15457: Add support for prepared queries

Xavier Perseguers typo3 at perseguers.ch
Sat Aug 14 23:14:25 CEST 2010


Hi,

This is an SVN patch request.

Type: feature

Bugtracker reference:
http://bugs.typo3.org/view.php?id=15457

Branches: trunk

Problem:
Having support for prepared queries would allow to implement an 
efficient caching mechanism when using DBAL which would result in a huge 
speed improvement.

It will provide a PDO-like syntax which could, in a second phase, allow 
TYPO3 to issue real prepared statements to the underlying DBMS. In 
addition, this RFC provides a DB abstraction that is object oriented, 
meaning, it is not necessary anymore to deal with MySQL pointers


Additional information:
Some of you might ask why we cannot use PDO right away. The reason is 
that we need remapping feature that PDO does not provide, at least when 
using with Oracle. But as said, in a second phase, it could be perhaps 
possible to take the remapped query and send it to the DBMS using PDO 
instead of ADOdb. However this is not the purpose of this RFC.


Additional information 2:
DBAL corresponding patch is available in bug tracker. You are of course 
encouraged to have a look at it if you wish but this is not mandatory to 
review this RFC.


Additional information 3:
MySQL-only implementation (thus what is in this patch) does not use the 
SQL parser to extract parameters, meaning the execution speed will not 
suffer from using prepared queries in regards to the "old way" but 
instead it paves the way for improvement in future.


How prepared queries could then be used:
Idea is to rewrite Core queries using prepared queries once this support 
has been made available.

sample #1
====================================
$stmt = $GLOBALS['TYPO3_DB']->prepare_SELECTquery('*', 'pages', 'pid = 
:pid');
$stmt->execute(array(':uid' => 2));
while (($row = $stmt->fetch()) !== FALSE) {
	// ...
}
$stmt->free();


sample #2
====================================
$stmt = $GLOBALS['TYPO3_DB']->prepare_SELECTquery('uid, title', 'pages', 
'pid = ?');
$pid = 1;
$stmt->bindParam(1, $pid);
$stmt->execute();
$pagesWithPid1 = $stmt->fetchAll();
$stmt->free();

$pid = 4;
$stmt->execute();
$pagesWithPid4 = $stmt->fetchAll();
$stmt->free();
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: 15457_core_v2.diff
URL: <http://lists.typo3.org/pipermail/typo3-team-core/attachments/20100814/4530c702/attachment.txt>


More information about the TYPO3-team-core mailing list