function testDatabaseQueryLoadsValuesInCorrectOrder()
 {
     $name1 = 'paramName1';
     $val1 = 'value1';
     $name2 = 'paramName2';
     $val2 = 'value2';
     $cn = new FakeDBConnection();
     $db = new Database($cn);
     $p1 = new Parameter($name1, $val1);
     $p2 = new Parameter($name2, $val2);
     $parameters = new Parameters();
     $parameters->Add($p1);
     $parameters->Add($p2);
     $command = new SqlCommand("SELECT * FROM sometable WHERE col1 = @{$name1} AND col2 = @{$name2}");
     $command->SetParameters($parameters);
     $adapter = new Mdb2CommandAdapter($command);
     $vals = $adapter->GetValues();
     $this->assertEquals(2, count($vals));
     $this->assertEquals($val1, $vals[$name1]);
     $this->assertEquals($val2, $vals[$name2]);
     $this->assertEquals("SELECT * FROM sometable WHERE col1 = :{$name1} AND col2 = :{$name2}", $adapter->GetQuery());
 }
Example #2
0
 public function _PrepareAndExecute(ISqlCommand &$sqlCommand, $prepareType)
 {
     $cmd = new Mdb2CommandAdapter($sqlCommand);
     $stmt =& $this->_db->prepare($cmd->GetQuery(), true, $prepareType);
     if (MDB2::isError($stmt)) {
         throw new Exception('Error preparing MDB2 command. Query=%s. Error=%s', $sqlCommand->__toString(), $stmt->getMessage());
     }
     $result =& $stmt->execute($cmd->GetValues());
     if (MDB2::isError($result)) {
         throw new Exception('Error executing MDB2 command. Query=%s. Error=%s', $sqlCommand->__toString(), $stmt->getMessage());
     }
     return new Mdb2Reader($result);
 }