public static function listTableIndexes($table) { $keyName = 'Key_name'; $nonUnique = 'Non_unique'; $keyName = strtolower($keyName); $nonUnique = strtolower($nonUnique); $table = Soup_Inflector::quoteIdentifier($table); $query = 'SHOW INDEX FROM ' . $table; $indexes = Soup_Query::query($query); $result = array(); foreach ($indexes as $indexData) { if ($indexData[$nonUnique] && ($index = Soup_Inflector::fixIndexName($indexData[$keyName]))) { $result[] = $index; } } return $result; }
/** * * @todo bu kısımda tek bir data varsa o silinecek birden fazla data tutuluyorsa içerisinde hepsi birden silinecek. Relationlar eklendikten sonra test edilecek. */ public function delete() { // if($this->count()>0) // return 'Toplu siliş'; // else // return 'Tekli Siliş'; return Soup_Query::delete($this->getTable()->getTableName())->where($this->getTable()->getPrimaryKey() . ' = ?', $this->_data[$this->getTable()->getPrimaryKey()])->execute(); }
/** * Fieldname'e göre arama yapıyor. * * @param string $column * @param string $value * @return Soup_Result|array * @todo: Bu method kontrol edilmedi */ public function findBy($fieldName, $params) { $result = Soup_Query::select()->from($this->getTable()->getTableName())->where($fieldName . ' = ?', $params)->execute(); return $result; }
public static function getLastSqlString() { return (string) self::$_instance->_builSqlString()->_sql; }
public function fetch() { $query = Soup_Query::select("SQL_CALC_FOUND_ROWS *")->from($this->getTable()->getTableName()); if ($this->_where) { $i = 0; foreach ($this->_where as $where) { if ($i) { $query->andWhere($where['where'], $where['params']); } else { $query->where($where['where'], $where['params']); } $i++; } } if ($this->_limit) { $query->limit($this->_limit); } if ($this->_offset) { $query->offset($this->_offset); } if ($this->_order) { $query->orderBy($this->_order); } $this->_where = array(); $this->_limit = null; $this->_offset = null; $this->_order = null; return $query->execute(); }
/** * Save * * @todo preSave, afterSave eventleri eklenecek * @todo validationlar eklenecek * @return integer $primaryKey */ public function save() { try { $calledTable = array(); foreach ($this->_data as $key => $value) { if ($value instanceof Soup_Record) { $foreignKey = $this->getTable()->getForeignKey($value->getTable()->getName()); if ($foreignKey['type'] == Soup_Table::RELATION_ONE) { $this->set($foreignKey['local'], $value->save()); } else { $calledTable[$key] = $value; } } } Soup_Query::insert($this->getTable()->getTableName(), $this->_values)->execute(); $lastId = Soup_Query::lastInsertId(); $this->set($this->getTable()->getPrimaryKey(), $lastId); foreach ($calledTable as $key => $value) { $foreignKey = $this->getTable()->getForeignKey($value->getTable()->getName()); $value->set($foreignKey['foreign'], $lastId); $value->save(); } return $lastId; } catch (Soup_Query_Exception $e) { throw new Soup_Record_Exception($e->getMessage(), $e->getCode()); } }