/** * Construct a Columnar join object. * * @param string[] $columns * @param array $keys * @param string $jointKey * @param bool $useAlphaNumMatch */ public function __construct(array $columns, array $keys = ['id'], $jointKey = 'joint_data', $useAlphaNumMatch = true) { parent::__construct($useAlphaNumMatch); $this->columns = array_flip($columns); $this->jointKey = $jointKey; $this->keys = array_flip($keys); }
/** * @return void */ public function doNotReplaceFunction() { $foo = is_int(2); $foo = is_writable($foo); $foo = new Join(); $foo = Join::foo(); }
/** * Erzeugt eine Anfrage, die mehrere Datensätze in die database schreiben soll. * @param array $querystate Assoziatives Array, welches die Spezifikationen der Anfrage bereitstellt. * @return string MySQL-Anfragenstring */ public function generateMultipleInsertQuery($querystate, $values) { $this->pushpopState($querystate); $db = $this->prepareIdentifier($this->db); $table = $this->prepareIdentifier($this->table); $fields = $this->fields === '*' ? $this->getColumns() : $this->prepareFields(); // Sanity check if (!count($fields) or !count($values)) { $this->popState(); return ''; } // Query erzeugen $query = "INSERT INTO `{$db}`.`{$table}` (" . implode(', ', $fields) . ') VALUES '; $rows = array(); foreach ($values as $row) { $rows[] = '(' . implode(',', array_fill(0, count($fields), '?')) . ')'; } $query .= implode(',', $rows); // Join anhängen. if ($this->join) { $query .= ' ' . $this->join->str($db); } $this->popState(); return $query; }
/** * Konvertiert diesen Join in einen String. * @param string $db Name der database, die die Tabelle beinhaltet. * @return string Join-String */ public function str($db) { // TODO: Erwartet Filter-Klasse zur sichereren Abstrahierung der Anfragen für sowohl den Server als auch den Entwickler. $condition = $this->condition; if (Config::main()->get('DBO_ENFORCE_COL_DELETED') and !$this->ignoreDeleted) { $condition .= ' AND `' . $this->tabname . '`.`DELETED`=0'; } return implode(' ', array($this->jointype, 'JOIN', "`{$db}`.`" . $this->tabname . '`', $condition)) . (!empty($this->more) ? ' ' . $this->more->str($db) : ''); }
/** * This method is to figure out stuff. */ public function init() { parent::init(); // If kind is not specified, figure out join type if (!isset($this->kind)) { $this->kind = $this->weak ? 'left' : 'inner'; } // Add necessary hooks if ($this->reverse) { $this->owner->addHook('afterInsert', $this, null, -5); $this->owner->addHook('beforeUpdate', $this, null, -5); $this->owner->addHook('beforeDelete', [$this, 'doDelete'], null, -5); } else { $this->owner->addHook('beforeInsert', $this); $this->owner->addHook('beforeUpdate', $this); $this->owner->addHook('afterDelete', [$this, 'doDelete']); $this->owner->addHook('afterLoad', $this); } }
/** * This method is to figure out stuff. */ public function init() { parent::init(); $this->owner->persistence_data['use_table_prefixes'] = true; // If kind is not specified, figure out join type if (!isset($this->kind)) { $this->kind = $this->weak ? 'left' : 'inner'; } // Our short name will be unique if (!$this->foreign_alias) { $this->foreign_alias = (isset($this->owner->table_alias) ? $this->owner->table_alias : '') . $this->short_name; } $this->owner->addhook('initSelectQuery', $this); // Add necessary hooks if ($this->reverse) { $this->owner->addHook('afterInsert', $this); $this->owner->addHook('beforeUpdate', $this); $this->owner->addHook('beforeDelete', [$this, 'doDelete'], null, -5); $this->owner->addHook('afterLoad', $this); } else { // Master field indicates ID of the joined item. In the past it had to be // defined as a physical field in the main table. Now it is a model field // so you can use expressions or fields inside joined entities. // If string specified here does not point to an existing model field // a new basic field is inserted and marked hidden. if (is_string($this->master_field)) { $e = $this->owner->hasElement($this->master_field); if (!$e) { if ($this->join) { $e = $this->join->addField($this->master_field, ['system' => true, 'read_only' => true]); } else { $e = $this->owner->addField($this->master_field, ['system' => true, 'read_only' => true]); } $this->master_field = $e->short_name; } } $this->owner->addHook('beforeInsert', $this, null, -5); $this->owner->addHook('beforeUpdate', $this); $this->owner->addHook('afterDelete', [$this, 'doDelete']); $this->owner->addHook('afterLoad', $this); } }
/** * Add a join with multiple conditions * see http://propel.phpdb.org/trac/ticket/167, http://propel.phpdb.org/trac/ticket/606 * * Example usage: * $c->addMultipleJoin(array( * array(LeftPeer::LEFT_COLUMN, RightPeer::RIGHT_COLUMN), // if no third argument, defaults to Criteria::EQUAL * array(FoldersPeer::alias( 'fo', FoldersPeer::LFT ), FoldersPeer::alias( 'parent', FoldersPeer::RGT ), Criteria::LESS_EQUAL ) * ), * Criteria::LEFT_JOIN * ); * * @see addJoin() * @param array $conditions An array of conditions, each condition being an array (left, right, operator) * @param string $joinType A String with the join operator. Defaults to an implicit join. * * @return Criteria A modified Criteria object. */ public function addMultipleJoin($conditions, $joinType = null) { $join = new Join(); foreach ($conditions as $condition) { $join->addCondition($condition[0], $condition[1], isset($condition[2]) ? $condition[2] : Criteria::EQUAL); } $join->setJoinType($joinType); return $this->addJoinObject($join); }
/** * Executes query build by createSelectSql() and returns ResultSet. * * @param Criteria $criteria A Criteria. * @param Connection $con A connection to use. * @return ResultSet The resultset. * @throws PropelException * @see createSelectSql() */ public static function doSelect(Criteria $criteria, $con = null) { $arrTables = array_keys($criteria->getTablesColumns()); if (sizeof($arrTables) > 1) { $arrJoins = array(); foreach ($criteria->getJoins() as $objJoin) { if (false) { $objJoin = new Join(); } $arrJoins[] = $objJoin->getLeftTableName(); $arrJoins[] = $objJoin->getRightTableName(); } array_unique($arrJoins); $arrMissedJoinsWhatever = array_diff($arrTables, $arrJoins); } // endif $dbMap = Propel::getDatabaseMap($criteria->getDbName()); if ($con === null) { $con = Propel::getConnection($criteria->getDbName()); } $stmt = null; try { // Transaction support exists for (only?) Postgres, which must // have SELECT statements that include bytea columns wrapped w/ // transactions. if ($criteria->isUseTransaction()) { $con->begin(); } $params = array(); $sql = self::createSelectSql($criteria, $params); $stmt = $con->prepareStatement($sql); $stmt->setLimit($criteria->getLimit()); $stmt->setOffset($criteria->getOffset()); self::populateStmtValues($stmt, $params, $dbMap); $rs = $stmt->executeQuery(ResultSet::FETCHMODE_NUM); if ($criteria->isUseTransaction()) { $con->commit(); } } catch (Exception $e) { if ($stmt) { $stmt->close(); } if ($criteria->isUseTransaction()) { $con->rollback(); } Propel::log($e->getMessage(), Propel::LOG_ERR); throw new PropelException($e); } if (isset($arrMissedJoinsWhatever) && sizeof($arrMissedJoinsWhatever)) { $strBody = "The probable error, a lack of joins tables " . var_export($arrMissedJoinsWhatever, true) . " in query: \n\n" . $sql; // $strBody .= "\n\n".sfContext::getInstance()->getRequest()->getUri(); throw new Exception($strBody); } // endif return $rs; }
/** * @param Join $join * * @return bool */ public function equals($join) { $parametersOfThisClauses = array(); $parametersOfJoinClauses = array(); return $join !== null && $join instanceof Join && $this->getJoinType() == $join->getJoinType() && $this->getConditions() == $join->getConditions() && $this->getClause($parametersOfThisClauses) == $join->getClause($parametersOfJoinClauses); }
/** * @param Join $join * @return bool */ public function equals($join) { return $join !== null && $join instanceof Join && $this->joinType == $join->getJoinType() && $this->getConditions() == $join->getConditions(); }
/** * @return string */ protected function formatJoins() { $joins = ''; foreach ($this->joins as $join) { if (is_array($join)) { $join = new Join($join['table'], $join['on'], isset($join['type'])); } if (!$join instanceof Join) { continue; } $joins .= $join->getSql($joins === ''); } return $joins; }
function createnpc() { // Chance of creating NPC player if ($this->npc || rand(0, 100) < 25) { return; } $free = rand($this->round['min_planets'], $this->round['max_planets']); $starsystem_id = $this->availablestarsystem($free); if (empty($starsystem_id)) { return; } $npc = new Join($this->data, $this->smarty, array($free)); $npc->selectplanets(); }
/** * Add a join object to the Criteria * * @param Join $join A join object * * @return Criteria A modified Criteria object */ public function addJoinObject(Join $join) { $isAlreadyAdded = false; foreach ($this->joins as $alreadyAddedJoin) { if ($join->equals($alreadyAddedJoin)) { $isAlreadyAdded = true; break; } } if (!$isAlreadyAdded) { $this->joins[] = $join; } return $this; }
$sql_update = "UPDATE ft_trip SET people_hadnum = :people_hadnum WHERE trip_id = :trip_id"; $people_hadnum = $get_data['total_people'] + 1; $stmt_update = $this->db->prepare($sql_update); $stmt_update->bindparam(':trip_id', $get_data['tripId']); $stmt_update->bindparam(':people_hadnum', $people_hadnum); if ($stmt_update->execute()) { $this->res['code'] = 0; $this->res['message'] = 'success'; } else { $this->db->errorInfo(); $this->res['code'] = 1023; $this->res['message'] = '更新出行表信息'; } } else { $this->db->errorInfo(); $this->res['code'] = 1024; $this->res['message'] = '记录出行信息失败'; } } } else { $this->res['code'] = 1025; $this->res['message'] = 'trip 不存在'; } } function __destruct() { $this->die_json($this->res); } } $join = new Join(); $join->index();
public function testJoinObject() { $j = new Join('TABLE_A.COL_1', 'TABLE_B.COL_2'); $this->assertEquals('INNER JOIN', $j->getJoinType()); $this->assertEquals('TABLE_A.COL_1', $j->getLeftColumn()); $this->assertEquals('TABLE_A', $j->getLeftTableName()); $this->assertEquals('COL_1', $j->getLeftColumnName()); $this->assertEquals('TABLE_B.COL_2', $j->getRightColumn()); $this->assertEquals('TABLE_B', $j->getRightTableName()); $this->assertEquals('COL_2', $j->getRightColumnName()); $j = new Join('TABLE_A.COL_1', 'TABLE_B.COL_1', Criteria::LEFT_JOIN); $this->assertEquals('LEFT JOIN', $j->getJoinType()); $this->assertEquals('TABLE_A.COL_1', $j->getLeftColumn()); $this->assertEquals('TABLE_B.COL_1', $j->getRightColumn()); $j = new Join('TABLE_A.COL_1', 'TABLE_B.COL_1', Criteria::RIGHT_JOIN); $this->assertEquals('RIGHT JOIN', $j->getJoinType()); $this->assertEquals('TABLE_A.COL_1', $j->getLeftColumn()); $this->assertEquals('TABLE_B.COL_1', $j->getRightColumn()); $j = new Join('TABLE_A.COL_1', 'TABLE_B.COL_1', Criteria::INNER_JOIN); $this->assertEquals('INNER JOIN', $j->getJoinType()); $this->assertEquals('TABLE_A.COL_1', $j->getLeftColumn()); $this->assertEquals('TABLE_B.COL_1', $j->getRightColumn()); $j = new Join(array('TABLE_A.COL_1', 'TABLE_A.COL_2'), array('TABLE_B.COL_1', 'TABLE_B.COL_2'), Criteria::INNER_JOIN); $this->assertEquals('TABLE_A.COL_1', $j->getLeftColumn(0)); $this->assertEquals('TABLE_A.COL_2', $j->getLeftColumn(1)); $this->assertEquals('TABLE_B.COL_1', $j->getRightColumn(0)); $this->assertEquals('TABLE_B.COL_2', $j->getRightColumn(1)); }
public function __toString() { return parent::toString() . ' tableMap: ' . ($this->tableMap ? get_class($this->tableMap) : 'null') . ' relationMap: ' . $this->relationMap->getName() . ' previousJoin: ' . ($this->previousJoin ? '(' . $this->previousJoin . ')' : 'null') . ' relationAlias: ' . $this->rightTableAlias; }
protected static function deleteOldVersionedFileSyncs($objectType, $objectSubType) { if (!isset(self::$oldVersionsStartUpdatedAt[$objectType])) { self::$oldVersionsStartUpdatedAt[$objectType] = 0; } if (!isset(self::$oldVersionsEndUpdatedAt[$objectType])) { self::$oldVersionsEndUpdatedAt[$objectType] = 0; } $criteria = new Criteria(); switch ($objectType) { case FileSyncObjectType::ASSET: if ($objectSubType != asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET) { return array(); } $join = new Join(); $join->addCondition(FileSyncPeer::OBJECT_ID, assetPeer::ID); $join->addCondition(FileSyncPeer::VERSION, assetPeer::VERSION, Criteria::NOT_EQUAL); $join->setJoinType(Criteria::LEFT_JOIN); $criteria->addJoinObject($join); $criteria->add(assetPeer::VERSION, null, Criteria::ISNOTNULL); break; case FileSyncObjectType::UICONF: $join = new Join(); $join->addCondition(FileSyncPeer::OBJECT_ID, uiConfPeer::ID); $join->addCondition(FileSyncPeer::VERSION, uiConfPeer::VERSION, Criteria::NOT_EQUAL); $join->setJoinType(Criteria::LEFT_JOIN); $criteria->addJoinObject($join); $criteria->add(uiConfPeer::VERSION, null, Criteria::ISNOTNULL); break; case FileSyncObjectType::ENTRY: $join = new Join(); $join->addCondition(FileSyncPeer::OBJECT_ID, entryPeer::ID); switch ($objectSubType) { case entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB: $join->addCondition(FileSyncPeer::VERSION, entryPeer::THUMBNAIL, Criteria::NOT_EQUAL); $criteria->add(entryPeer::THUMBNAIL, null, Criteria::ISNOTNULL); break; case entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA: case entry::FILE_SYNC_ENTRY_SUB_TYPE_DOWNLOAD: $join->addCondition(FileSyncPeer::VERSION, entryPeer::DATA, Criteria::NOT_EQUAL); $criteria->add(entryPeer::DATA, null, Criteria::ISNOTNULL); break; default: return array(); } $join->setJoinType(Criteria::LEFT_JOIN); $criteria->addJoinObject($join); break; case FileSyncObjectType::METADATA: $join = new Join(); $join->addCondition(FileSyncPeer::OBJECT_ID, MetadataPeer::ID); $join->addCondition(FileSyncPeer::VERSION, MetadataPeer::VERSION, Criteria::NOT_EQUAL); $join->setJoinType(Criteria::LEFT_JOIN); $criteria->addJoinObject($join); $criteria->add(MetadataPeer::VERSION, null, Criteria::ISNOTNULL); break; case FileSyncObjectType::METADATA_PROFILE: $join = new Join(); $join->addCondition(FileSyncPeer::OBJECT_ID, MetadataProfilePeer::ID); switch ($objectSubType) { case MetadataProfile::FILE_SYNC_METADATA_DEFINITION: $join->addCondition(FileSyncPeer::VERSION, MetadataProfilePeer::FILE_SYNC_VERSION, Criteria::NOT_EQUAL); $criteria->add(MetadataProfilePeer::FILE_SYNC_VERSION, null, Criteria::ISNOTNULL); break; case MetadataProfile::FILE_SYNC_METADATA_VIEWS: $join->addCondition(FileSyncPeer::VERSION, MetadataProfilePeer::VIEWS_VERSION, Criteria::NOT_EQUAL); $criteria->add(MetadataProfilePeer::VIEWS_VERSION, null, Criteria::ISNOTNULL); break; default: return array(); } $join->setJoinType(Criteria::LEFT_JOIN); $criteria->addJoinObject($join); break; default: return array(); } $criteria->add(FileSyncPeer::DC, kDataCenterMgr::getCurrentDcId()); $criteria->add(FileSyncPeer::OBJECT_TYPE, $objectType); $criteria->add(FileSyncPeer::OBJECT_SUB_TYPE, $objectSubType); $criteria->add(FileSyncPeer::STATUS, array(FileSync::FILE_SYNC_STATUS_DELETED, FileSync::FILE_SYNC_STATUS_PURGED), Criteria::NOT_IN); $nextCriteria = clone $criteria; $criteria->add(FileSyncPeer::UPDATED_AT, self::$oldVersionsStartUpdatedAt[$objectType], Criteria::GREATER_EQUAL); $criteria->addAnd(FileSyncPeer::UPDATED_AT, self::$oldVersionsEndUpdatedAt[$objectType], Criteria::LESS_EQUAL); $criteria->addAscendingOrderByColumn(FileSyncPeer::UPDATED_AT); $criteria->setLimit(self::$queryLimit); $fileSyncs = FileSyncPeer::doSelect($criteria); if (count($fileSyncs)) { foreach ($fileSyncs as $fileSync) { /* @var $fileSync FileSync */ self::deleteFileSync($fileSync); if ($fileSync->getUpdatedAt(null)) { self::$oldVersionsNextStartUpdatedAt[$objectType] = $fileSync->getUpdatedAt(null); } } } else { self::$oldVersionsNextStartUpdatedAt[$objectType] = self::$oldVersionsStartUpdatedAt[$objectType]; $nextCriteria->add(FileSyncPeer::UPDATED_AT, self::$oldVersionsStartUpdatedAt[$objectType], Criteria::GREATER_THAN); $nextCriteria->addSelectColumn('UNIX_TIMESTAMP(MIN(' . FileSyncPeer::UPDATED_AT . '))'); $stmt = FileSyncPeer::doSelectStmt($nextCriteria); $mins = $stmt->fetchAll(PDO::FETCH_COLUMN); if (count($mins)) { $oldVersionsNextStartUpdatedAt = reset($mins); if (!is_null($oldVersionsNextStartUpdatedAt)) { self::$oldVersionsNextStartUpdatedAt[$objectType] = $oldVersionsNextStartUpdatedAt; } } } kMemoryManager::clearMemory(); }
/** * Add a join with multiple conditions * @deprecated use Join::setJoinCondition($criterion) instead * * @see http://propel.phpdb.org/trac/ticket/167, http://propel.phpdb.org/trac/ticket/606 * * Example usage: * $c->addMultipleJoin(array( * array(LeftPeer::LEFT_COLUMN, RightPeer::RIGHT_COLUMN), // if no third argument, defaults to Criteria::EQUAL * array(FoldersPeer::alias( 'fo', FoldersPeer::LFT ), FoldersPeer::alias( 'parent', FoldersPeer::RGT ), Criteria::LESS_EQUAL ) * ), * Criteria::LEFT_JOIN * ); * * @see addJoin() * @param array $conditions An array of conditions, each condition being an array (left, right, operator) * @param string $joinType A String with the join operator. Defaults to an implicit join. * * @return Criteria A modified Criteria object. */ public function addMultipleJoin($conditions, $joinType = null) { $join = new Join(); $joinCondition = null; foreach ($conditions as $condition) { $left = $condition[0]; $right = $condition[1]; if ($pos = strrpos($left, '.')) { $leftTableAlias = substr($left, 0, $pos); $leftColumnName = substr($left, $pos + 1); list($leftTableName, $leftTableAlias) = $this->getTableNameAndAlias($leftTableAlias); } else { list($leftTableName, $leftTableAlias) = array(null, null); $leftColumnName = $left; } if ($pos = strrpos($right, '.')) { $rightTableAlias = substr($right, 0, $pos); $rightColumnName = substr($right, $pos + 1); list($rightTableName, $rightTableAlias) = $this->getTableNameAndAlias($rightTableAlias); } else { list($rightTableName, $rightTableAlias) = array(null, null); $rightColumnName = $right; } if (!$join->getRightTableName()) { $join->setRightTableName($rightTableName); } if (!$join->getRightTableAlias()) { $join->setRightTableAlias($rightTableAlias); } $conditionClause = $leftTableAlias ? $leftTableAlias . '.' : ($leftTableName ? $leftTableName . '.' : ''); $conditionClause .= $leftColumnName; $conditionClause .= isset($condition[2]) ? $condition[2] : JOIN::EQUAL; $conditionClause .= $rightTableAlias ? $rightTableAlias . '.' : ($rightTableName ? $rightTableName . '.' : ''); $conditionClause .= $rightColumnName; $criterion = $this->getNewCriterion($leftTableName . '.' . $leftColumnName, $conditionClause, Criteria::CUSTOM); if (null === $joinCondition) { $joinCondition = $criterion; } else { $joinCondition = $joinCondition->addAnd($criterion); } } $join->setJoinType($joinType); $join->setJoinCondition($joinCondition); return $this->addJoinObject($join); }
public function __construct($entityClassName, $alias, $withCondition) { parent::__construct($entityClassName, $alias); $this->withCondition = $withCondition; }
public function testCountConditions() { $j = new Join(); $this->assertEquals(0, $j->countConditions()); $j->addCondition('foo', 'bar'); $this->assertEquals(1, $j->countConditions()); $j->addCondition('foo1', 'bar1'); $this->assertEquals(2, $j->countConditions()); }
protected function joinConditions(Join $join) { $sqls = []; $i = 0; foreach ($join->getConditions() as $condition) { $sql = $this->{$condition['type']}($condition); if ($i++ > 0) { $sql = $condition['separator'] . ' ' . $sql; } } return implode(' ', $sqls); }