I am now researching about our next generation database abstraction layer in D7. It is almost for sure that we will ship with PDO supporting, as it will become a standard build in package for PHP5 and future. So what will need for PDO supporting? Will this supporting change our database abstraction layer much? Can't it compatible with existing database driver (mysql/mysqli/pgsql)? And will this able to include more database driver supporting, e.g. Oracle/DM2/MSSQL, etc? This issue is trying to research about these questions.
Patch attached including:
- Remove
'%s'
syntax, and standardize it as%s
. This can simply existing syntax, and so reduce buggy code; on the other hand, it is required if we are trying to use PDO?
substitution for query prepare and variable binding. According to this change,%
will need to be included together with variable for substitution. Take this as example (http://php.net/pdo):
<?php // Invalid use of placeholder $stmt = $dbh->prepare("SELECT * FROM REGISTRY where name LIKE '%?%'"); $stmt->execute(array($_GET['name'])); // placeholder must be used in the place of the whole value $stmt = $dbh->prepare("SELECT * FROM REGISTRY where name LIKE ?"); $stmt->execute(array("%$_GET[name]%")); ?>
- Abstracting decimal and float as callback function handling, within _db_query_callback(). This change can give us a change for replacing
%d|%f
input into?
for further more variable binding in PDO - Extend abstraction level with CLOB supporting. This is a follow up for D6 LOBs patch. As it seems not able to be committed within D6, I merge that patch into here for further more follow up. The needs of this handling is fully discussed in http://drupal.org/node/147947, which will not repeat in this issue. Developer will need additional (but handy) API call for LOBs value update action
Patch is created based on latest CVS HEAD of D6. I will keep on update and develop this issue, and keep on researching about the needs of our next generation :)
Comment | File | Size | Author |
---|---|---|---|
#29 | siren-1.0-rc4.patch | 598.11 KB | hswong3i |
#29 | siren-1.0.patch | 822.01 KB | hswong3i |
#29 | siren-1.1.patch | 839.16 KB | hswong3i |
#29 | drupal-6.x-siren-1.x.patch | 839.69 KB | hswong3i |
#29 | coder-6.x-1.x-dev.patch | 806 bytes | hswong3i |
Comments
Comment #1
Crell CreditAttribution: Crell commentedEdison: The whole point of using PDO is that its prepared statements are type agnostic. We won't be using %s/%d at all, quoted or otherwise. We'll be using either ? or :varname. (PDO supports both, I see no reason to go out of our way to break one of them.) That means this patch will not be useful for D7. It is also way too late in the D6 cycle to change the database API syntax. I really don't see what purpose this patch serves.
The only reason we'd need to specify data types at all would be for LOB/BLOB handling in those databases that need special hand-holding. For that, we can either derive that information from the schema API where needed (possibly difficult regexing on those databases) or we can flag it within the query itself, with a syntax like:
which would mean a simpler but still annoying regex in *every* database.
Although, come to think of it, Oracle et al don't allow WHERE operations on LOB/BLOB fields anyway, do they?
In any case, that's a separate issue.
Comment #2
hswong3i CreditAttribution: hswong3i commented@Crell: totally agree about we may have a huge revamp of database abstraction layer in D7, but how will it be? And so this patch: try to approach our target step by step. First work out something, and so prove our idea by code implementation, testing and benchmarking. May be we don't even need a totally revamp of abstraction, which both keep backward compatibility, forward supporting with PDO + other databases, and also booting up performance? No one know the answer, until we try and implement it :)
Comment #3
hswong3i CreditAttribution: hswong3i commentedI just did a simple benchmarking for v0.3, with following setup:
And here is the benchmarking result. You may also find the complete benchmarking result set (please remove the tail .txt within filename) in attachment (c: Concurrency Level; n: Complete requests; all counted in ms):
According to the above benchmarking result, we may conclude that:
'%s'
syntax clean up, and also with standardized LOBs value handling%d|%f|%s|%c
, based on cross database compatibility concernComment #4
hswong3i CreditAttribution: hswong3i commentedLatest research progress result: with v0.3 progress, plus abstract some database specific function by using API, e.g.
SUBSTR
vsSUBSTRING
,LENGTH
vsDATALENGTH
, random and concatenate strings handling. It is mainly cloned from ADOdb (http://phplens.com/lens/adodb/docs-adodb.htm#substr). The implementation is not perfect: I am consider about changing those function call asdefine
constant, but seems will generate conflict with other db_* functions?Code patched with latest drupal-6.x-dev CVS HEAD. Not yet fully tested. Seems a bit buggy in
admin/user/user
filter handling (mainly related to the change of'%%%s%%'
) ;pComment #5
chx CreditAttribution: chx commentedYou never listen to anyone else but yourself. You litter other people's issues with meaningless comments. Accept please that Drupal 7 will change to PDO so this patch has no merit because all those placeholders will be gone.
And finally, please do not reblog all your issue followups in the Drupal planets. Noone else does that, so please don't.
Comment #6
hswong3i CreditAttribution: hswong3i commentedComment #7
hswong3i CreditAttribution: hswong3i commentedPatch update with latest CVS HEAD, with minor bug fixes, includes
%s
handling. It is now including:%d|%f
function wrapper abstraction, and update of%s
syntax among queries (http://www.php.net/pdo, http://edin.no-ip.com/html/?q=node/310).LENGTH
,SUBSTRING
,RAND
, etc (http://drupal.org/node/167335)Next Target: enclose all table/column/constraint name with
[]
, for solving database specific reserved words conflict (http://drupal.org/node/371).Schema API (in XML style) and INSERT/UPDATE/DELETE API should be handled as individual issue (http://edin.no-ip.com/html/?q=node/310). We should tread them as bonus feature for D7 database abstraction layer, but not essential elements, as they will not directly affect the overall PDO and other database drivers development. It is all about developers friendly :)
The actual PDO driver development can get start after next stage of exploration, which should also comes together with legacy mysql/mysqli/pgsql/oracle/db2 drivers supporting.
Here is the benchmarking result, for ensure no degrade of overall performance. It reuse above benchmarking system setup and drupal configuration. The result is positive:
Comment #8
hswong3i CreditAttribution: hswong3i commenteda little round up: all queries under /includes are now enclosed with
[]
for identifiers and name escape (together with updated handling in database.mysql*.inc). as stated in http://drupal.org/node/371, this additional syntax should able to fix the reserved word conflict permanently, under different conditions (e.g. version change in MySQL, or add other database supporting such as Oracle and DB2).as this is a huge job (i need to change EVERY queries line by line... sometime even need to trace overall program logic as queries are dynamically generated...), it is now only implemented for MySQL version: PgSQL and Oracle will added afterward. benchmarking will also be done after changing all core modules and tested as functioning, in order to ensure there is no greatly performance degrade based on this additional handling :)
P.S. also comes together with a minor update of LOBs API. BTW, i am now trying to explore if we will able to merge INSERT/UPDATE/DELETE APIs together with existing db_update_clob() and db_update_blob() (may be coming with additional arguments based on LOBs needs...), so keep our API as simple as possibile :)
Comment #9
keith.smith CreditAttribution: keith.smith commented(correcting typo in issue title)
Comment #10
hswong3i CreditAttribution: hswong3i commentedThe patch contain the progresses of following research result:
This patch is tested for both MySQL and PgSQL with latest D6 CVS HEAD, which worked as an extension of cross database compatible issue. Since we may move to PHP5.2 + PDO in D7, The progress of this patch may not directly contribute to the coming version, e.g. database.mysql*.inc may replaced as database.pdo_mysql.inc with new PDO API.
BTW, all of the above progress WON'T benefited by the change using PDO, so they are REQUIRED based on cross database compatibility concern; on the other hand, unofficial D6 Oracle driver will based on this patch: this patch handle most database variation with minimum changes, so oracle driver will able to implement as a drop-in version (#39260).
P.S. the following issue is not included within this patch. They are required for a complete revamp of queries implementation, which is not easy to be handle within a single patch:
[]
syntax: #371'%s'
syntax: this issueComment #11
chx CreditAttribution: chx commentedIf I were you I would submit the drupal_write_record calls as a separate patch as "code cleanup". They have a good chance of getting in.
Comment #12
hswong3i CreditAttribution: hswong3i commentedJust be honest about my motivation of cleaning up drupal_write_record():
From my point of view, that is not too meaningful if we just focusing on cleaning up drupal_write_record() itself: it should combine with some other enhancement, or at least come with drupal_drop_record().
Anyway, it is already ban by Dires (http://drupal.org/node/183148#comment-614475), even I try to propose both w/o INSERT/UPDATE/DELETE API version (http://drupal.org/node/183148#comment-614473). Even it is too pity, I need to wait for D7 :(
Comment #13
hswong3i CreditAttribution: hswong3i commentedMinor update:
db_query_insert($table, $values)
rather thandb_query_insert("{". $table ."}", $values)
syntax, which synchronize with drupal_write_record() and drupal_drop_record().Comment #14
hswong3i CreditAttribution: hswong3i commentedMinor update: just simply coding style clean up, and reroll via CVS HEAD. Test with both MySQL and PgSQL.
P.S. Patch may seems so large; BTW, most of the changes (except INSERT/UPDATE/DELETE API and LOBs handling) should able to commit within D6. If someone would like to help about keeping this unofficial DB API enhancement as simple as possible, please give me a hand about issues listed in #10. Thank you.
Comment #15
hswong3i CreditAttribution: hswong3i commentedLatest research progress, which integrate ALL points as mentioned in this issue, plus some additional changes discovered during implantation.
The patch is GIANT since I need to change ALL core queries into new coding standard: remove
%%
, simplify'%s'
as%s
and add[]
syntax for all table/column/constrain name. It seems to be crazy, but this is the main point for a complete PDO and Oracle driver implementation.I am going to split the progress result into number of small patches for D7; on the other hand, I will host a project call Siren, which provide this unofficial database driver supporting along D6 life cycle.
Comment #16
hswong3i CreditAttribution: hswong3i commentedLatest research progress. For checkout latest development snapshot:
Comment #17
hswong3i CreditAttribution: hswong3i commentedFollowing on the first release candidate of Drupal 6.0, Siren 1.0 RC1 is now released, too. There is no critical changes for Siren since beta4. Attachment below is for patching Drupal 6.0 RC1.
Read more of this story at my personal research project Siren.
Comment #18
chx CreditAttribution: chx commentedAs Siren is not a project on Drupal.org but an unofficial fork, I am removing it from issue titles to avoid confusion.
Comment #19
hswong3i CreditAttribution: hswong3i commentedFollowing on the second release candidate of Drupal 6.0, I am proud to present to you the Siren 1.0 RC2. I fix some hidden and critical bug since Siren 1.0 RC1, including syntax bug in drupal_write_record() and mishandling in oci8's db_escape_string(). There is no critical change in case of MySQL and PostgreSQL. I am confident that the code is stable enough for wider testing by the community. Attachment below is for patching Drupal 6.0 RC2.
Read more of this story at my personal research project Siren.
Comment #20
hswong3i CreditAttribution: hswong3i commentedFollowing on the thrid release candidate of Drupal 6.0, I am proud to present to you the Siren 1.0 RC3. There is a lot of changes since Siren 1.0 RC2, including the REMOVE of CLOB abstraction (replaced with BLOB), complete revamp some driver implementation (including oci8, pdo_mysql and pdo_pgsql), add pdo_oci driver with limited supporting, and an indeed cross diff for coding style synchronize among different database driver implementation. I am confident that the code is stable enough for wider testing by the community.
Read more of this story at my personal research project Siren.
Comment #21
hswong3i CreditAttribution: hswong3i commentedA minor progress report on today: just able to complete Drupal 6.x installer (hacked with Siren) with SQLite, face the welcome screen, install all optional module (except forum and search), generate dummy content with devel, and finally pass a AB stress test together with MySQL/PostgreSQL/Oracle. So now we have both 4 databases on hand, and all of them come with PDO implementation (even some is not yet perfect).
I did a simple review and benchmarking for this. Patch below is the latest research progress.
Comment #22
Crell CreditAttribution: Crell commentedI don't think this is necessary anymore, and is superseded by: http://drupal.org/node/225450
Comment #23
hswong3i CreditAttribution: hswong3i commentedI have been waiting for a workable implementation from http://drupal.org/node/225450 since last comment; BTW, according to information provided by that issue, the installer is still "almost done" with some module support are broken (e.g. poll, message from IRC #drupal), up to this moment. It is not suitable to say as "superseded" with an incomplete and still under development implementation, especially when this issue have been proposal, complete and keep update for more than 2 months (since #15), where progress already split for individual review, too.
On the other hand, this issue mention a workable implementation for Drupal 6.x. Even they have different approach for next generation, but not means it is suitable to judge each other as duplicated. I would like to contribute the research progress of this issue for our next generation, especially when they are ready to split for individual review; but up to this moment, it is still too early.
Comment #24
chx CreditAttribution: chx commentedWe have not rolled a patch yet in that issue because we are fixing various issues as uncovered by simpletest, have you run all the tests there are to make sure everythign works fine? There is an svn repo you are free to check out the code from there -- as some others already did -- and there will be a patch in due course, both Crell and I am burning midnight oil to have it out there before DrupalCon. Also, as I told you on groups.drupal.org, we were shocked to find no way to pass in CLIENT_FOUND_ROWS as reported at http://bugs.php.net/bug.php?id=44135 -- I read the pdo_mysql driver source and I am fairly confident there is no way. For Drupal it means that when you variable_set something to the same value then there should be an error because of the way variable_set is written and how MySQL returns matched vs affected rows. If you have not stumbled on this then either
In either case, this is bogus and you can not have any idea what those bugs are.
Comment #25
hswong3i CreditAttribution: hswong3i commentedI am now requesting a new project in SourceForge for public CVS service, rather than in-house implementation. I guess it will soon be done, please feel free to contact me if you hope to give a hand for it, or grain for commit right :-)
On the other hand, it is a good point of using simpletest. I learn from chx's project and run parallel test with mysqli and pgsql, for both drupal-7.x-dev and my implementation. Most coming with same result report (except forum and search module, as they contain non-ANSI standard queries which are not within my concern), and some even better, e.g. profile test and module test. Based on this result, we can for sure that MOST core patches for query syntax update are backward compatible with CVS HEAD.
Moreover, since I split the implementation into 3 sections: schema, common and database, which only database.*.inc are PHP driver specific (please refer to http://groups.drupal.org/node/8907#drupal-7.x), we can figure out MOST other bugs for pdo_mysql/pdo_pgsql driver are related to PHP PDO implementation ITSELF, e.g. the CLIENT_FOUND_ROWS bug that chx and Crell have figure out. BTW, that is not our duty, or at least that is not the bug of implementation of this thread. Please don't mix them up.
And once again, please be polite: we may have different approach, but not means we can't contribute and learn form each other. E.g. I learn that SVN/CVS should host by public server for better project image and easy for join development, or using simpletest for professional quality check. It is still too early to judge that issue as "superseded" and this issue as "duplicated" if none of the patch is released for public review, within drupal.org.
All patches below via CVS HEAD. Able to pass though ALL installation procedures, activate MOST core modules, running ALL simpletest checking with similar result as CVS HEAD, generate dummy data by devel for AB benchmarking, etc. Most progresses are split for individual review, please feel free to comment about that :-)
Comment #26
Anonymous (not verified) CreditAttribution: Anonymous commentedsubscribing.
Comment #27
recidive CreditAttribution: recidive commentedHello, can you clarify these points?
Why is it necessary to wrap table names twice, e.g.
[{table_name}]
?Why to wrap field names, e.g.
[field_name]
?Can't we just PDO standard placeholders, e.g.
:value
instead of%d
?Can we drop support for legacy drivers, e.g. mysql, mysqli and switch to PDO only?
Can you cleanup the patch to remove any mentions to SIREN project?
Can you submit the new drivers, Orcacle, DB2 etc as a separated patch?
Comment #28
hyperlogos CreditAttribution: hyperlogos commented+1, hope to see PDO-only myself. Interesting to see which project ends up in the swing.
Comment #29
hswong3i CreditAttribution: hswong3i commentedSince my server is down and so loss all existing research progress, I reuse the above uploaded patch and reroll most progress. Below are patches of the missing ring. Moreover, an array style connection string handling is clone/hack/backport from http://drupal.org/node/225450 with simpler implementation, and added to Siren since 1.0 (I will split its progress as individual patch afterward for simple review).
As I promised in #25, a SourceForge project page is now setup as http://sourceforge.net/projects/siren. You may obtain the full packages from there. CVS repository is now uploading and soon ready. I will keep on posting Siren's research progress under this issue, and so keep on contributing Drupal but not running away from it.
@recidive:
1 & 2. Check here for more information: http://drupal.org/node/371
3. Since the original target of siren is "support other database with minimal logical changes", keep using
%d
but not:value
just because this change give NONE OF BENEFIT to multiple database supporting, and so out of the range of Siren's target.4. We can drop; but once again, there is no different for Siren implementation. As it can support both legacy and PDO driver, and legacy drivers are still keep on supporting within PHP5.x (PHP6 will be purely PDO based), it is not my duty for the removal decision.
5 & 6. Siren is just a project code name, and just cut down Oracle/DB2/SQLite within this patch is not too meaningful: if a single code base can support for multiple database, why we need to split it? On the other hand, I have also split most research progress as individual patches, and this should be more useful for solid and simple review: http://groups.drupal.org/node/8663
Comment #30
chx CreditAttribution: chx commentedThe issue I raised in http://drupal.org/node/172541#comment-751091 is not addressed still. Also you submitted patches beyond the size of humanly possible review.
Comment #31
hswong3i CreditAttribution: hswong3i commentedAbout the question from http://drupal.org/node/172541#comment-751091:
For the problem of giant patch, research progress already split as small and simple patches as mentioned in http://groups.drupal.org/node/8663. People who are interesting in Drupal + MySQL/PostgreSQL/Oracle/DB2/MSSQL/SQLite/etc should give a hand to those basic elements, in order to improve Drupal core as less specific database dependent.
Comment #32
David Strauss@hswong3i Adapting Drupal core to support new database systems is not "research." You seem to refer to any mundane work you produce as research, and I don't think it's an English comprehension issue. I'd give you a detailed explanation, but I have to research some laundry first.
chx is right about solving problems in your patch. Drupal isn't your academic toy, and claiming something is "out of the research scope of this issue" -- along with your continued failure to properly cooperate with the rest of the Drupal community -- makes me want to "won't fix" your issue.
Actually, I think I will.
Comment #33
hswong3i CreditAttribution: hswong3i commented@David: What if we need Oracle/DB2/SQLite support on today? This issue is target for such on time needs. It is no point to ask people wait for a year for Drupal 7, with a may/may not support of other databases. Some people are asking me "how to obtain this research progress?" for their project (including a staff from IBM in US which asking for DB2 support, and a company with hosting 30+ website in Oracle 9i which hope to move to Drupal), and so I keep on update this issue. This is not a toy for myself but a solution which target for production, before we have a real hope of other database support in Drupal core.
On the other hand, what chx mentioned in http://drupal.org/node/172541#comment-751091 is about the bug of PHP pdo_mysql implementation. Why that issue should include in this patch, but not in the patch query of PHP? Moreover, the stability of this patch is already proved by simpletest. When Drupal CVS HEAD also face buggy report with simpletest, what is the duty of this patch to become perfect?
This patch itself shouldn't be commit directly since too giant in size; BTW, it have a duty to show out the possibility of Drupal. If we hope to push the case forward, please give a hand to issues mentioned in http://groups.drupal.org/node/8663, but not striking the progress of this issue.
Comment #34
David Strauss"What if we need Oracle/DB2/SQLite support on today?"
Fortunately, no one does. Well, maybe except you, but I'm prepared to enjoy that consequence.
Comment #35
David StraussIf we can get some consensus from the community that this is not the path for Drupal 7 database development, I would like to lock further commenting on this issue.
I think it's pretty clear that #225450 is the consensus for where Drupal 7 database work is happening, even with the debates there over nuances of the implementation.
Comment #36
catchI'd support locking this issue until #225420 is resolved. There is a pattern of these parallel issues over the past few months which do nothing to help to the development process and if anything disrupt it.
Comment #37
chx CreditAttribution: chx commentedI need to repeat myself "In either case, this is bogus and you can not have any idea what those bugs are". This is the fundamental problem with this monster patch. And all hswong3i has to say is "hey it works" -- no, it does not.
Comment #38
David StraussI'm locking this thread from further commenting until #225450 achieves some stable status for Drupal 7. What's likely is that #225450 will be finished and committed in some form. Then, we can reopen this issue (or, better yet, start a fresh, clean one without patches to fork Drupal core) to discuss extending the support of the new Drupal 7 database API to Oracle, SQLite, and DB2.
This decision reflects the almost universal opinion in the community that a solid Drupal 7 database API is a higher priority than extending support to more database systems.
hswong3i: This is not an invitation to discuss Oracle, SQLite, or DB2 on #225450.