RedUNIT\Mysql\Writer::testScanningAndCoding PHP Method

testScanningAndCoding() public method

Test scanning and coding of values.
public testScanningAndCoding ( ) : void
return void
    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", $adapter->getCol("show tables")), FALSE);
        $writer->createTable("testtable");
        asrt(in_array("testtable", $adapter->getCol("show tables")), TRUE);
        asrt(count(array_diff($writer->getTables(), $adapter->getCol("show tables"))), 0);
        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", MySQL::C_DATATYPE_UINT32);
        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, TRUE), MySQL::C_DATATYPE_SPECIFIED);
            }
        }
        asrt($writer->code(MySQL::C_DATATYPE_SPECIAL_DATETIME), MySQL::C_DATATYPE_SPECIFIED);
        asrt($writer->code("unknown"), MySQL::C_DATATYPE_SPECIFIED);
        asrt($writer->scanType(FALSE), MySQL::C_DATATYPE_BOOL);
        asrt($writer->scanType(TRUE), MySQL::C_DATATYPE_BOOL);
        asrt($writer->scanType(INF), MySQL::C_DATATYPE_TEXT7);
        asrt($writer->scanType(NULL), MySQL::C_DATATYPE_BOOL);
        asrt($writer->scanType(2), MySQL::C_DATATYPE_UINT32);
        asrt($writer->scanType(255), MySQL::C_DATATYPE_UINT32);
        //no more uint8
        asrt($writer->scanType(256), MySQL::C_DATATYPE_UINT32);
        asrt($writer->scanType(-1), MySQL::C_DATATYPE_DOUBLE);
        asrt($writer->scanType(1.5), MySQL::C_DATATYPE_DOUBLE);
        asrt($writer->scanType("abc"), MySQL::C_DATATYPE_TEXT7);
        asrt($writer->scanType(str_repeat('abcd', 100000)), MySQL::C_DATATYPE_TEXT32);
        asrt($writer->scanType("2001-10-10", TRUE), MySQL::C_DATATYPE_SPECIAL_DATE);
        asrt($writer->scanType("2001-10-10 10:00:00", TRUE), MySQL::C_DATATYPE_SPECIAL_DATETIME);
        asrt($writer->scanType("2001-10-10"), MySQL::C_DATATYPE_TEXT7);
        asrt($writer->scanType("2001-10-10 10:00:00"), MySQL::C_DATATYPE_TEXT7);
        asrt($writer->scanType("1.23", TRUE), MySQL::C_DATATYPE_SPECIAL_MONEY);
        asrt($writer->scanType("12.23", TRUE), MySQL::C_DATATYPE_SPECIAL_MONEY);
        asrt($writer->scanType("124.23", TRUE), MySQL::C_DATATYPE_SPECIAL_MONEY);
        asrt($writer->scanType(str_repeat("lorem ipsum", 100)), MySQL::C_DATATYPE_TEXT16);
        $writer->widenColumn("testtable", "c1", MySQL::C_DATATYPE_UINT32);
        $writer->addColumn("testtable", "special", MySQL::C_DATATYPE_SPECIAL_DATE);
        $cols = $writer->getColumns("testtable");
        asrt($writer->code($cols['special'], TRUE), MySQL::C_DATATYPE_SPECIAL_DATE);
        asrt($writer->code($cols['special'], FALSE), MySQL::C_DATATYPE_SPECIFIED);
        $writer->addColumn("testtable", "special2", MySQL::C_DATATYPE_SPECIAL_DATETIME);
        $cols = $writer->getColumns("testtable");
        asrt($writer->code($cols['special2'], TRUE), MySQL::C_DATATYPE_SPECIAL_DATETIME);
        asrt($writer->code($cols['special'], FALSE), MySQL::C_DATATYPE_SPECIFIED);
        $cols = $writer->getColumns("testtable");
        asrt($writer->code($cols["c1"]), MySQL::C_DATATYPE_UINT32);
        $writer->widenColumn("testtable", "c1", MySQL::C_DATATYPE_DOUBLE);
        $cols = $writer->getColumns("testtable");
        asrt($writer->code($cols["c1"]), MySQL::C_DATATYPE_DOUBLE);
        $writer->widenColumn("testtable", "c1", MySQL::C_DATATYPE_TEXT7);
        $cols = $writer->getColumns("testtable");
        asrt($writer->code($cols["c1"]), MySQL::C_DATATYPE_TEXT7);
        $writer->widenColumn("testtable", "c1", MySQL::C_DATATYPE_TEXT8);
        $cols = $writer->getColumns("testtable");
        asrt($writer->code($cols["c1"]), MySQL::C_DATATYPE_TEXT8);
        $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);
        $writer->addColumn("testtable", "c2", MySQL::C_DATATYPE_UINT32);
    }