示例#1
0
 /**
  * Binds a value to a positioned parameter in a statement,
  * given a ColumnMap object to infer the binding type.
  *
  * @param StatementInterface $stmt      The statement to bind
  * @param string             $parameter Parameter identifier
  * @param mixed              $value     The value to bind
  * @param ColumnMap          $cMap      The ColumnMap of the column to bind
  * @param null|integer       $position  The position of the parameter to bind
  *
  * @return boolean
  */
 public function bindValue(StatementInterface $stmt, $parameter, $value, ColumnMap $cMap, $position = null)
 {
     if ($cMap->isTemporal()) {
         $value = $this->formatTemporalValue($value, $cMap);
     } elseif (is_resource($value) && $cMap->isLob()) {
         // we always need to make sure that the stream is rewound, otherwise nothing will
         // get written to database.
         rewind($value);
     }
     return $stmt->bindValue($parameter, $value, $cMap->getPdoType());
 }
示例#2
0
 /**
  * @see       DBAdapter::bindValue()
  *
  * @param     PDOStatement  $stmt
  * @param     string        $parameter
  * @param     mixed         $value
  * @param     ColumnMap     $cMap
  * @param     null|integer  $position
  *
  * @return    boolean
  */
 public function bindValue(PDOStatement $stmt, $parameter, $value, ColumnMap $cMap, $position = null)
 {
     if ($cMap->isTemporal()) {
         $value = $this->formatTemporalValue($value, $cMap);
     } elseif ($cMap->getType() == PropelColumnTypes::CLOB_EMU) {
         return $stmt->bindParam(':p' . $position, $value, $cMap->getPdoType(), strlen($value));
     } elseif (is_resource($value) && $cMap->isLob()) {
         // we always need to make sure that the stream is rewound, otherwise nothing will
         // get written to database.
         rewind($value);
     }
     return $stmt->bindValue($parameter, $value, $cMap->getPdoType());
 }
 /**
  * @see AdapterInterface::bindValue()
  *
  * @param StatementInterface $stmt
  * @param string             $parameter
  * @param mixed              $value
  * @param ColumnMap          $cMap
  * @param null|integer       $position
  *
  * @return boolean
  */
 public function bindValue(StatementInterface $stmt, $parameter, $value, ColumnMap $cMap, $position = null)
 {
     $pdoType = $cMap->getPdoType();
     // FIXME - This is a temporary hack to get around apparent bugs w/ PDO+MYSQL
     // See http://pecl.php.net/bugs/bug.php?id=9919
     if (\PDO::PARAM_BOOL === $pdoType) {
         $value = (int) $value;
         $pdoType = \PDO::PARAM_INT;
         return $stmt->bindValue($parameter, $value, $pdoType);
     }
     if ($cMap->isTemporal()) {
         $value = $this->formatTemporalValue($value, $cMap);
     } elseif (is_resource($value) && $cMap->isLob()) {
         // we always need to make sure that the stream is rewound, otherwise nothing will
         // get written to database.
         rewind($value);
     }
     return $stmt->bindValue($parameter, $value, $pdoType);
 }
示例#4
0
 /**
  * @see AdapterInterface::bindValue()
  *
  * @param PDOStatement $stmt
  * @param string       $parameter
  * @param mixed        $value
  * @param ColumnMap    $cMap
  * @param null|integer $position
  *
  * @return boolean
  */
 public function bindValue(StatementInterface $stmt, $parameter, $value, ColumnMap $cMap, $position = null)
 {
     if ($cMap->isTemporal()) {
         $value = $this->formatTemporalValue($value, $cMap);
     } elseif (is_resource($value) && $cMap->isLob()) {
         // we always need to make sure that the stream is rewound, otherwise nothing will
         // get written to database.
         rewind($value);
         // pdo_sqlsrv must have bind binaries using bindParam so that the PDO::SQLSRV_ENCODING_BINARY
         // driver option can be utilized. This requires a unique blob parameter because the bindParam
         // value is passed by reference and if we didn't do this then the referenced parameter value
         // would change on the next loop
         $blob = 'blob' . $position;
         ${$blob} = $value;
         return $stmt->bindParam($parameter, ${$blob}, \PDO::PARAM_LOB, 0, \PDO::SQLSRV_ENCODING_BINARY);
     }
     return $stmt->bindValue($parameter, $value, $cMap->getPdoType());
 }
 /**
  * @param ColumnMap $column
  * @return \Closure|null
  */
 public function guessFormat(ColumnMap $column)
 {
     $generator = $this->generator;
     if ($column->isTemporal()) {
         if ($column->getType() == PropelTypes::BU_DATE || $column->getType() == PropelTypes::BU_TIMESTAMP) {
             return function () use($generator) {
                 return $generator->dateTime;
             };
         } else {
             return function () use($generator) {
                 return $generator->dateTimeAD;
             };
         }
     }
     $type = $column->getType();
     switch ($type) {
         case PropelTypes::BOOLEAN:
         case PropelTypes::BOOLEAN_EMU:
             return function () use($generator) {
                 return $generator->boolean;
             };
         case PropelTypes::NUMERIC:
         case PropelTypes::DECIMAL:
             $size = $column->getSize();
             return function () use($generator, $size) {
                 return $generator->randomNumber($size + 2) / 100;
             };
         case PropelTypes::TINYINT:
             return function () {
                 return mt_rand(0, 127);
             };
         case PropelTypes::SMALLINT:
             return function () {
                 return mt_rand(0, 32767);
             };
         case PropelTypes::INTEGER:
             return function () {
                 return mt_rand(0, intval('2147483647'));
             };
         case PropelTypes::BIGINT:
             return function () {
                 return mt_rand(0, intval('9223372036854775807'));
             };
         case PropelTypes::FLOAT:
             return function () {
                 return mt_rand(0, intval('2147483647')) / mt_rand(1, intval('2147483647'));
             };
         case PropelTypes::DOUBLE:
         case PropelTypes::REAL:
             return function () {
                 return mt_rand(0, intval('9223372036854775807')) / mt_rand(1, intval('9223372036854775807'));
             };
         case PropelTypes::CHAR:
         case PropelTypes::VARCHAR:
         case PropelTypes::BINARY:
         case PropelTypes::VARBINARY:
             $size = $column->getSize();
             return function () use($generator, $size) {
                 return $generator->text($size);
             };
         case PropelTypes::LONGVARCHAR:
         case PropelTypes::LONGVARBINARY:
         case PropelTypes::CLOB:
         case PropelTypes::CLOB_EMU:
         case PropelTypes::BLOB:
             return function () use($generator) {
                 return $generator->text;
             };
         case PropelTypes::ENUM:
             $valueSet = $column->getValueSet();
             return function () use($generator, $valueSet) {
                 return $generator->randomElement($valueSet);
             };
         case PropelTypes::OBJECT:
         case PropelTypes::PHP_ARRAY:
         default:
             // no smart way to guess what the user expects here
             return null;
     }
 }