Esempio n. 1
0
 /**
  * Gets the foreign keys of a table
  * @param string $name Name of the table
  * @return array Array with ForeignKey objects
  */
 protected function getTableFields($name)
 {
     $tableName = $this->connection->quoteIdentifier($name);
     $sql = 'SHOW FIELDS FROM ' . $tableName;
     $result = $this->connection->execute($sql);
     if (!$result) {
         throw new MysqlException('Could not find any fields for table ' . $name . '. Does it exist?');
     }
     $fields = array();
     foreach ($result as $data) {
         $field = new Field($data['Field'], $data['Type']);
         $field->setDefaultValue($data['Default']);
         $fields[] = $field;
         if (!$data['Key']) {
             continue;
         }
         if ($data['Key'] == 'PRI') {
             $field->setIsPrimaryKey(true);
             if ($data['Extra']) {
                 $field->setIsAutoNumbering(true);
                 $field->setDefaultValue(0);
             }
         } elseif ($data['Key'] == 'UNI') {
             $field->setIsUnique(true);
         }
     }
     return $fields;
 }
Esempio n. 2
0
 /**
  * @expectedException zibo\library\database\exception\DatabaseException
  */
 public function testSetIsAutoNumberingThrowsExceptionWhenNoBooleanPassed()
 {
     $field = new Field('name', 'type');
     $field->setIsAutoNumbering('test');
 }