當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Criteria::getTableName方法代碼示例

本文整理匯總了PHP中Propel\Runtime\ActiveQuery\Criteria::getTableName方法的典型用法代碼示例。如果您正苦於以下問題:PHP Criteria::getTableName方法的具體用法?PHP Criteria::getTableName怎麽用?PHP Criteria::getTableName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Propel\Runtime\ActiveQuery\Criteria的用法示例。


在下文中一共展示了Criteria::getTableName方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getPrimaryKey

 /**
  * Helper method which returns the primary key contained
  * in the given Criteria object.
  *
  * @param  Criteria  $criteria A Criteria.
  * @return ColumnMap If the Criteria object contains a primary key, or null if it doesn't.
  *
  * @throws \Propel\Runtime\Exception\RuntimeException
  */
 private static function getPrimaryKey(Criteria $criteria)
 {
     // Assume all the keys are for the same table.
     $keys = $criteria->keys();
     $key = $keys[0];
     $table = $criteria->getTableName($key);
     $pk = null;
     if (!empty($table)) {
         $dbMap = Propel::getServiceContainer()->getDatabaseMap($criteria->getDbName());
         $pks = $dbMap->getTable($table)->getPrimaryKeys();
         if (!empty($pks)) {
             $pk = array_shift($pks);
         }
     }
     return $pk;
 }
開發者ID:KyleGoslan,項目名稱:Huge-Propel,代碼行數:25,代碼來源:TableMap.php

示例2: doInsert

 /**
  * Method to perform inserts based on values and keys in a
  * Criteria.
  * <p>
  * If the primary key is auto incremented the data in Criteria
  * will be inserted and the auto increment value will be returned.
  * <p>
  * If the primary key is included in Criteria then that value will
  * be used to insert the row.
  * <p>
  * If no primary key is included in Criteria then we will try to
  * figure out the primary key from the database map and insert the
  * row with the next available id using util.db.IDBroker.
  * <p>
  * If no primary key is defined for the table the values will be
  * inserted as specified in Criteria and null will be returned.
  *
  * @param  Criteria            $criteria Object containing values to insert.
  * @param  ConnectionInterface $con      A ConnectionInterface connection.
  * @return mixed               The primary key for the new row if the primary key is auto-generated. Otherwise will return null.
  *
  * @throws \Propel\Runtime\Exception\RuntimeException
  */
 public static function doInsert($criteria, ConnectionInterface $con = null)
 {
     // The primary key
     $id = null;
     if (null === $con) {
         $con = Propel::getServiceContainer()->getWriteConnection($criteria->getDbName());
     }
     $db = Propel::getServiceContainer()->getAdapter($criteria->getDbName());
     // Get the table name and method for determining the primary
     // key value.
     $keys = $criteria->keys();
     if (!empty($keys)) {
         $tableName = $criteria->getTableName($keys[0]);
     } else {
         throw new RuntimeException('Database insert attempted without anything specified to insert.');
     }
     $tableName = $criteria->getTableName($keys[0]);
     $dbMap = Propel::getServiceContainer()->getDatabaseMap($criteria->getDbName());
     $tableMap = $dbMap->getTable($tableName);
     $keyInfo = $tableMap->getPrimaryKeyMethodInfo();
     $useIdGen = $tableMap->isUseIdGenerator();
     //$keyGen = $con->getIdGenerator();
     $pk = static::getPrimaryKey($criteria);
     // only get a new key value if you need to
     // the reason is that a primary key might be defined
     // but you are still going to set its value. for example:
     // a join table where both keys are primary and you are
     // setting both columns with your own values
     // pk will be null if there is no primary key defined for the table
     // we're inserting into.
     if (null !== $pk && $useIdGen && !$criteria->keyContainsValue($pk->getFullyQualifiedName()) && $db->isGetIdBeforeInsert()) {
         try {
             $id = $db->getId($con, $keyInfo);
         } catch (\Exception $e) {
             throw new RuntimeException('Unable to get sequence id.', 0, $e);
         }
         $criteria->add($pk->getFullyQualifiedName(), $id);
     }
     try {
         $adapter = Propel::getServiceContainer()->getAdapter($criteria->getDBName());
         $qualifiedCols = $criteria->keys();
         // we need table.column cols when populating values
         $columns = array();
         // but just 'column' cols for the SQL
         foreach ($qualifiedCols as $qualifiedCol) {
             $columns[] = substr($qualifiedCol, strrpos($qualifiedCol, '.') + 1);
         }
         // add identifiers
         if ($adapter->useQuoteIdentifier()) {
             $columns = array_map(array($adapter, 'quoteIdentifier'), $columns);
             $tableName = $adapter->quoteIdentifierTable($tableName);
         }
         $sql = 'INSERT INTO ' . $tableName . ' (' . implode(',', $columns) . ')' . ' VALUES (';
         // . substr(str_repeat("?,", count($columns)), 0, -1) .
         for ($p = 1, $cnt = count($columns); $p <= $cnt; $p++) {
             $sql .= ':p' . $p;
             if ($p !== $cnt) {
                 $sql .= ',';
             }
         }
         $sql .= ')';
         $params = static::buildParams($qualifiedCols, $criteria);
         $db->cleanupSQL($sql, $params, $criteria, $dbMap);
         $stmt = $con->prepare($sql);
         $db->bindValues($stmt, $params, $dbMap, $db);
         $stmt->execute();
     } catch (\Exception $e) {
         Propel::log($e->getMessage(), Propel::LOG_ERR);
         throw new RuntimeException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e);
     }
     // If the primary key column is auto-incremented, get the id now.
     if (null !== $pk && $useIdGen && $db->isGetIdAfterInsert()) {
         try {
             $id = $db->getId($con, $keyInfo);
         } catch (\Exception $e) {
             throw new RuntimeException("Unable to get autoincrement id.", 0, $e);
         }
//.........這裏部分代碼省略.........
開發者ID:kalaspuffar,項目名稱:php-orm-benchmark,代碼行數:101,代碼來源:TableMap.php


注:本文中的Propel\Runtime\ActiveQuery\Criteria::getTableName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。