Extending DSQL

You might be wondering — how to add support for your un-supported database type or perhaps how to add syntax for some other commands.

When connect() is called, it will calculate $db->type based on the supplied DSN. If you are using MySQL database then type will be "mysql". Also DB class will set $db-->dsql_class variable which is then used by dsql() class. If you want to extend it, you would need to be able to specify your own class there. This can be done either by supplying 'class'=>'myclass' in the DSN array or manually changing value of $db->dsql_class after connection.

Below is a sample extension for MySQL which adds $q->showTables() command.

class DB_dsql_mysqlextra extends DB_dsql_mysql {
$this->template='show tables';

// config.php


// elsehere

$q->showTables() as $row){
// ...

Changing existing queries

If your database driver needs existing query changed, you can simply redefine function in your class:

class DB_dsql_pgsql extends DB_dsql {

/** PostgreSQL does not like backticks */
public $bt='';

/** Use extended PostgreSQL syntax for fetching ID */
function insert(){
$this->template.=" returning id";

Adding sum() function

Whenever you need to calculate sum of the field, you must create expression. How about creating a function for doing this easier?

    function sum($expr,$alias){