Exemplo n.º 1
0
 private function findRecord($column, $value)
 {
     $db = DatabaseConnection::getInstance();
     $sql = "SELECT * FROM {$this->table} WHERE `{$column}`=%s";
     $this->data = $db->query($sql, $value)->fetchAll();
     return $this;
 }
Exemplo n.º 2
0
 public function dbtosdl()
 {
     $args = func_get_args();
     $opts = $this->parseOpts($args, array('database' => 'database:', 'table' => 'table:', 'with-data' => '+withdata'));
     var_dump($opts);
     // Get the connection instance
     if (empty($opts['database'])) {
         $conn = DatabaseConnection::getInstance("default");
     } else {
         $conn = DatabaseConnection::getInstance($opts['database']);
     }
     // Enumerate all the tables
     foreach ($conn->tables->getAll() as $table) {
         if (empty($opts['table']) || $table->name == $opts['table']) {
             // Print out the table nodes
             $sdl = new SdlTag("table", $table->name);
             $sdl->setComment("Table {$table->name} from database {$table->database->name}");
             // Convert the columns to SDL
             foreach ($table->getColumns() as $co) {
                 $col = new SdlTag("column", $co->name, ['type' => $co->type]);
                 if ($co->default !== NULL) {
                     $col->setAttribute('default', $co->default);
                 }
                 if ($co->auto) {
                     $col->setAttribute('auto', 1);
                 }
                 $col->setAttribute('null', $co->null);
                 $sdl->addChild($col);
             }
             // Convert the indexes to SDL
             $idx = new SdlTag("indexes");
             foreach ($table->getIndexes() as $ix) {
                 $cols = $ix->columns;
                 $ii = new SdlTag($ix->type, $ix->name);
                 $ii->setComment("Index {$ix->name}");
                 $ii->addChild(new SdlTag(NULL, $cols));
                 $idx->addChild($ii);
             }
             $sdl->addChild($idx);
             $rs = $conn->query("SELECT * FROM {$table->name}");
             $data = new SdlTag("data");
             foreach ($rs as $row) {
                 $rdata = new SdlTag("row");
                 foreach ($row as $k => $v) {
                     if (!is_integer($k)) {
                         $rdata->addChild(new SdlTag($k, $v));
                     }
                 }
                 $data->addChild($rdata);
             }
             $sdl->addChild($data);
             echo $sdl->encode() . "\n";
         }
     }
 }
Exemplo n.º 3
0
 private static function getDbInstance()
 {
     if (!self::$servicedb) {
         DatabaseConnection::register("servicemanager", "sqlite://service.db");
         self::$servicedb = DatabaseConnection::getInstance("servicemanager");
     }
     static $initd;
     if (!$initd) {
         $sm = self::$servicedb->getSchemaManager();
         $tl = $sm->getTableList();
         if (!in_array("services", $tl)) {
             $sm->applyTableSdlString(SM_TABLE_SERVICES);
         }
         if (!in_array("serviceprops", $tl)) {
             $sm->applyTableSdlString(SM_TABLE_SERVICEPROPS);
         }
         if (!in_array("instances", $tl)) {
             $sm->applyTableSdlString(SM_TABLE_INSTANCES);
         }
         $initd = true;
     }
     return self::$servicedb;
 }
Exemplo n.º 4
0
 public function __construct(DatabaseConnection $db)
 {
     $this->db = $db;
     $this->adapter = $db->getSqlAdapter();
     $this->tables = $this->adapter->getTableList();
 }