public function testGetExpressionData()
 {
     $subject = new Expression('? = ?', array(33.0, true));
     $this->expr->setSubject($subject);
     $this->platform->enableFloatConversion(false);
     $this->assertSame(array(array('%s = %s', array(33.0, 1), array(Expression::TYPE_VALUE, Expression::TYPE_VALUE))), $this->expr->getExpressionData());
     $platform = new TrustedSphinxQL();
     // Use platform to ensure same float point precision
     $platform->enableFloatConversion(true);
     $this->platform->enableFloatConversion(true);
     $this->assertSame(array(array('%s = %s', array($platform->quoteTrustedValue(33.0), 1), array(Expression::TYPE_LITERAL, Expression::TYPE_VALUE))), $this->expr->getExpressionData());
 }
 /**
  * @param array|\Zend\Db\Adapter\Driver\DriverInterface $config
  * @throws UnsupportedDriverException
  * @return \Zend\Db\Adapter\Adapter
  */
 public static function factory($config)
 {
     $platform = new SphinxQL();
     $adapter = new ZendDBAdapter($config, $platform);
     $driver = $adapter->getDriver();
     // Check driver
     if ($driver instanceof ZendPdoDriver && $driver->getDatabasePlatformName(ZendPdoDriver::NAME_FORMAT_CAMELCASE) == 'Mysql') {
         $driver->registerStatementPrototype(new PdoStatement());
     } elseif (!$driver instanceof ZendMysqliDriver) {
         $class = get_class($driver);
         throw new UnsupportedDriverException($class . ' not supported. Use Zend\\Db\\Adapter\\Driver\\Pdo\\Pdo or Zend\\Db\\Adapter\\Driver\\Mysqli\\Mysqli');
     }
     $platform->setDriver($adapter->getDriver());
     return $adapter;
 }
Пример #3
0
 /**
  *
  * @return array of array|string should return an array in the format:
  *
  * array (
  *    // a sprintf formatted string
  *    string $specification,
  *
  *    // the values for the above sprintf formatted string
  *    array $values,
  *
  *    // an array of equal length of the $values array, with either TYPE_IDENTIFIER or TYPE_VALUE for each value
  *    array $types,
  * )
  *
  */
 public function getExpressionData()
 {
     $expressionData = $this->subject->getExpressionData();
     foreach ($expressionData as &$expressionPart) {
         if (!is_array($expressionPart)) {
             continue;
         }
         $parametersCount = count($expressionPart[1]);
         for ($i = 0; $i < $parametersCount; $i++) {
             if ($this->platform->isFloatConversionEnabled() && is_float($expressionPart[1][$i]) && $expressionPart[2][$i] == Expression::TYPE_VALUE) {
                 $expressionPart[1][$i] = $this->platform->toFloatSinglePrecision($expressionPart[1][$i]);
                 $expressionPart[2][$i] = Expression::TYPE_LITERAL;
             }
             if (is_bool($expressionPart[1][$i]) && $expressionPart[2][$i] == Expression::TYPE_VALUE) {
                 $expressionPart[1][$i] = (int) $expressionPart[1][$i];
             }
         }
     }
     return $expressionData;
 }
 /**
  * Create a DB adapter
  *
  * @param  ServiceLocatorInterface $services
  * @param  string $name
  * @param  string $requestedName
  * @throws Exception\UnsupportedDriverException
  * @return \Zend\Db\Adapter\Adapter
  */
 public function createServiceWithName(ServiceLocatorInterface $services, $name, $requestedName)
 {
     $config = $this->getConfig($services);
     $platform = new SphinxQL();
     $adapter = new ZendDBAdapter($config[$requestedName], $platform);
     $driver = $adapter->getDriver();
     // Check driver
     if ($driver instanceof ZendPdoDriver && $driver->getDatabasePlatformName(ZendPdoDriver::NAME_FORMAT_CAMELCASE) == 'Mysql') {
         $driver->registerStatementPrototype(new PdoStatement());
     } elseif (!$driver instanceof ZendMysqliDriver) {
         $class = get_class($driver);
         throw new UnsupportedDriverException($class . ' not supported. Use Zend\\Db\\Adapter\\Driver\\Pdo\\Pdo or Zend\\Db\\Adapter\\Driver\\Mysqli\\Mysqli');
     }
     $platform->setDriver($adapter->getDriver());
     return $adapter;
 }
Пример #5
0
 public function testFloatConversion()
 {
     //assume default enabled
     $this->assertTrue($this->platform->isFloatConversionEnabled());
     $this->assertInstanceOf('\\SphinxSearch\\Db\\Adapter\\Platform\\SphinxQL', $this->platform->enableFloatConversion(false));
     $this->assertFalse($this->platform->isFloatConversionEnabled());
     $this->platform->enableFloatConversion(true);
     $this->assertTrue($this->platform->isFloatConversionEnabled());
     //test default param value in method
     $this->platform->enableFloatConversion();
     $this->assertTrue($this->platform->isFloatConversionEnabled());
     $singlePrecisionPi = '3.141592654';
     $doublePrecisionPi = '3.1415926535898';
     $this->assertSame($singlePrecisionPi, $this->platform->toFloatSinglePrecision(pi()));
     $this->platform->enableFloatConversion(false);
     $this->assertSame($doublePrecisionPi, $this->platform->quoteTrustedValue(pi()));
     $this->platform->enableFloatConversion(true);
     $this->assertSame($singlePrecisionPi, $this->platform->quoteTrustedValue(pi()));
 }