Exemple #1
0
 /**
  * @covers SphinxSearch\Db\Sql\Replace::getSqlString
  */
 public function testGetSqlString()
 {
     $this->replace->into('foo')->values(array('bar' => 'baz', 'boo' => new Expression('NOW()'), 'bam' => null));
     $this->assertEquals('REPLACE INTO `foo` (`bar`, `boo`, `bam`) VALUES (\'baz\', NOW(), NULL)', $this->replace->getSqlString(new TrustedSphinxQL()));
     // with TableIdentifier
     $this->replace = new Replace();
     $this->replace->into(new TableIdentifier('foo'))->values(array('bar' => 'baz', 'boo' => new Expression('NOW()'), 'bam' => null));
     $this->assertEquals('REPLACE INTO `foo` (`bar`, `boo`, `bam`) VALUES (\'baz\', NOW(), NULL)', $this->replace->getSqlString(new TrustedSphinxQL()));
 }
 /**
  * @depends testConnection
  */
 public function testTypeWithSql()
 {
     $this->adapter->query('DELETE FROM foo WHERE id = 1', Adapter::QUERY_MODE_EXECUTE);
     $search = new Search($this->adapter);
     $search->setQueryMode($search::QUERY_MODE_EXECUTE);
     $indexer = new Indexer($this->adapter);
     $indexer->setQueryMode($indexer::QUERY_MODE_EXECUTE);
     $sql = new Sql($this->adapter);
     //test Replace with sql query
     $insert = new Replace('foo');
     $insert->values(['id' => 1, 'c1' => 10, 'c2' => true, 'c3' => '5', 'f1' => 3.333]);
     $affectedRow = $indexer->insertWith($insert);
     $this->assertEquals(1, $affectedRow);
     $select = new Select('foo');
     $select->where(['id' => 1]);
     //test select sql
     $results = $search->searchWith($select);
     foreach ($results as $result) {
         $this->assertEquals(1, $result['id']);
         $this->assertEquals(10, $result['c1']);
         $this->assertEquals(1, $result['c2']);
         $this->assertEquals(5, $result['c3']);
         $this->assertEquals(3.333, $result['f1']);
         break;
     }
     $select = new Select('foo');
     $select->where(['f1' => 3.333]);
     //test select sql with float in where and direct adapter execution
     $results = $this->adapter->query($sql->getSqlStringForSqlObject($select), Adapter::QUERY_MODE_EXECUTE);
     foreach ($results as $result) {
         $this->assertEquals(1, $result['id']);
         $this->assertEquals(10, $result['c1']);
         $this->assertEquals(1, $result['c2']);
         $this->assertEquals(5, $result['c3']);
         $this->assertEquals(3.333, $result['f1']);
         break;
     }
 }