/**
  * Ensures that a row exists in the given tablet
  * @param I2CE_Form $form
  * @param string $col
  * @param mixed $parent_col.  If a string it is the parent col to save the parent id in
  */
 protected function ensureFormId($form, $col, $parent_col)
 {
     $table = $this->getTable($form->getName());
     if (!$table) {
         I2CE::raiseError("No table specified for {$form}");
         return '0';
     }
     $id = $form->getId();
     if ($id == '0') {
         $new_id = $this->db->getBeforeID($table, $col, true, true);
         if (I2CE::pearError($new_id, "Cannot get next id")) {
             return '0';
         }
         $stmt = "INSERT INTO  SET `{$col}` = '" . $form->getName() . "|{$id}'";
         if (is_string($parent_col)) {
             $stmt .= ", `{$parent_col}` = '" . $form->getParent() . "'";
         }
         if (I2CE::pearError($this->db->exec($stmt), "Error inserting form " . $form->getName() . ": ")) {
             return '0';
         }
         $new_id = $this->db->getAfterID($new_id, $table, $col);
         $form->setId($new_id);
         $form->setChangeType(I2CE_FormStorage_Mechanism::CHANGE_INITIAL);
         return $new_id;
     } else {
         $stmt = "INSERT IGNORE INTO {$table} SET `{$col}` = '{$id}'";
         if (is_string($parent_col)) {
             $stmt .= ", `{$parent_col}` = '" . $form->getParent() . "'";
         }
         if (I2CE::pearError($this->db->exec($stmt), "Error inserting form " . $form->getName() . ": ")) {
             return '0';
         }
         return $id;
     }
 }