Exemplo n.º 1
0
 protected function get_applied_migrations()
 {
     $this->ensure_schema_version_table();
     $cmd = new SDBCommand("SELECT `id` FROM @schema_name ORDER BY `id`");
     $cmd->set('schema_name', self::SCHEMA_NAME, SDB::TableName);
     $rows = $cmd->get_all();
     return array_map(create_function('$r', 'return $r["id"];'), $rows);
 }
 protected function do_get_tables_list()
 {
     // **TODO**: read about 'sqlite_temp_master'
     $cmd = new SDBCommand("SELECT \"name\" FROM sqlite_master WHERE \"type\"='table'");
     $res = $cmd->get_all();
     $arr = array();
     foreach ($res as $row) {
         $name = first_value($row);
         if (strlen($this->prefix) && strpos($name, $this->prefix) === 0) {
             $name = substr($name, strlen($this->prefix));
         }
         $arr[] = $name;
     }
     return $arr;
 }
        $cmd->set('name', 'Name #' . md5(now()), SDB::String);
        $cmd->set('date_created', now(), SDB::DateTime);
        $cmd->execute();
        echo 'ok';
        break;
    case 'list':
        $cmd = new SDBCommand("SELECT * FROM some_items");
        $arr = $cmd->get_all();
        echo '<pre>';
        echo "<b><u>id\tname\t\t\t\t\tdate_created\t   </u></b>\n";
        foreach ($arr as $row) {
            echo $row['id'] . "\t" . $row['name'] . "\t" . $row['date_created'] . "\n";
        }
        echo '</pre>';
        break;
    case 'remove':
        $cmd = new SDBCommand("SELECT id FROM some_items");
        $ids = $cmd->get_all();
        $id = $ids[rand() % count($ids)]['id'];
        $cmd = new SDBCommand("DELETE FROM some_items WHERE id=@id");
        $cmd->set('id', $id, SDB::Int);
        $cmd->execute();
        echo 'ok';
        break;
    case 'clear':
        $cmd = new SDBCommand("DELETE FROM some_items");
        $cmd->execute();
        echo 'ok';
        break;
}
echo_debug();
Exemplo n.º 4
0
 public function move($full_path, $position)
 {
     if ($full_path == $this->path . $this->name && $position == $this->position) {
         return;
     }
     self::lock();
     $prev_path = $this->path;
     if ($full_path != $this->path . $this->name) {
         // Проапдейтить позицию в папке **откуда** была нода
         $this->update_positions();
         $cmd = new SDBCommand("SELECT id,path FROM nodes WHERE path LIKE @path");
         $cmd->set('path', $this->path . $this->name . '/%', SDB::String, self::PathSize);
         $arr = $cmd->get_all();
         $len = strlen($this->path . $this->name);
         $cmd = new SDBCommand("UPDATE nodes SET path=@path WHERE id=@id");
         $cmd->set('id', null, SDB::Int);
         $cmd->set('path', null, SDB::String, self::PathSize);
         foreach ($arr as $row) {
             $cmd->set('id', $row['id']);
             $cmd->set('path', $full_path . substr($row['path'], $len));
             $cmd->execute();
         }
         self::path_parts($full_path, $path, $name);
         $this->path = $path;
         $this->name = $name;
         $this->_childs = null;
         $this->_parent_node = false;
     }
     if ($prev_path != $this->path || $position != $this->position) {
         // Проапдейтить позицию в папке **куда** переместилась нода
         $pos = $this->update_positions($position);
         $this->position = $position == 0 || $position > $pos ? $pos : $position;
     }
     $this->save();
     self::unlock();
 }