コード例 #1
0
ファイル: Result.php プロジェクト: jasny/Q
 /**
  * Class constructor
  *
  * @param Q\DB|Q\DB_Table $source
  * @param object|resource $native     The native result object or resource
  * @param string          $statement  The query statement which created this result
  */
 public function __construct($source, $native, $statement)
 {
     if ($source instanceof DB) {
         $this->link = $source;
     } elseif ($source instanceof DB_Table) {
         $this->basetable = $source;
         $this->link = $source->getConnection();
     } else {
         throw new Exception("Parent of result can only be a Q\\DB or Q\\DB_Table, not a " . (is_object($source) ? get_class($source) : gettype($source)));
     }
     $this->native = $native;
     $this->statement = $statement;
 }
コード例 #2
0
ファイル: Record.php プロジェクト: jasny/Q
 /**
  * The class constructor.
  *
  * @param Q\DB_Result|Q\DB_Table $source
  * @param array                  $values  Ordered or associated array with values
  */
 protected function __construct($source = null, $values = null)
 {
     if (!isset($source)) {
         $fields = array();
         foreach ((array) $values as $key => $value) {
             $this->_fieldIndex[$key] = array_push($this->_fields, DB_Field::create(null, array('name' => $key, 'table' => null, 'type' => gettype($value)), $value)) - 1;
         }
     } else {
         $this->_link = $source->getConnection();
         $this->_baseTable = $source instanceof DB_Table ? $source : $source->getBasetable();
         list($fields, $this->_fieldIndex, $this->_fieldnames, $this->_tablerefs) = $source->getInternalInfo();
         if (!isset($values)) {
             foreach ($fields as $i => $fd) {
                 $this->_fields[$i] = $fd->asNewActive($this);
             }
         } else {
             foreach ($fields as $i => $fd) {
                 $this->_fields[$i] = $fd->asActive(isset($values[$fd->getName()]) ? $values[$fd->getName()] : (isset($values[$i]) ? $values[$i] : null), $this);
             }
         }
     }
 }
コード例 #3
0
ファイル: DB.php プロジェクト: jasny/Q
 /**
  * Initialises auth, onStart, onLogin and onLogout queries.
  */
 public function initStatement()
 {
     if (isset($this->table)) {
         if (is_string($this->table)) {
             $this->table = DB::i()->table($this->table);
         }
         if (!isset($this->query)) {
             $this->query = $this->table->getStatement('auth');
         }
         if (!isset($this->onStartQuery) && $this->table['onstart']) {
             $this->onStartQuery = $this->table->getStatement('onstart');
         }
         if (!isset($this->onLoginQuery) && $this->table['onlogin']) {
             $this->onLoginQuery = $this->table->getStatement('onlogin');
         }
         if (!isset($this->onLogoutQuery) && $this->table['onlogout']) {
             $this->onLogoutQuery = $this->table->getStatement('onlogout');
         }
         $link = $this->table->getConnection();
     } else {
         $link = DB::i();
     }
     if (!isset($this->query)) {
         throw new Exception("Table nor query is set.");
     }
     if (is_string($this->query)) {
         $this->query = $link->prepare($this->query);
     } else {
         $this->query->commit();
     }
     if (isset($this->onStartQuery) && is_string($this->onStartQuery)) {
         $this->onStartQuery = $link->prepare($this->onStartQuery);
     }
     if (isset($this->onLoginQuery) && is_string($this->onLoginQuery)) {
         $this->onLoginQuery = $link->prepare($this->onLoginQuery);
     }
     if (isset($this->onLogoutQuery) && is_string($this->onLogoutQuery)) {
         $this->onLogoutQuery = $link->prepare($this->onLogoutQuery);
     }
     if (!isset($this->passwordCrypt)) {
         $this->passwordCrypt = $this->query->getField(4)->getProperty('crypt');
     }
     $this->queryInit = true;
 }