Skip to content

Commit

Permalink
fix bug in add_table()
Browse files Browse the repository at this point in the history
  • Loading branch information
lmcmicu committed Nov 20, 2024
1 parent e11fc7f commit 94504e2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/guess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::{
toolkit::{get_query_param, local_sql_syntax, QueryParam},
valve::{Valve, ValveConfig, ValveDatatypeConfig},
SQL_PARAM,
MOVE_INTERVAL, SQL_PARAM,
};
use fix_fn::fix_fn;
use futures::executor::block_on;
Expand Down Expand Up @@ -220,6 +220,7 @@ pub fn guess(
println!("Updating the table configuration in the database ...");
}
let row_number = get_max_row_number_from_table(valve, "table");
let row_order = row_number * MOVE_INTERVAL;
let sql = {
let column_names = &required_table_table_headers
.iter()
Expand All @@ -229,8 +230,8 @@ pub fn guess(
local_sql_syntax(
&valve.db_kind,
&format!(
r#"INSERT INTO "table" ("row_number", {column_names}) VALUES
({row_number}, {SQL_PARAM}, {SQL_PARAM}, NULL, NULL)"#,
r#"INSERT INTO "table" ("row_number", "row_order", {column_names}) VALUES
({row_number}, {row_order}, {SQL_PARAM}, {SQL_PARAM}, NULL, NULL)"#,
),
)
};
Expand All @@ -254,7 +255,8 @@ pub fn guess(
let mut params = vec![];
let values = vec![
// row_number
format!("{}", row_number),
format!("{row_number}"),
format!("{row_order}", row_order = row_number * MOVE_INTERVAL),
// table
{
params.push(table);
Expand Down Expand Up @@ -312,7 +314,7 @@ pub fn guess(
let sql = local_sql_syntax(
&valve.db_kind,
&format!(
r#"INSERT INTO "column" ("row_number", {}) VALUES ({})"#,
r#"INSERT INTO "column" ("row_number", "row_order", {}) VALUES ({})"#,
column_names, values
),
);
Expand Down
2 changes: 0 additions & 2 deletions src/valve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,6 @@ impl Valve {
self.reconfigure()
}

// TODO: This function doesn't seem to be able to handle a table name with spaces.
/// Given a table name, the path of the table's associated TSV file, and other parameters
/// used as input to the function, [guess()], guess the table's configuration on the basis
/// of the contents of the TSV file and the other, and add it to the database.
Expand All @@ -1340,7 +1339,6 @@ impl Valve {
if table_added {
self.save_tables(&vec!["table", "column"], &None).await?;
self.reconfigure()?;
self.load_tables(&vec!["table", "column"], true).await?;
self.ensure_all_tables_created(&vec![table]).await?;
}
Ok(())
Expand Down

0 comments on commit 94504e2

Please sign in to comment.