<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,177 +1,29 @@
 &lt;?php
 
-/** @addtogroup arch */
-/** @{ */
-
-/** @file
- * Generic database interface.
- */
-
-/** Generic database interface.
- */
 class database extends PDO
 {
-  public $dbtype;
-
-  /** Constructor. Create database connection and set some connection attributes.
-   */
-  public function __construct($dsn, $user = null, $pass = null)
+  public function __construct($path)
   {
-    $this-&gt;dbtype = explode(':', $dsn);
-    $this-&gt;dbtype = $this-&gt;dbtype[0];
-    $opts = array();
-    //if ($this-&gt;dbtype == 'pgsql')
-    //  $opts = DEBUG_ENABLED ? array() : array(PDO::ATTR_PERSISTENT =&gt; true);
-    parent::__construct($dsn, $user, $pass, $opts);
-    if ($this-&gt;dbtype == 'mysql')
-    {
-      $this-&gt;query(&quot;SET NAMES utf8&quot;);
-      $this-&gt;query(&quot;SET sql_mode = 'ANSI'&quot;);
-//      $this-&gt;query(&quot;SET TRANSACTION ISOLATION LEVEL SERIALIZABLE&quot;);
-    }
+    parent::__construct(&quot;sqlite:&quot;.$path);
     $this-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
   }
 
-  /** Check if result has exactly one row.
-   */
-  private function fetch_one_row($result, $style)
-  {
-    $row = $result-&gt;fetch($style);
-    if (!$row)
-      throw new Exception(&quot;expecting single row, got none&quot;);
-    $next_row = $result-&gt;fetch($style);
-    if (!$next_row)
-      return $row;
-    throw new Exception(&quot;expecting single row, got more&quot;);
-  }
-
-  /** Make SQL query to that returns single row.
-   */
-  public function row_iquery()
-  {
-    $args = func_get_args();
-    $res = call_user_func_array(array($this, &quot;iquery&quot;), $args);
-    $row = $this-&gt;fetch_one_row($res, PDO::FETCH_BOTH);
-    return $row;
-  }
-
-  /** Make SQL query to that returns first column from the first row.
-   */
-  public function col_iquery()
-  {
-    $args = func_get_args();
-    $res = call_user_func_array(array($this, &quot;iquery&quot;), $args);
-    $row = $this-&gt;fetch_one_row($res, PDO::FETCH_NUM);
-    return $row[0];
-  }
-
   public function table_exists($name)
   {
-    return $GLOBALS['db']-&gt;col_iquery('SELECT COUNT(*) FROM pg_tables WHERE schemaname = ? AND tablename = ?', &quot;public&quot;, $name) != 0;
+    $data = $GLOBALS['db']-&gt;iquery('SELECT COUNT(*) FROM sqlite_master WHERE type = ? AND name = ?', &quot;table&quot;, $name)-&gt;fetchAll();
+    return $data[0][0] &gt; 0;
   }
 
-  /** Make intelligent SQL query.
-   *
-   * @param base_sql [string] SQL query string that may contain ? substitution parameter
-   * @param  ... Substitution parameter values.
-   * @return PDOStatement object.
-   *
-   * @par Code:
-   * @code
-   *  $db-&gt;iquery('INSERT INTO table(col1, col2) VALUES (?, ?)', (string)$col1, (int)$col2);
-   *  $db-&gt;iquery('SELECT * FROM table WHERE col1 = ? AND col2 = ?', (string)$col1, (int)$col2);
-   * @endcode
-   */
   public function iquery($base_sql)
   {
     $args = func_get_args();
     $sql = array_shift($args);
     if (isset($args[0]) &amp;&amp; is_array($args[0]))
       $args = $args[0];
-    //X($sql.&quot;\n&quot;);
     $stmt = $this-&gt;prepare($sql);
     $stmt-&gt;execute($args);
     return $stmt;
   }
-
-  /** Make SQL query.
-   */
-  public function query($sql)
-  {
-    //X($sql.&quot;\n\n&quot;);
-    return parent::query($sql);
-  }
-
-  /** Backup data.
-   * 
-   * @param out_dbtype [string] Output for specified database type.
-   */
-  public function backup($out_dbtype = 'pgsql')
-  {
-    if ($out_dbtype == 'pgsql')
-      echo &quot;SET escape_string_warning = off;\n&quot;;
-
-    if ($this-&gt;dbtype == 'pgsql')
-      $tables = $this-&gt;query(&quot;SELECT table_name AS name FROM information_schema.tables WHERE table_schema = 'public'&quot;)-&gt;fetchAll(PDO::FETCH_NUM);
-    else
-      $tables = $this-&gt;query(&quot;SHOW TABLES&quot;)-&gt;fetchAll(PDO::FETCH_NUM);
-
-    foreach ($tables as $table)
-    {
-      $name = $table[0];
-
-      echo &quot;\n-- TABLE: $name\n\n&quot;;
-
-      // get table data
-      if ($this-&gt;dbtype == 'mysql')
-        $query = $this-&gt;query(&quot;SELECT * FROM `$name`&quot;);
-      else
-        $query = $this-&gt;query(&quot;SELECT * FROM $name&quot;);
-      $column_count = $query-&gt;columnCount();
-
-      // and metadata
-      $column_names = array();
-      $metas = array();
-      for ($i = 0; $i &lt; $column_count; $i++)
-      {
-        $metas[$i] = $meta = $query-&gt;getColumnMeta($i);
-        if ($out_dbtype == 'mysql')
-          $column_names[] = '`'.$meta['name'].'`';
-        else
-          $column_names[] = $meta['name'];
-      }
-      $column_names = implode(', ', $column_names);
-
-      if ($out_dbtype == 'pgsql')
-        echo &quot;ALTER TABLE $name DISABLE TRIGGER ALL;\n\n&quot;;
-
-      // create INSERTS
-      while ($row = $query-&gt;fetch(PDO::FETCH_NUM))
-      {
-        $insert = &quot;INSERT INTO $name ($column_names) VALUES (&quot;;
-        for ($i = 0; $i &lt; $column_count; $i++)
-        {
-          $mysql_int = isset($metas[$i]['native_type']) &amp;&amp; $metas[$i]['native_type'] == 'LONG';
-          $mysql_bool = !isset($metas[$i]['native_type']) &amp;&amp; $metas[$i]['len'] == '1';
-          $insert.= ($i ? &quot;, &quot; : &quot;&quot;);
-          if (is_null($row[$i]))
-            $insert.= 'NULL';
-          else if (is_integer($row[$i]) || $mysql_int)
-            $insert.= $row[$i];
-          else if (is_bool($row[$i]) || $mysql_bool)
-            $insert.= $row[$i] ? 'TRUE' : 'FALSE';
-          else
-            $insert.= Q($row[$i]);
-        }
-        $insert.= &quot;);\n&quot;;
-
-        echo $insert;
-      }
-
-      if ($out_dbtype == 'pgsql')
-        echo &quot;\nALTER TABLE $name ENABLE TRIGGER ALL;\n&quot;;
-    } 
-  }
 }
 
 /** Quote SQL string.
@@ -185,6 +37,4 @@ function Q($s)
   return $GLOBALS['db']-&gt;quote($s);
 }
 
-/** @} */
-
 ?&gt;</diff>
      <filename>database.php</filename>
    </modified>
    <modified>
      <diff>@@ -24,12 +24,12 @@ class gtd_rpc_server extends json_rpc_server
 {
   public function _pre_call($method, $params)
   {
-    $GLOBALS['db'] = new database(&quot;pgsql:dbname=mygtd&quot;, &quot;postgres&quot;, &quot;heslo&quot;);
+    $GLOBALS['db'] = new database(&quot;db/db.sqlite&quot;);
 
     if (!$GLOBALS['db']-&gt;table_exists(&quot;tasks&quot;))
     {
-      $GLOBALS['db']-&gt;query(&quot;CREATE TABLE categories (id SERIAL, name TEXT NOT NULL)&quot;);
-      $GLOBALS['db']-&gt;query(&quot;CREATE TABLE tasks (id SERIAL, title TEXT NOT NULL, detail TEXT, category_id INTEGER NOT NULL, exdate DATE NOT NULL, done BOOLEAN NOT NULL)&quot;);
+      $GLOBALS['db']-&gt;query(&quot;CREATE TABLE categories (id INTEGER PRIMARY KEY, name TEXT NOT NULL)&quot;);
+      $GLOBALS['db']-&gt;query(&quot;CREATE TABLE tasks (id INTEGER PRIMARY KEY, title TEXT NOT NULL, detail TEXT, category_id INTEGER NOT NULL, exdate DATE NOT NULL, done BOOLEAN NOT NULL)&quot;);
       $GLOBALS['db']-&gt;iquery(&quot;INSERT INTO categories (name) VALUES (?)&quot;, &quot;Pr&#225;ce&quot;);
       $GLOBALS['db']-&gt;iquery(&quot;INSERT INTO categories (name) VALUES (?)&quot;, &quot;Osobn&#237;&quot;);
       $GLOBALS['db']-&gt;iquery(&quot;INSERT INTO categories (name) VALUES (?)&quot;, &quot;Ostatn&#237;&quot;);
@@ -43,21 +43,26 @@ class gtd_rpc_server extends json_rpc_server
     $obj = new stdClass;
     $obj-&gt;tasks = $GLOBALS['db']-&gt;iquery(&quot;SELECT *, tasks.category_id AS category FROM tasks ORDER BY id&quot;)-&gt;fetchAll(PDO::FETCH_ASSOC);
     foreach ($obj-&gt;tasks as &amp;$task)
+    {
       $task['html'] = texy_process($task['detail']);
+      $task['done'] = $task['done'] == 'true';
+    }
     $obj-&gt;categories = $GLOBALS['db']-&gt;iquery(&quot;SELECT * FROM categories ORDER BY id&quot;)-&gt;fetchAll(PDO::FETCH_ASSOC);
     return $obj;
   }
 
   public function createTask($task)
   {
-    $id = $GLOBALS['db']-&gt;col_iquery(&quot;INSERT INTO tasks(title, detail, exdate, category_id, done) VALUES (?, ?, ?, ?, ?) RETURNING id&quot;, 
+    $GLOBALS['db']-&gt;iquery(&quot;INSERT INTO tasks(title, detail, exdate, category_id, done) VALUES (?, ?, ?, ?, ?)&quot;, 
       $task-&gt;title, $task-&gt;detail, $task-&gt;exdate, (int)$task-&gt;category_id, $task-&gt;done ? 'true' : 'false');
+    $id = $GLOBALS['db']-&gt;lastInsertId();
     return array('id' =&gt; $id, 'html' =&gt; texy_process($task-&gt;detail));
   }
 
   public function createCategory($name)
   {
-    $id = $GLOBALS['db']-&gt;col_iquery(&quot;INSERT INTO categories(name) VALUES (?) RETURNING id&quot;, $name);
+    $GLOBALS['db']-&gt;iquery(&quot;INSERT INTO categories(name) VALUES (?)&quot;, $name);
+    $id = $GLOBALS['db']-&gt;lastInsertId();
     return array('id' =&gt; $id);
   }
 </diff>
      <filename>rpc.php</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>656c9d6f5cba0efd173dfe732238766923ff9048</id>
    </parent>
  </parents>
  <author>
    <name>Ondrej Jirman</name>
    <email>megous@megous.com</email>
  </author>
  <url>http://github.com/megous/ajax-todo-list/commit/296cd29174f691212121c90d0263d77dc780420f</url>
  <id>296cd29174f691212121c90d0263d77dc780420f</id>
  <committed-date>2009-01-15T13:44:41-08:00</committed-date>
  <authored-date>2009-01-15T13:44:41-08:00</authored-date>
  <message>port to sqlite</message>
  <tree>eac5427108c9178af2535b4baa0d1b883d655c9a</tree>
  <committer>
    <name>Ondrej Jirman</name>
    <email>megous@megous.com</email>
  </committer>
</commit>
