public function testScanningAndCoding()
{
$toolbox = R::getToolBox();
$adapter = $toolbox->getDatabaseAdapter();
$writer = $toolbox->getWriter();
$redbean = $toolbox->getRedBean();
$pdo = $adapter->getDatabase();
$a = new AssociationManager($toolbox);
$adapter->exec("DROP TABLE IF EXISTS testtable");
asrt(in_array("testtable", $writer->getTables()), FALSE);
$writer->createTable("testtable");
asrt(in_array("testtable", $writer->getTables()), TRUE);
asrt(count(array_keys($writer->getColumns("testtable"))), 1);
asrt(in_array("id", array_keys($writer->getColumns("testtable"))), TRUE);
asrt(in_array("c1", array_keys($writer->getColumns("testtable"))), FALSE);
$writer->addColumn("testtable", "c1", 1);
asrt(count(array_keys($writer->getColumns("testtable"))), 2);
asrt(in_array("c1", array_keys($writer->getColumns("testtable"))), TRUE);
foreach ($writer->sqltype_typeno as $key => $type) {
if ($type < 100) {
asrt($writer->code($key, TRUE), $type);
} else {
asrt($writer->code($key), PostgreSQL::C_DATATYPE_SPECIFIED);
}
}
asrt($writer->code(PostgreSQL::C_DATATYPE_SPECIAL_DATETIME), PostgreSQL::C_DATATYPE_SPECIFIED);
asrt($writer->code("unknown"), PostgreSQL::C_DATATYPE_SPECIFIED);
asrt($writer->scanType(FALSE), PostgreSQL::C_DATATYPE_INTEGER);
asrt($writer->scanType(TRUE), PostgreSQL::C_DATATYPE_INTEGER);
asrt($writer->scanType(NULL), PostgreSQL::C_DATATYPE_INTEGER);
asrt($writer->scanType(2), PostgreSQL::C_DATATYPE_INTEGER);
asrt($writer->scanType(255), PostgreSQL::C_DATATYPE_INTEGER);
asrt($writer->scanType(256), PostgreSQL::C_DATATYPE_INTEGER);
asrt($writer->scanType(-1), PostgreSQL::C_DATATYPE_INTEGER);
asrt($writer->scanType(1.5), PostgreSQL::C_DATATYPE_DOUBLE);
asrt($writer->scanType(INF), PostgreSQL::C_DATATYPE_TEXT);
asrt($writer->scanType("abc"), PostgreSQL::C_DATATYPE_TEXT);
asrt($writer->scanType("2001-10-10", TRUE), PostgreSQL::C_DATATYPE_SPECIAL_DATE);
asrt($writer->scanType("2001-10-10 10:00:00", TRUE), PostgreSQL::C_DATATYPE_SPECIAL_DATETIME);
asrt($writer->scanType("2001-10-10 10:00:00"), PostgreSQL::C_DATATYPE_TEXT);
asrt($writer->scanType("2001-10-10"), PostgreSQL::C_DATATYPE_TEXT);
asrt($writer->scanType(str_repeat("lorem ipsum", 100)), PostgreSQL::C_DATATYPE_TEXT);
$writer->widenColumn("testtable", "c1", PostgreSQL::C_DATATYPE_TEXT);
$cols = $writer->getColumns("testtable");
asrt($writer->code($cols["c1"]), PostgreSQL::C_DATATYPE_TEXT);
$writer->addColumn("testtable", "special", PostgreSQL::C_DATATYPE_SPECIAL_DATE);
$cols = $writer->getColumns("testtable");
asrt($writer->code($cols['special'], TRUE), PostgreSQL::C_DATATYPE_SPECIAL_DATE);
asrt($writer->code($cols['special'], FALSE), PostgreSQL::C_DATATYPE_SPECIFIED);
$writer->addColumn("testtable", "special2", PostgreSQL::C_DATATYPE_SPECIAL_DATETIME);
$cols = $writer->getColumns("testtable");
asrt($writer->code($cols['special2'], TRUE), PostgreSQL::C_DATATYPE_SPECIAL_DATETIME);
asrt($writer->code($cols['special'], FALSE), PostgreSQL::C_DATATYPE_SPECIFIED);
//$id = $writer->insertRecord("testtable", array("c1"), array(array("lorem ipsum")));
$id = $writer->updateRecord("testtable", array(array("property" => "c1", "value" => "lorem ipsum")));
$row = $writer->queryRecord("testtable", array("id" => array($id)));
asrt($row[0]["c1"], "lorem ipsum");
$writer->updateRecord("testtable", array(array("property" => "c1", "value" => "ipsum lorem")), $id);
$row = $writer->queryRecord("testtable", array("id" => array($id)));
asrt($row[0]["c1"], "ipsum lorem");
$writer->deleteRecord("testtable", array("id" => array($id)));
$row = $writer->queryRecord("testtable", array("id" => array($id)));
asrt(empty($row), TRUE);
}