Ejemplo n.º 1
0
 function __construct($driver, $node, $dsn, $username = null, $password = null, $driver_options = null)
 {
     $this->node = $node;
     $this->_driver = $driver;
     parent::__construct($dsn, $username, $password, $driver_options);
     $this->setAttribute(self::ATTR_ERRMODE, self::ERRMODE_EXCEPTION);
 }
Ejemplo n.º 2
0
    private function _buildTableView($pathTo, $item)
    {
        $objectType = $item['type'];
        $className = str_replace('.', '_', $item['name']);
        if (isset($item['conf']['columns']) && count($item['conf']['columns']) > 0) {
            foreach ($item['conf']['columns'] as $columName => $conf) {
                $_consts[] = '    const ' . strtoupper($columName) . ' = "' . $columName . '";';
                $_conf[] = '        self::' . strtoupper($columName) . ' => array(Nov\\Types::' . $this->_getNovType($conf['native_type']) . '),';
                $_fcts[] = '    function ' . $columName . '()
    {
        return $this->_isObject ? $this->_recordset->{' . $className . '::' . strtoupper($columName) . '} : $this->_recordset[' . $className . '::' . strtoupper($columName) . '];
    }';
            }
        }
        $consts = implode("\n", $_consts);
        $conf = implode("\n", $_conf);
        $fcts = implode("\n\n", $_fcts);
        $schema = is_null($this->_schema) || $this->_db->getDriver() == 'sqlite' ? 'null' : "'{$this->_schema}'";
        $class = <<<EOD
<?php
namespace Orm\\{$this->_schema};
use \\Nov;
class {$className} extends Nov\\Db\\Orm\\{$objectType}
{
    protected \$_schema = {$schema};
    protected \$_object = "{$item['name']}";

{$consts}
    
    protected \$_conf = array(
{$conf}
        );
}

class {$className}_Record
{
    /**
     * @param \\Nov\\Orm\\Record \$recordset
     * @return \\Orm\\{$this->_schema}\\{$className}_Record
     */
    static function factory(\$recordset)
    {
        return new {$className}_Record(\$recordset);
    }
    
    private \$_recordset;
    function __construct(\$recordset)
    {
        \$this->_isObject = \$recordset instanceof Nov\\Db\\Orm\\Record;
        \$this->_recordset = \$recordset;
    }
    
{$fcts}
}
EOD;
        $this->_makeFile($pathTo, $item['name'], $class);
    }
Ejemplo n.º 3
0
 public function exec($fetchType = Nov\Db::FETCH_ALL)
 {
     if (is_string($this->getDb())) {
         $this->setDb(Nov\Db\PDO::factory($this->getDb()));
     }
     $this->_composeSql();
     if ($this->_type == self::_SELECT) {
         $this->_execute();
     } else {
         if ($this instanceof Nov\Db\Orm\Instance\Table) {
             $this->_triggerPre();
             $this->_execute();
             $this->_triggerPost();
         }
     }
     return $this->_fetch($fetchType);
 }