/**
  * Deletes a row from a table
  * @param string $tableName
  * @param array $search
  */
 private function delete($tableName, $search)
 {
     $select = new eDB_Select();
     $rowID = $select->getRowIdBySearch($search, $tableName);
     $content = $select->search($tableName, '*');
     unset($content[$rowID - 1]);
     $cols = $select->getColumns($tableName);
     $completeContent[] = $cols;
     foreach ($content as $row) {
         $completeContent[] = $row;
     }
     $update = new eDB_Update();
     $update->updateTable($completeContent, $tableName);
 }
 /**
  * Peform an update
  * @param array $values
  * @param array $search
  * @param string $tableName
  */
 private function update($values, $search, $tableName)
 {
     $select = new eDB_Select();
     $rowID = $select->getRowIdBySearch($search, $tableName);
     $ChangedRow = $select->getRowById($rowID, $tableName);
     foreach ($values as $col => $value) {
         $ChangedRow[0][$col] = $value;
     }
     $cols = $select->getColumns($tableName, true);
     $content = $select->search($tableName, '*');
     $completeContent[] = $cols;
     foreach ($content as $row) {
         $completeContent[] = $row;
     }
     $completeContent[$rowID] = $ChangedRow[0];
     $this->updateTable($completeContent, $tableName);
 }
 /**
  * Generate array which contains primarykey and next number
  * @param string $tableName
  * @return array
  */
 private function generateIncrement($tableName)
 {
     $select = new eDB_Select();
     $cols = $select->getColumns($tableName, true);
     $keyNumber = 0;
     foreach ($cols as $col) {
         if (preg_match('#[\\w]*:key;[0-9]#i', $col)) {
             break;
         }
         $keyNumber++;
     }
     $cols[$keyNumber] = preg_replace('#(.*):key;[0-9]#i', "\$1", $cols[$keyNumber]);
     $result = $select->search($tableName, '*');
     $result[count($result) - 1][$cols[$keyNumber]]++;
     return array('key' => $cols[$keyNumber], 'value' => $result[count($result) - 1][$cols[$keyNumber]]);
 }
 /**
  * Sets a primary key which contains auto increement
  *
  * @param string $table
  * @param string $name
  * @param int $startpos
  */
 public function setPrimaryKey($table, $name, $startpos = 1)
 {
     $select = new eDB_Select($table, '*');
     $cols = $select->getColumns($table, true);
     if (!is_array($cols)) {
         return false;
     }
     if (preg_match("#{$name}:key;[0-9]#i", implode('|', $cols))) {
         return false;
     }
     $i = 0;
     foreach ($cols as $x) {
         if ($x == $name) {
             break;
         }
         ++$i;
     }
     if ($select->result) {
         foreach ($select->result as $key => $x) {
             $select->result[$key][$cols[$i]] = $startpos;
             ++$startpos;
         }
     } else {
         $select->result = array();
     }
     $cols[$i] = $cols[$i] . ":key;{$startpos}";
     $thecols[0] = $cols;
     $result = array_merge($thecols, $select->result);
     array_values($result);
     $update = new eDB_Update();
     $update->updateTable($result, $table);
 }