Page 1 of 1

Proposal: SQLite

PostPosted: Mon Jan 18, 2010 11:44 am
by janniz
Some months ago (last october), on a spare time basis :), I've tried to include SQLite support into PivotX and I've obtained a sort of working copy of pivotx (based on SVN-2185) that can use SQLite as a db backend.
Unluckily I was not able to find any regression test suite on Pivotx developers site that can validate the result of my efforts... in the meantime other projects arose, and I forgot to submit this 'draft' to developers team :(
Now I found my original sqlite implementation, so I've decided that's time to submit it to the community... :-)

The attachment contains a patch file that can be used to transform a plain pivotx (SVN-2185) setup to an SQLite enabled one.

HTH
Janniz

P.S: Developers can freely send me a PM if they have any question about my messy changes :)

Re: Proposal: SQLite

PostPosted: Mon Jan 18, 2010 9:35 pm
by Bob
Hi,

I haven't looked at the code yet, but i surely will!

One questions (i know, i could look at the code, but i'm impatient like that. ;-) ) Does this _add_ sqlite as an option, or does it _replace_ mysql?

If it's the first, it'll be much easier to incorporate into PivotX, and officially support it..

Re: Proposal: SQLite

PostPosted: Tue Jan 19, 2010 10:09 am
by janniz
I've tryied to leave previous SQL code as is so that SQLite/anyoytherDb support can be added semless.
In the first step I had to make some sort of abstraction to make things co-exist and I created a new class sqlFactory.
Where previously there where something such as this piece of code:
Code: Select all
$this->sql = new sql('mysql',
            $PIVOTX['config']->get('db_databasename'),
            $PIVOTX['config']->get('db_hostname'),
            $PIVOTX['config']->get('db_username'),
            $PIVOTX['config']->get('db_password')
);

now there is:
Code: Select all
$this->sqlFactory = new sqlFactory($PIVOTX['config']->get('db_model'),
            $PIVOTX['config']->get('db_databasename'),
            $PIVOTX['config']->get('db_hostname'),
            $PIVOTX['config']->get('db_username'),
            $PIVOTX['config']->get('db_password')
);

// Set up DB connection
$this->sql = $this->sqlFactory->getSqlInstance();


then I tryied to look at SQL queries, in order to try/catch/support SQLite unsupported statements.

Obviously I cannot be sure of the reliability of the code without executing a proper regression tests, and so I advise again using this patch in production environment :)

Finally:
In real life I'm no longer a PHP developer by many years (I'm on Java boat now :)) so my PHP code can (maybe) look messy and strange... (I apologize for this :)) My spare time is really, really little... but if you need support for this patch (or for any DB/code architecture related question) I will be proud to give my 2cents for this great project.

P.S: I've not updated all headers/comments of source files I've changed. I'm a little lazy on doing this kind of work... and this code was not touched with the aim to be show off to the public :)

Re: Proposal: SQLite

PostPosted: Tue Jan 19, 2010 3:44 pm
by hansfn
Thx for your contribution. I have planned to add support for SQLite a long time so this will likely reduce the needed work. Thx again.

PS! Any specific reason you create a sqlFactory in stead of following the abstraction/pattern in modules/module_db.php?

Re: Proposal: SQLite

PostPosted: Tue Jan 19, 2010 4:13 pm
by janniz
The module_db was left untouched (The entry for sqlite was already there).

I created sqlFactory to decouple the code in module_sql from MySQL specific logic (module_sql is strongly tied to mysql and mysql_query statements...).

The factory manage the creation of 'new kind of sql' objects. These objects are of type MySQL, SQLite, etc. and all of them extends the new class abstractSql (in modules/abstractSql.php) that replaces in a more generic way the old module_sql.

But I think that if you look at the patch file you will understand more things than reading my crappy english :(

In any case if you have any other question to ask... I'm here !!!! :P