예제 #1
0
 public function getAlterFromSdl(SdlTag $tag, $meta)
 {
     $cols = [];
     foreach ($tag->query("column") as $column) {
         if (array_key_exists($column[0], $meta)) {
             $ctype = $this->getSqlVartype($column);
             $atype = strtoupper($meta[$column[0]]->type);
             if ($ctype != $atype) {
                 $cid = $column[0];
                 $ctype = $this->getSqlVartype($column);
                 $col = "CHANGE COLUMN `{$cid}` `{$cid}` {$ctype}";
                 $col .= $column->null ? ' NULL' : ' NOT NULL';
                 if ($column->default) {
                     $col .= " DEFAULT '" . $column->default . "'";
                 }
                 $cols[$cid] = $col;
             }
         } else {
             $cid = $column[0];
             $ctype = $this->getSqlVartype($column);
             $col = "ADD COLUMN `{$cid}` {$ctype}";
             $col .= $column->null ? ' NULL' : ' NOT NULL';
             if ($column->default) {
                 $col .= " DEFAULT '" . $column->default . "'";
             }
             $cols[$cid] = $col;
         }
     }
     if ($tag->auto && !array_key_exists($tag->auto, $meta)) {
         $cols[$tag->auto] = "ADD COLUMN `{$tag->auto}` INT NOT NULL PRIMARY KEY AUTO_INCREMENT";
     }
     foreach ($meta as $col => $cmeta) {
         if (!$tag->getChild("column", $col) && $tag->auto != $col) {
             $cols[$col] = "DROP COLUMN `{$col}`";
         }
     }
     if (count($cols) > 0) {
         $sql = "ALTER TABLE `{$tag[0]}` " . join(", ", $cols);
         return $sql;
     }
     return null;
 }
예제 #2
0
 public function applyTableSdlString($string)
 {
     $root = new SdlTag("root");
     $root->loadString($string);
     return $this->applyTableSdl($root->getChild(0));
 }
예제 #3
0
use Cherry\Util\Timer;
// Create a new root node, we need this.
$root = new SdlTag("cyanogenmod");
$root->setComment("These are the latest three CyanogenMod versions with some info");
// You can create nodes and set attributes manually
$cm9 = new SdlTag("version", "9");
$cm9->multiuser = false;
$cm9->android = "4.0.x";
$cm9->setComment("Based on AOSP 4.0.x");
$root->addChild($cm9);
// Or provide them to the constructor
$cm10 = new SdlTag("version", "10", ['multiuser' => false, 'android' => "4.1.x"]);
$cm10->setComment("Based on AOSP 4.1.x");
$root->addChild($cm10);
// Comments can also go as the 5th argument
$cm101 = new SdlTag("version", "10.1", ['multiuser' => true, 'android' => "4.2.x", 'note' => "New and hot!"], null, "Based on AOSP 4.2.x");
$root->addChild($cm101);
// And the data can be serialized to SDL
$sdl = $root->encode();
echo $sdl;
// Read it back out again
$test = new SdlTag("root");
$test->loadString($sdl);
// Print some info about the various versions.
foreach ($test->getChild("cyanogenmod")->getChildren() as $child) {
    echo "CM{$child[0]}: Based on Android AOSP {$child->android}.";
    if ($child->multiuser) {
        echo " Multiple user-profiles supported.";
    }
    echo "\n";
}
예제 #4
0
 public function testAttributes()
 {
     $test = new SdlTag("root");
     $test->setAttribute("name", "bob");
     $this->assertEquals("bob", $test->name);
     $test->name = "joe";
     $this->assertEquals("joe", $test->name);
     unset($test->name);
     $this->assertEquals(null, $test->name);
     $test->loadString("pet name=\"bobo\" type=\"dog\" alive=true age=14");
     $this->assertEquals("dog", $test->getChild("pet")->type, "String ttribute don't match parsed value");
     $this->assertEquals(true, $test->getChild("pet")->alive, "Bool attribute don't match parsed value");
     $this->assertEquals(14, $test->getChild("pet")->age, "Numeric attribute don't match parsed value");
     $this->assertEquals("bobo", $test->getChild("pet")->name, "String attribute don't match parsed value");
     $attr = $test->getChild("pet")->getAttributes();
     $match = ['name' => 'bobo', 'type' => 'dog', 'age' => 14, 'alive' => true];
     $this->assertEquals($match, $attr, "Unexpected attribute set returned");
 }
예제 #5
0
<?php

require_once "../../share/include/cherryphp";
use Cherry\Data\Ddl\SdlTag;
use Cherry\Util\Timer;
// This is a node with base64-encoded data.
$sdl = <<<EOT
testnode [SGVsbG8gV29ybGQh];
EOT;
// Read it back out again
$test = new SdlTag("root");
$test->loadString($sdl);
$node = new SdlTag("testnode2");
$node->setValue("Putting binary data in the SDL node", 0, SdlTag::LT_BINARY);
$test->addChild($node);
echo "Current state of SDL tree:\n";
echo $test->encode() . "\n";
echo "Node values:\n";
echo "  testnode=" . $test->getChild("testnode")[0] . "\n";
echo "  testnode2=" . $test->getChild("testnode2")[0] . "\n";