Esempio n. 1
0
 public function keyExists($key)
 {
     /** @noinspection PhpMethodParametersCountMismatchInspection */
     $row = $this->db->select($this->table)->select('?', $this->expireField)->where('? = ?', $this->keyField, $key)->query()->fetchRow();
     if (!$row) {
         return false;
     } else {
         $expireUt = $row[$this->expireField->name];
         if ($expireUt && $this->time->now() > $expireUt) {
             $this->delete($key);
             return false;
         }
         return true;
     }
 }
Esempio n. 2
0
 private function readForeignKeys(Table $def)
 {
     $res = $this->database->select()->select('tc.constraint_name, kcu.column_name')->select('ccu.table_name  AS foreign_table_name, ccu.column_name AS foreign_column_name')->from('information_schema.table_constraints AS tc')->innerJoin('information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name')->innerJoin('information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name')->where('constraint_type = \'FOREIGN KEY\'')->where('tc.table_name = ?', $def->schemaName)->query()->fetchAll();
     $fk = array();
     foreach ($res as $r) {
         $fk[$r['constraint_name']][$r['column_name']] = array($r['foreign_table_name'], $r['foreign_column_name']);
     }
     foreach ($fk as $constraintName => $constraintColumns) {
         $localColumns = array();
         $referenceColumns = array();
         foreach ($constraintColumns as $localName => $refData) {
             $localColumns[] = $def->columns->{$localName};
             $column = new Column();
             $column->table = new Table(null, null, $refData[0]);
             $column->schemaName = $refData[1];
             $referenceColumns[] = $column;
         }
         $foreignKey = new Database\Definition\ForeignKey($localColumns, $referenceColumns);
         $foreignKey->setName($constraintName);
         $def->addForeignKey($foreignKey);
     }
 }