Example #1
0
 /**
  * @covers \Cougar\PDO\PDO::exec
  * @covers \Cougar\PDO\PDO::queryFetchAll
  * @covers \Cougar\PDO\PDO::queryFetchRow
  * @covers \Cougar\PDO\PDO::queryFetchColumn
  * @covers \Cougar\PDO\PDO::lastInsertId
  * @covers \Cougar\PDO\PDO::establishConnection
  */
 public function testExec()
 {
     # Update
     $rows = $this->object->exec("UPDATE UnitTest SET BlobValue = 'Blob'");
     $this->assertEquals(5, $rows);
     # Get data
     $data = $this->object->queryFetchAll("SELECT * FROM UnitTest");
     $this->assertCount(5, $data);
     $this->assertCount(8, $data[0]);
     $row_id = $data[0]["RowID"];
     # Update with parameters
     $rows = $this->object->exec("UPDATE UnitTest\n            SET FloatValue = :float_value WHERE RowID = :row_id", array("float_value" => 12.12, "row_id" => $row_id));
     $this->assertEquals(1, $rows);
     # Insert with parameters
     $date = date("Y-m-d H:i:s");
     $rows = $this->object->exec("INSERT INTO UnitTest\n            (BinaryValue, StringValue, IntegerValue, FloatValue, BlobValue,\n                DateTimeValue)\n            VALUES(:binaryValue, :stringValue, :integerValue, :floatValue,\n                :blobValue, :dateTimeValue)", array("binaryValue" => "Binary", "stringValue" => "String Value", "integerValue" => 15, "floatValue" => 15.15, "blobValue" => str_repeat("Xx", 10000), "dateTimeValue" => $date));
     $this->assertEquals(1, $rows);
     $row_id = $this->object->lastInsertId();
     $row = $this->object->queryFetchRow("SELECT * FROM UnitTest\n            WHERE RowID = :row_id", array("row_id" => $row_id));
     $this->assertCount(8, $row);
     $this->assertEquals("Binary", $row["BinaryValue"]);
     $this->assertEquals("String Value", $row["StringValue"]);
     $this->assertEquals(15, $row["IntegerValue"]);
     $this->assertEquals(15.15, $row["FloatValue"]);
     $this->assertEquals(str_repeat("Xx", 10000), $row["BlobValue"]);
     $this->assertEquals($date, $row["DateTimeValue"]);
     # Delete with parameters
     $rows = $this->object->exec("DELETE FROM UnitTest\n            WHERE RowID = :row_id", array("row_id" => $row_id));
     $this->assertEquals(1, $rows);
     $this->assertEquals(5, $this->object->queryFetchColumn("SELECT COUNT(*) FROM UnitTest"));
 }