Esempio n. 1
0
File: Field.php Progetto: jasny/Q
 /**
  * Return the name of a field.
  *
  * @param int $flags  A DB::FIELDNAME_% constant and DB::WITH_ALIAS and DB::QUOTE_% options as binary set 
  * @return string
  */
 public function getName($flags = DB::FIELDNAME_FULL)
 {
     switch ($flags & 0xf) {
         case DB::FIELDNAME_NAME:
             return $flags & QUOTE_LOOSE || $flags & QUOTE_STRICT ? $this->parent->getConnection()->quoteIdentifier($this['name'], $flags) : $this['name'];
         case DB::FIELDNAME_FULL:
             return $flags & QUOTE_LOOSE || $flags & QUOTE_STRICT ? $this->parent->getConnection()->makeIdentifier($this['table'], $this['name'], $flags) : (isset($this['table']) ? $this['table'] . '.' . $this['name'] : $this['name']);
         case DB::FIELDNAME_COLUMN:
             return $this->parent->getConnection()->makeIdentifier($this['table'], $this['name_db'], $flags & DB::WITH_ALIAS && $this['name'] != $this['name_db'] ? $this['name'] : null, $flags);
         case DB::FIELDNAME_DB:
             return $this->parent->getConnection()->makeIdentifier($this['table_db'], $this['name_db'], $flags & DB::WITH_ALIAS && $this['name'] != $this['name_db'] ? $this['name'] : null);
     }
 }
Esempio n. 2
0
 /**
  * Helper function: Test field of a record
  *
  * @param DB_Record $record
  */
 function recordFieldsTest($record)
 {
     $field = $record->getField('id');
     $this->assertNotNull($field, "Did not find field 'id'");
     $this->assertEquals('Id', $field['description'], "Description of 'id'");
     $this->assertEquals('test', $field['table'], "Table of 'id'");
     $this->assertEquals(1, $field->getValue(), "Value of 'id'");
     $field_role = $record->getField('#role:id');
     $this->assertNotNull($field_role, "Did not find field '#role:id'");
     if ($field_role !== $field) {
         $this->fail("#role:id != id, but " . $field_role->name);
     }
     $field = $record->getField('title');
     $this->assertNotNull($field, "Did not find field 'title'");
     $this->assertEquals('Title', $field['description'], "Description of 'title'");
     $this->assertEquals('first row', $field->getValue(), "Value of 'title'");
     $field = $record->getField('#role:active');
     $this->assertNull($field, "Should not have found file '#role:active'");
 }
Esempio n. 3
0
File: Table.php Progetto: jasny/Q
 /**
  * Load a record for this table
  *
  * @param mixed  $id          Value(s) for primary key or criteria or NULL for a new record
  * @param string $mode        Use property 'load.$mode' (defaults back to property 'load' and 'view')
  * @param int    $resulttype  A Q\DB::FETCH_% constant
  * @return DB_Record
  * 
  * @throws DB_LimitException if query results in > 1 record
  */
 public function load($id, $mode = null, $resulttype = DB::FETCH_RECORD)
 {
     if (!isset($id) && $resulttype != DB::FETCH_RECORD) {
         throw new Exception("Loading a new record for any other result type than DB::FETCH_RECORD is not supported.");
     }
     // No link or no table property, so create new record directly (mode is ignored)
     if (!$this->getConnection()) {
         if (isset($id)) {
             throw new Exception("Unable to load a record '{$id}' for table '{$this}': No database connection");
         }
         return DB_Record::create($this);
     }
     // Create a record using though a query result
     if (isset($mode) && isset($this["load.{$mode}"])) {
         $statement = $this["load.{$mode}"];
     } else {
         $statement = $this['load'];
     }
     $result = $this->select($statement, isset($id) ? $id : false)->execute();
     if (!isset($id)) {
         return $result->newRecord();
     }
     if ($result->countRows() > 1) {
         throw new DB_LimitException("Query returned " . $result->countRows() . " rows, while only 1 row was expected");
     }
     return $result->fetchRow($resulttype);
 }
Esempio n. 4
0
File: Result.php Progetto: jasny/Q
 /**
  * Returns a new record based on the fields of the result
  * 
  * @return DB_Record
  */
 public function newRecord()
 {
     return DB_Record::create($this);
 }
Esempio n. 5
0
 /**
  * Set an item of (or add to) the array object
  * 
  * @param int          $offset
  * @param Q\DB_Record $value   New Child record
  */
 function offsetSet($offset, $value)
 {
     if (!$value instanceof DB_Record) {
         $value = DB_Record::create($this->parent, $value);
     }
     parent::offsetSet($offset, $value);
 }