Today I had an odd idea: why not create an ElkArte abstraction layer that implements Doctrine Abstraction layer?
I know it's just stupid, but doing it that it saves me the hassle of changing all the queries just to understand if Doctrine is a possible alternative. :P And it would also be backward compatible by default. O:-)
Okay, few links:
http://www.doctrine-project.org/
some documentation:
http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/index.html
I started with the 2.5.0 version found at the github repository here:
https://github.com/doctrine/dbal/releases
First question: why should I want to use Doctrine to begin with?
Obviously because the database abstraction layer is probably the second worst piece of code in terms of hassles after emails.
There are tons of different DBMSes out there and support even only the 3 we should support is difficult (for example the SQLite support is just nominal at the moment, because in fact the code is not working AFAIR due to changes we did in the past).
So, have someone else take care of that would be a nice improvement.
That said, I started out using the MySQL code.
The main thing seems to somehow work. It's not impossible, but being the first time I use Doctrine DBAL, I have some problems hammering it into our schema.
At the moment I have basically nothing really working, and I may not have anything in the future.
At the moment I'm smashing my head against a wall of:
<br />
<strong>Warning</strong>: Illegal string offset: -1 in <strong>/forum/sources/database/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php</strong> on line <strong>142</strong><br />
Notice: Uninitialized string offset: 1 in /forum/sources/database/Db-doctrine.class.php on line 463
Call Stack:
0.0006 304600 1. {main}() /forum/index.php:0
0.0399 4969112 2. loadSession() /forum/index.php:169
0.0399 4971744 3. session_start() /forum/sources/Session.php:89
0.0400 4972304 4. sessionRead() /forum/sources/Session.php:89
0.0400 4972752 5. Database_Doctrine->query() /forum/sources/Session.php:166
0.0417 5025056 6. Doctrine\DBAL\Driver\Mysqli\MysqliStatement->bindValue() /forum/sources/database/Db-doctrine.class.php:463
0.0417 5026744 7. error_handler() /forum/sources/database/Db-doctrine.class.php:142
0.0417 5027104 8. log_error() /forum/sources/Errors.php:279
0.0419 5033760 9. Database_Doctrine->insert() /forum/sources/Errors.php:115
0.0421 5040496 10. Database_Doctrine->query() /forum/sources/database/Db-doctrine.class.php:955
Warning: Illegal string offset: -1 in /forum/sources/database/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php on line 142
Call Stack:
0.0006 304600 1. {main}() /forum/index.php:0
0.0399 4969112 2. loadSession() /forum/index.php:169
0.0399 4971744 3. session_start() /forum/sources/Session.php:89
0.0400 4972304 4. sessionRead() /forum/sources/Session.php:89
0.0400 4972752 5. Database_Doctrine->query() /forum/sources/Session.php:166
0.0417 5025056 6. Doctrine\DBAL\Driver\Mysqli\MysqliStatement->bindValue() /forum/sources/database/Db-doctrine.class.php:463
0.0417 5026744 7. error_handler() /forum/sources/database/Db-doctrine.class.php:142
0.0417 5027104 8. log_error() /forum/sources/Errors.php:279
0.0419 5033760 9. Database_Doctrine->insert() /forum/sources/Errors.php:115
0.0421 5040496 10. Database_Doctrine->query() /forum/sources/database/Db-doctrine.class.php:955
0.0444 5050040 11. Doctrine\DBAL\Driver\Mysqli\MysqliStatement->bindValue() /forum/sources/database/Db-doctrine.class.php:463
Notice: Uninitialized string offset: 0 in /forum/sources/database/Db-doctrine.class.php on line 463
Call Stack:
0.0006 304600 1. {main}() /forum/index.php:0
0.0399 4969112 2. loadSession() /forum/index.php:169
0.0399 4971744 3. session_start() /forum/sources/Session.php:89
0.0400 4972304 4. sessionRead() /forum/sources/Session.php:89
0.0400 4972752 5. Database_Doctrine->query() /forum/sources/Session.php:166
0.0417 5025056 6. Doctrine\DBAL\Driver\Mysqli\MysqliStatement->bindValue() /forum/sources/database/Db-doctrine.class.php:463
0.0417 5026744 7. error_handler() /forum/sources/database/Db-doctrine.class.php:142
0.0417 5027104 8. log_error() /forum/sources/Errors.php:279
0.0419 5033760 9. Database_Doctrine->insert() /forum/sources/Errors.php:115
0.0421 5040496 10. Database_Doctrine->query() /forum/sources/database/Db-doctrine.class.php:955
Notice: Uninitialized string offset: 1 in /forum/sources/database/Db-doctrine.class.php on line 463
Call Stack:
0.0006 304600 1. {main}() /forum/index.php:0
0.0399 4969112 2. loadSession() /forum/index.php:169
0.0399 4971744 3. session_start() /forum/sources/Session.php:89
0.0400 4972304 4. sessionRead() /forum/sources/Session.php:89
0.0400 4972752 5. Database_Doctrine->query() /forum/sources/Session.php:166
0.0417 5025056 6. Doctrine\DBAL\Driver\Mysqli\MysqliStatement->bindValue() /forum/sources/database/Db-doctrine.class.php:463
0.0417 5026744 7. error_handler() /forum/sources/database/Db-doctrine.class.php:142
0.0417 5027104 8. log_error() /forum/sources/Errors.php:279
0.0419 5033760 9. Database_Doctrine->insert() /forum/sources/Errors.php:115
0.0421 5040496 10. Database_Doctrine->query() /forum/sources/database/Db-doctrine.class.php:955
Warning: Illegal string offset: -1 in /forum/sources/database/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php on line 142
[...]
etc.
No idea what is going on. lol
But I think it's a problem with some inserts that is not "escaped" properly...
More digging needed.
nods
Very cool project to undertake !
Have a abstraction layer really seems like the way to go as it opens up other DB platforms for use, its not like we currently have the time to add new layers for other than what we have. What we have covers the vast majority, but we know there are complications and a few weak areas.
Are you writing a layer to convert our syntax to query builder syntax or would we update all the queries to the new syntax? Just curious which way you were looking in your mad scientist way.
Post what you have
Yup.
I will, at the moment I still don't even have the full query function. :P
BTW, I can't find "equivalents" of fetch_assoc and fetch_row, it looks like I have to fetchAll when I do the query, and then handle manually the returning of the single rows. Do you know if I'm doing it wrong?
I meant so I can take a look at it for you to help you fix that error.
Should be $conn->fetchAssoc() IIRC: http://doctrine-dbal.readthedocs.org/en/latest/reference/data-retrieval-and-manipulation.html#fetchassoc
You might also be able to use the PDO::FETCH_* constants in fetchAll()
Yep, I know, though the way it is now, it's not worth spending time trying to fix things, because things are not really implemented yet. :P
I thought so, but it seems like it expects the query inside fetchAssoc... :-\
I'll try again, maybe this evening (yesterday I wasn't at home and today I was a bit tired and had other things to do, also tomorrow I'm not home again...).
Okay, quickly implemented the insert and hit the first very "big" issue.
In logging (but likely in other places as well), there is an insert like:
$id->insert('', '{db_prefix}log_online', array(...), array(..., 'IFNULL(INET_ATON(\'IP_ADDRESS\'))', '''));
So that, at the moment, it is translated to:
$doctrine->insert('elk_log_online', array(.... 'ip_something' => 'IFNULL(INET_ATON(\'IP_ADDRESS\'))', ...));
and of course it fails... :-\
Well, that's all for today.