function addColumns(knjdb_table $table, $columns)
 {
     //Again again... SQLite does not have a alter table... F*****g crap.
     //Starting by creating a name for the temp-table.
     $tempname = $table->get("name") . "_temp";
     $tablename = $table->get("name");
     //Editing the index-array for renamed columns.
     $indexes = $table->getIndexes();
     //Making SQL.
     $oldcolumns = $table->getColumns();
     $newcolumns = array();
     foreach ($oldcolumns as $column) {
         $newcolumns[] = $column->data;
     }
     foreach ($columns as $column) {
         $newcolumns[] = $column;
     }
     $table->rename($tempname);
     $this->knjdb->tables()->createTable($tablename, $newcolumns);
     $newtable = $this->knjdb->getTable($tablename);
     //If we are adding columns, the new columns are at their defaults, so we just have to add the old data.
     //Making SQL for insert into new table.
     $sql_insert = "INSERT INTO " . $this->knjdb->conn->sep_table . $tablename . $this->knjdb->conn->sep_table . " (";
     //Creating the fields that should be insertet into for the SQL.
     $first = true;
     foreach ($oldcolumns as $column) {
         if ($first == true) {
             $first = false;
         } else {
             $sql_insert .= ", ";
         }
         $sql_insert .= $this->knjdb->conn->sep_col . $column->get("name") . $this->knjdb->conn->sep_col;
     }
     //If a new column has set "notnull" to be true, then we MUST insert into it (thanks evil devil).
     foreach ($columns as $column) {
         if ($column['notnull'] && !$column['default']) {
             $sql_insert .= ", " . $this->knjdb->conn->sep_col . $column["name"] . $this->knjdb->conn->sep_col;
         }
     }
     $sql_insert .= ") SELECT ";
     $first = true;
     foreach ($oldcolumns as $column) {
         if ($first == true) {
             $first = false;
         } else {
             $sql_insert .= ", ";
         }
         $sql_insert .= $this->knjdb->conn->sep_col . $column->get("name") . $this->knjdb->conn->sep_col;
     }
     //If a new column has set "notnull" to be true, then we MUST insert into it (thanks evil devil). So
     //we are just emulating an empty string, which will be insertet.
     foreach ($columns as $column) {
         if ($column["notnull"] && !$column["default"]) {
             $sql_insert .= ", '' AS " . $column["name"];
         }
     }
     $sql_insert .= " FROM " . $this->knjdb->conn->sep_col . $tempname . $this->knjdb->conn->sep_col;
     //Execute the insert-SQL.
     $this->knjdb->query($sql_insert);
     //Add indexes.
     foreach ($indexes as $index) {
         $cols = array();
         foreach ($index->getColumns() as $col) {
             $cols[] = $newtable->getColumn($col->get("name"));
         }
         $newtable->addIndex($cols);
     }
     //Drop the tempoary table.
     $table->drop();
     $newtable->columns_changed = true;
 }
 function removeColumn(knjdb_table $table, knjdb_column $column_remove)
 {
     $tablename = $table->get("name");
     //Again... SQLite has no "ALTER TABLE".
     $columns = $table->getColumns();
     $indexes = $table->getIndexes();
     $tempname = $tablename . "_temp";
     $table->rename($tempname);
     //Removing the specific column from the array.
     $cols = array();
     foreach ($columns as $key => $column) {
         if ($column->get("name") != $column_remove->get("name")) {
             $cols[] = $column->data;
         }
     }
     $this->knjdb->tables()->createTable($tablename, $cols);
     $newtable = $this->knjdb->getTable($tablename);
     $sql_insert = "INSERT INTO " . $this->knjdb->conn->sep_table . $tablename . $this->knjdb->conn->sep_table . " SELECT ";
     $first = true;
     foreach ($columns as $column) {
         if ($column->get("name") != $column_remove->get("name")) {
             if ($first == true) {
                 $first = false;
             } else {
                 $sql_insert .= ", ";
             }
             $sql_insert .= $this->knjdb->conn->sep_col . $column->get("name") . $this->knjdb->conn->sep_col;
             $newcolumns[] = $value;
         }
     }
     $sql_insert .= " FROM " . $this->knjdb->conn->sep_table . $tempname . $this->knjdb->conn->sep_table;
     $this->knjdb->query($sql_insert);
     //Creating indexes again from the array, that we saved at the beginning. In short terms this will rename the columns which have indexes to the new names, so that they wont be removed.
     foreach ($indexes as $index) {
         $cols = array();
         foreach ($index->getColumns() as $column) {
             $cols[] = $newtable->getColumn($column->get("name"));
         }
     }
     //Drop the temp-table.
     $table->drop();
     unset($this->columns[$column_remove->get("name")]);
 }