Skip to content

Commit 4999728

Browse files
committed
Don't use a serial for subtable domain
The subtable probably has its own primary key. You can add an explicit serial if not.
1 parent db56869 commit 4999728

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

src/main.rs

+4-15
Original file line numberDiff line numberDiff line change
@@ -631,22 +631,12 @@ fn main() {
631631
if !tables.is_empty() { // This is a subtable; write the first column value of the parent table as the first column of the subtable (for use as a foreign key)
632632
let key = tables.last().unwrap().columns[0].value.borrow();
633633
if key.is_empty() && !settings.hush_warning { println!("Warning: subtable {} has no foreign key for parent (you may need to add a 'seri' column)", table.name); }
634-
table.write(&key);
634+
table.write(&format!("{}\t", key));
635635
if let Some(domain) = table.domain.as_ref() {
636+
table.write(&format!("{}\n" , table.columns[0].value.borrow())); // This is a many-to-may relation; write the two keys into the link table
636637
let mut domain = domain.borrow_mut();
637-
let found = match domain.map.get(&table.columns[0].value.borrow().to_string()) {
638-
Some(id) => { table.write(&format!("\t{}\n" , *id)); true },
639-
None => {
640-
domain.lastid += 1;
641-
let id = domain.lastid;
642-
table.write(&format!("\t{}\n" , id));
643-
domain.map.insert(table.columns[0].value.borrow().to_string(), id);
644-
domain.table.write(&format!("{}\t", id));
645-
false
646-
}
647-
};
648-
649-
if !found {
638+
if !domain.map.contains_key(&table.columns[0].value.borrow().to_string()) {
639+
domain.map.insert(table.columns[0].value.borrow().to_string(), 0); // Table domains use the HashMap as a HashSet
650640
for i in 0..table.columns.len() {
651641
if table.columns[i].subtable.is_some() { continue; }
652642
if table.columns[i].hide { continue; }
@@ -676,7 +666,6 @@ fn main() {
676666
table = tables.pop().unwrap();
677667
continue 'restart;
678668
}
679-
else { table.write("\t"); }
680669
}
681670

682671
// Now write out the other column values

0 commit comments

Comments
 (0)