/**
 * Returns the resulting table but uses the $key field as an index
 *
 * @abstract 
 * @access   public
 *
 * @param    String     $table        the table name
 * @param    String     $id_col       the name of the primary key column
 * @param    String     $id           the key of the dataset to clone
 * @param    Array      $exclusion    columns not to copy
 *
 * @return   Mixed       new key or FALSE
 */
 function cloneDataset(&$db, $table, $id_col, $id, $exclusion = null)
 {
     $db->query("SELECT * FROM {$table} WHERE {$id_col}='{$id}'");
     $data = $db->getNext();
     if ($data) {
         unset($data[$id_col]);
         if (is_array($exclusion)) {
             foreach ($exclusion as $key) {
                 unset($data[$key]);
             }
         }
         if ($db->query(QueryHelper::insert($table, $data))) {
             $res = $db->getInsertId();
             if (!$res) {
                 $db->query(QueryHelper::select($id_col, $table, $data));
                 return $db->getValue();
             }
             return $res;
         }
     }
     echo $db->lastQuery;
     return false;
 }
 /**
  * Returns the data for one table
  *
  * @access   public
  *
  * @param    AbstractDB  $db                 db identifier
  * @param    String      $table              table name
  * @param    Integer     $type               ANYDB_DUMP_ constants
  * @param    String      $seperator          for csv files
  *
  * @returns  Array       the table data
  */
 function getTableData(&$db, $table, $type = ANYDB_DUMP_SQL, $seperator = "\t")
 {
     $res = '';
     $first = true;
     // get all the data
     $query = "SELECT * FROM {$table}";
     $db->query($query, ANYDB_RES_ASSOC);
     while ($line = $db->getNext()) {
         $line = $db->escapeStr($line);
         switch ($type) {
             case ANYDB_DUMP_SQL:
                 $res .= QueryHelper::insert($table, $line) . ";\n";
                 break;
             case ANYDB_DUMP_CSV:
                 if ($first) {
                     $res .= implode($seperator, array_keys($line)) . "\n";
                     $first = false;
                 }
                 $res .= implode($seperator, $line) . "\n";
                 break;
         }
     }
     return $res;
 }