You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
letmut subtable:Option<Table> = match col["cols"].is_badvalue(){
260
263
true => None,
261
264
false => {
262
-
if table.columns.is_empty(){fatalerr!("Error: table '{}' cannot have a subtable as first column", name);}
263
-
let filename = col["file"].as_str().unwrap_or_else(|| fatalerr!("Error: subtable {} has no 'file' entry", colname));
264
-
Some(add_table(colname,&path,Some(filename), settings, col["cols"].as_vec().unwrap_or_else(|| fatalerr!("Error: subtable 'cols' entry is not an array")),Some(format!("{} {}", name, table.columns[0].datatype))))
265
+
if norm.is_some() && col["file"].is_badvalue(){// Normalized subtable; writes its primary key into the parent table
266
+
letmut subtable = add_table(colname,&path, norm, settings, col["cols"].as_vec().unwrap_or_else(|| fatalerr!("Error: subtable 'cols' entry is not an array")),None);
267
+
subtable.normalized = true;
268
+
Some(subtable)
269
+
}
270
+
else{
271
+
let filename = col["file"].as_str().unwrap_or_else(|| fatalerr!("Error: subtable {} has no 'file' entry", colname));
272
+
if table.columns.is_empty(){fatalerr!("Error: table '{}' cannot have a subtable as first column", name);}
273
+
Some(add_table(colname,&path,Some(filename), settings, col["cols"].as_vec().unwrap_or_else(|| fatalerr!("Error: subtable 'cols' entry is not an array")),Some(format!("{} {}", name, table.columns[0].datatype))))
274
+
}
265
275
}
266
276
};
267
277
let hide = col["hide"].as_bool().unwrap_or(false);
continue'restart;// Continue the restart loop because a subtable column may also match the current path
523
538
}
@@ -638,49 +653,66 @@ fn main() {
638
653
}
639
654
else{
640
655
641
-
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)
642
-
let key = tables.last().unwrap().columns[0].value.borrow();
643
-
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);}
644
-
table.write(&format!("{}\t", key));
645
-
ifletSome(domain) = table.domain.as_ref(){
646
-
table.write(&format!("{}\n", table.columns[0].value.borrow()));// This is a many-to-may relation; write the two keys into the link table
647
-
letmut domain = domain.borrow_mut();
648
-
if !domain.map.contains_key(&table.columns[0].value.borrow().to_string()){
649
-
domain.map.insert(table.columns[0].value.borrow().to_string(),0);// Table domains use the HashMap as a HashSet
650
-
for i in0..table.columns.len(){
651
-
if table.columns[i].subtable.is_some(){continue;}
652
-
if table.columns[i].hide{continue;}
653
-
if i > 0{ domain.table.write("\t");}
654
-
if table.columns[i].value.borrow().is_empty(){ domain.table.write("\\N");}
if !table.normalized{// Write the first column value of the parent table as the first column of the subtable (for use as a foreign key)
658
+
let key = tables.last().unwrap().columns[0].value.borrow();
659
+
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);}
660
+
table.write(&format!("{}\t", key));
661
+
ifletSome(domain) = table.domain.as_ref(){
662
+
if table.columns[0].value.borrow().is_empty(){println!("Warning: subtable {} has no primary key to normalize on", table.name);}
663
+
table.write(&format!("{}", table.columns[0].value.borrow()));// This is a many-to-may relation; write the two keys into the link table
664
+
letmut domain = domain.borrow_mut();
665
+
if !domain.map.contains_key(&table.columns[0].value.borrow().to_string()){
666
+
domain.map.insert(table.columns[0].value.borrow().to_string(),0);// Table domains use the HashMap as a HashSet
667
+
for i in0..table.columns.len(){
668
+
if table.columns[i].subtable.is_some(){continue;}
669
+
if table.columns[i].hide{continue;}
670
+
if i > 0{ domain.table.write("\t");}
671
+
if table.columns[i].value.borrow().is_empty(){ domain.table.write("\\N");}
0 commit comments