working commits!

This commit is contained in:
djkato 2023-04-09 14:07:46 +02:00
parent 471b3e7383
commit 62fa057daf
4 changed files with 109 additions and 98 deletions

View file

@ -16,3 +16,11 @@ services:
volumes:
db:
driver: local
# To connect to mysql, do:
# sudo docker exec -it csql-Opencart_dummy_DB-1 /bin/bash
# mysql -p
# [password]
# use quotes;
# select * from oc_product;
# clear table: truncate oc_product;

View file

@ -112,21 +112,25 @@ impl Table {
csv_row: Vec<&DataEntry>,
) -> QueryResult {
/* Field_name, data_name */
let fields = csv_row
let mut fields = csv_row
.iter()
.fold(("".to_owned(), "".to_owned()), |row, next_row| {
(
row.0
+ ", "
+ next_row
.curr_field_description
.as_ref()
.unwrap()
.field
.as_str(),
.as_str()
+ ", ",
row.1 + "\'" + next_row.data.as_str() + "\', ",
)
});
fields.0.pop();
fields.0.pop();
fields.1.pop();
fields.1.pop();
let query = format!(
"INSERT INTO {}({}) VALUES({})",
self.name, fields.0, fields.1

View file

@ -34,7 +34,7 @@ impl DBTransactionWindow {
}
}
impl DBTransactionWindow {
pub fn show(&mut self, ctx: &Context, ui: &mut Ui) {
pub fn show(&mut self, ctx: &Context, ui: &mut Ui, frame: &mut eframe::Frame) {
egui::Window::new("Database Transactions")
.id(egui::Id::new("Database Transactions"))
.resizable(false)
@ -43,6 +43,10 @@ impl DBTransactionWindow {
.movable(false)
.scroll2([false, true])
.enabled(true)
.fixed_size(egui::Vec2::new(
frame.info().window_info.size.x / 1.3,
frame.info().window_info.size.y / 1.5,
))
.anchor(egui::Align2::CENTER_CENTER, egui::Vec2::ZERO)
.show(ctx, |ui| {
self.log();
@ -57,10 +61,11 @@ impl DBTransactionWindow {
}
if self.is_log_finished_receiver.is_some() {
if let Ok(finished) = self.is_log_finished_receiver.as_mut().unwrap().try_recv() {
//self.result = Some(finished);
self.result = Some(vec![]);
println!("FINISHED THE QUERY!!!");
}
}
if self.is_log_finished_receiver.is_none() && self.logs_receiver.is_none() {
let (log_sender, log_receiver) = channel(2);
let (finished_sender, finished_receiver) = oneshot::channel();
self.is_log_finished_receiver = Some(finished_receiver);
@ -73,8 +78,10 @@ impl DBTransactionWindow {
))
.unwrap_or_else(|_| println!("Failed to send startInserting"));
}
}
pub fn ui(&mut self, ctx: &Context, ui: &mut Ui) {
ui.add_enabled_ui(self.result.is_some(), |ui| {
ui.horizontal(|ui| {
if ui.button("Roll back").clicked() {
if self.final_result_receiver.is_none() {
let (sender, receiver) = oneshot::channel();
@ -94,23 +101,21 @@ impl DBTransactionWindow {
}
}
});
});
/* DB Output Stuff */
egui::ScrollArea::vertical()
egui::ScrollArea::both()
.auto_shrink([false; 2])
.stick_to_bottom(true)
.show(ui, |ui| {
egui_extras::StripBuilder::new(ui)
.size(egui_extras::Size::remainder().at_least(100.0))
.size(egui_extras::Size::remainder())
.vertical(|mut strip| {
strip.cell(|ui| {
egui::ScrollArea::horizontal().show(ui, |ui| {
let mut table = egui_extras::TableBuilder::new(ui)
.striped(true)
.resizable(true)
.cell_layout(egui::Layout::left_to_right(egui::Align::LEFT))
.column(egui_extras::Column::auto().clip(false))
.column(egui_extras::Column::auto().clip(false))
.min_scrolled_height(0.0);
.column(egui_extras::Column::remainder().clip(true))
.stick_to_bottom(true)
.column(egui_extras::Column::remainder().clip(true))
.stick_to_bottom(true);
table
.header(20.0, |mut header| {
header.col(|ui| {
@ -121,10 +126,7 @@ impl DBTransactionWindow {
});
})
.body(|mut body| {
body.rows(
15.0,
self.log_history.len(),
|row_index, mut row| {
body.rows(15.0, self.log_history.len(), |row_index, mut row| {
let log = self.log_history.get(row_index).unwrap();
row.col(|ui| {
ui.label(&log.query);
@ -132,32 +134,24 @@ impl DBTransactionWindow {
row.col(|ui| {
match &log.result {
Ok(rows) => {
ui.style_mut()
.visuals
.override_text_color =
Some(egui::Color32::RED);
ui.style_mut().visuals.override_text_color =
Some(egui::Color32::LIGHT_GREEN);
ui.label(format!(
"Success! Rows affected: {}",
rows.rows_affected()
));
}
Err(e) => {
ui.style_mut()
.visuals
.override_text_color =
Some(egui::Color32::RED);
ui.style_mut().visuals.override_text_color =
Some(egui::Color32::LIGHT_RED);
ui.label(format!("Error! {}", e));
}
}
ui.reset_style();
});
},
);
});
});
ui.scroll_to_cursor(Some(egui::Align::BOTTOM));
});
});
})
});
}
}

View file

@ -71,13 +71,18 @@ impl App for CSQL {
if let Ok(resp) = self.open_db_transaction_window_receiver.try_recv() {
self.should_open_db_transaction_window = Some(resp);
}
if self.should_open_db_transaction_window.is_some() {
let db_transaction_window = DBTransactionWindow::default(
self.sender.clone(),
self.should_open_db_transaction_window.unwrap(),
);
if let Some(db_transaction_window) = self.db_transaction_window.as_mut() {
db_transaction_window.show(ctx, ui, frame)
}
if let Some(working_table_index) = self.should_open_db_transaction_window {
let db_transaction_window =
DBTransactionWindow::default(self.sender.clone(), working_table_index);
self.db_transaction_window = Some(db_transaction_window);
self.db_transaction_window.as_mut().unwrap().show(ctx, ui);
self.db_transaction_window
.as_mut()
.unwrap()
.show(ctx, ui, frame);
self.should_open_db_transaction_window = None;
}
/* Changes self if db connection is verified */