pub fn insert_row(&mut self, cols: &Vec<String>, values: &Vec<String>) {
        let mut next_rowid = self.last_rowid + i64::from(1);

        // Checks if table has a PRIMARY KEY
        if self.primary_key != "-1"{
            // Checking if primary key is in INSERT QUERY columns
            // If it is not, assign the next_rowid to it
            if !cols.iter().any(|col| col == &self.primary_key) {
                let rows_clone = Rc::clone(&self.rows);
                let mut row_data = rows_clone.as_ref().borrow_mut();
                let mut table_col_data = row_data.get_mut(&self.primary_key).unwrap();

                // Getting the header based on the column name
                let column_headers = self.get_column_mut(self.primary_key.to_string()).unwrap();

                // Getting index for column, if it exist
                let col_index = column_headers.get_mut_index();

                // We only AUTO ASSIGN in case the ROW is a PRIMARY KEY and INTEGER type
                match &mut table_col_data {
                    Row::Integer(tree) => {
                        let val = next_rowid as i32;
                        tree.insert(next_rowid.clone(), val);
                        if let Index::Integer(index) = col_index {
                            index.insert(val, next_rowid.clone());
                        }
                    }
                    _ => (),
                }
            } else {
                // If PRIMARY KEY Column is in the Column list from INSERT Query,
                // We get the value assigned to it in the VALUES part of the query
                // and assign it to next_rowid, so every value if indexed by same rowid
                // Also, next ROWID should keep AUTO INCREMENTING from last ROWID
                let rows_clone = Rc::clone(&self.rows);
                let mut row_data = rows_clone.as_ref().borrow_mut();
                let mut table_col_data = row_data.get_mut(&self.primary_key).unwrap();

                // Again, this is only valid for PRIMARY KEYs of INTEGER type
                match &mut table_col_data {
                    Row::Integer(_) => {
                        for i in 0..cols.len() {
                            // Getting column name
                            let key = &cols[i];
                            if key == &self.primary_key {
                                let val = &values[i];
                                next_rowid = val.parse::<i64>().unwrap();
                            }
                        }
                    }
                    _ => (),
                }
            }
        }

        // This block checks if there are any columns from table missing
        // from INSERT statement. If there are, we add "Null" to the column.
        // We do this because otherwise the ROWID reference for each value would be wrong
        // Since rows not always have the same length.
        let column_names = self
            .columns
            .iter()
            .map(|col| col.column_name.to_string())
            .collect::<Vec<String>>();
        let mut j: usize = 0;
        // For every column in the INSERT statement
        for i in 0..column_names.len() {
            let mut val = String::from("Null");
            let mut key = &column_names[i];

            if let Some(key) = &cols.get(j){
                if &key.to_string() == &column_names[i] {
                    // Getting column name
                    val = values[j].to_string();
                    j += 1;
                } else{
                    if &self.primary_key == &column_names[i]{
                        continue
                    } 
                } 
            }else{
                if &self.primary_key == &column_names[i]{
                    continue
                } 
            }

            // Getting the rows from the column name
            let rows_clone = Rc::clone(&self.rows);
            let mut row_data = rows_clone.as_ref().borrow_mut();
            let mut table_col_data = row_data.get_mut(key).unwrap();

            // Getting the header based on the column name
            let column_headers = self.get_column_mut(key.to_string()).unwrap();

            // Getting index for column, if it exist
            let col_index = column_headers.get_mut_index();

            match &mut table_col_data {
                Row::Integer(tree) => {
                    let val = val.parse::<i32>().unwrap();
                    tree.insert(next_rowid.clone(), val);
                    if let Index::Integer(index) = col_index {
                        index.insert(val, next_rowid.clone());
                    }
                }
                Row::Text(tree) => {
                    tree.insert(next_rowid.clone(), val.to_string());
                    if let Index::Text(index) = col_index {
                        index.insert(val.to_string(), next_rowid.clone());
                    }
                }
                Row::Real(tree) => {
                    let val = val.parse::<f32>().unwrap();
                    tree.insert(next_rowid.clone(), val);
                }
                Row::Bool(tree) => {
                    let val = val.parse::<bool>().unwrap();
                    tree.insert(next_rowid.clone(), val);
                }
                Row::None => panic!("None data Found"),
            }
        }
        self.last_rowid = next_rowid;
    }
/// Inserts all VALUES in its approprieta COLUMNS, using the ROWID an embedded INDEX on all ROWS
/// Every `Table` keeps track of the `last_rowid` in order to facilitate what the next one would be.
/// One limitation of this data structure is that we can only have one write transaction at a time, otherwise
/// we could have a race condition on the last_rowid.println!
///
/// Since we are loosely modeling after SQLite, this is also a limitation of SQLite (allowing only one write transcation at a time),
/// So we are good. :)
///
Inserts all VALUES in its approprieta COLUMNS, using the ROWID an embedded INDEX on all ROWS
Every `Table` keeps track of the `last_rowid` in order to facilitate what the next one would be.
One limitation of this data structure is that we can only have one write transaction at a time, otherwise
we could have a race condition on the last_rowid.println!

Since we are loosely modeling after SQLite, this is also a limitation of SQLite (allowing only one write transcation at a time),
So we are good.
Inserts all VALUES in its approprieta COLUMNS using the ROWID an embedded INDEX on all ROWS Every ` Table ` keeps track of the ` last_rowid ` in order to facilitate what the next one would be . One limitation of this data structure is that we can only have one write transaction at a time otherwise we could have a race condition on the last_rowid . println! Since we are loosely modeling after SQLite this is also a limitation of SQLite ( allowing only one write transcation at a time ) So we are good .
pub fn insert_row(&mut self, cols: &Vec<String>, values: &Vec<String>) {
        let mut next_rowid = self.last_rowid + i64::from(1);
        // Checks if table has a PRIMARY KEY
        if self.primary_key != "-1"{
            // Checking if primary key is in INSERT QUERY columns
            // If it is not, assign the next_rowid to it
            if !cols.iter().any(|col| col == &self.primary_key) {
                let rows_clone = Rc::clone(&self.rows);
                let mut row_data = rows_clone.as_ref().borrow_mut();
                let mut table_col_data = row_data.get_mut(&self.primary_key).unwrap();
                // Getting the header based on the column name
                let column_headers = self.get_column_mut(self.primary_key.to_string()).unwrap();
                // Getting index for column, if it exist
                let col_index = column_headers.get_mut_index();
                // We only AUTO ASSIGN in case the ROW is a PRIMARY KEY and INTEGER type
                match &mut table_col_data {
                    Row::Integer(tree) => {
                        let val = next_rowid as i32;
                        tree.insert(next_rowid.clone(), val);
                        if let Index::Integer(index) = col_index {
                            index.insert(val, next_rowid.clone());
                        }
                    }
                    _ => (),
                }
            } else {
                // If PRIMARY KEY Column is in the Column list from INSERT Query,
                // We get the value assigned to it in the VALUES part of the query
                // and assign it to next_rowid, so every value if indexed by same rowid
                // Also, next ROWID should keep AUTO INCREMENTING from last ROWID
                let rows_clone = Rc::clone(&self.rows);
                let mut row_data = rows_clone.as_ref().borrow_mut();
                let mut table_col_data = row_data.get_mut(&self.primary_key).unwrap();
                // Again, this is only valid for PRIMARY KEYs of INTEGER type
                match &mut table_col_data {
                    Row::Integer(_) => {
                        for i in 0..cols.len() {
                            // Getting column name
                            let key = &cols[i];
                            if key == &self.primary_key {
                                let val = &values[i];
                                next_rowid = val.parse::<i64>().unwrap();
                            }
                        }
                    }
                    _ => (),
                }
            }
        }
        // This block checks if there are any columns from table missing
        // from INSERT statement. If there are, we add "Null" to the column.
        // We do this because otherwise the ROWID reference for each value would be wrong
        // Since rows not always have the same length.
        let column_names = self
            .columns
            .iter()
            .map(|col| col.column_name.to_string())
            .collect::<Vec<String>>();
        let mut j: usize = 0;
        // For every column in the INSERT statement
        for i in 0..column_names.len() {
            let mut val = String::from("Null");
            let mut key = &column_names[i];
            if let Some(key) = &cols.get(j){
                if &key.to_string() == &column_names[i] {
                    // Getting column name
                    val = values[j].to_string();
                    j += 1;
                } else{
                    if &self.primary_key == &column_names[i]{
                        continue
                    } 
                } 
            }else{
                if &self.primary_key == &column_names[i]{
                    continue
                } 
            }
            // Getting the rows from the column name
            let rows_clone = Rc::clone(&self.rows);
            let mut row_data = rows_clone.as_ref().borrow_mut();
            let mut table_col_data = row_data.get_mut(key).unwrap();
            // Getting the header based on the column name
            let column_headers = self.get_column_mut(key.to_string()).unwrap();
            // Getting index for column, if it exist
            let col_index = column_headers.get_mut_index();
            match &mut table_col_data {
                Row::Integer(tree) => {
                    let val = val.parse::<i32>().unwrap();
                    tree.insert(next_rowid.clone(), val);
                    if let Index::Integer(index) = col_index {
                        index.insert(val, next_rowid.clone());
                    }
                }
                Row::Text(tree) => {
                    tree.insert(next_rowid.clone(), val.to_string());
                    if let Index::Text(index) = col_index {
                        index.insert(val.to_string(), next_rowid.clone());
                    }
                }
                Row::Real(tree) => {
                    let val = val.parse::<f32>().unwrap();
                    tree.insert(next_rowid.clone(), val);
                }
                Row::Bool(tree) => {
                    let val = val.parse::<bool>().unwrap();
                    tree.insert(next_rowid.clone(), val);
                }
                Row::None => panic!("None data Found"),
            }
        }
        self.last_rowid = next_rowid;
    }
pub fn insert_row ( & mut self , cols : & Vec < String > , values : & Vec < String > ) { let mut next_rowid = self . last_rowid + i64 :: from ( 1 ) ; // Checks if table has a PRIMARY KEY if self . primary_key != " " { // Checking if primary key is in INSERT QUERY columns // If it is not, assign the next_rowid to it if ! cols . iter ( ) . any ( | col | col == & self . primary_key ) { let rows_clone = Rc :: clone ( & self . rows ) ; let mut row_data = rows_clone . as_ref ( ) . borrow_mut ( ) ; let mut table_col_data = row_data . get_mut ( & self . primary_key ) . unwrap ( ) ; // Getting the header based on the column name let column_headers = self . get_column_mut ( self . primary_key . to_string ( ) ) . unwrap ( ) ; // Getting index for column, if it exist let col_index = column_headers . get_mut_index ( ) ; // We only AUTO ASSIGN in case the ROW is a PRIMARY KEY and INTEGER type match & mut table_col_data { Row :: Integer ( tree ) => { let val = next_rowid as i32 ; tree . insert ( next_rowid . clone ( ) , val ) ; if let Index :: Integer ( index ) = col_index { index . insert ( val , next_rowid . clone ( ) ) ; } } _ => ( ) , } } else { // If PRIMARY KEY Column is in the Column list from INSERT Query, // We get the value assigned to it in the VALUES part of the query // and assign it to next_rowid, so every value if indexed by same rowid // Also, next ROWID should keep AUTO INCREMENTING from last ROWID let rows_clone = Rc :: clone ( & self . rows ) ; let mut row_data = rows_clone . as_ref ( ) . borrow_mut ( ) ; let mut table_col_data = row_data . get_mut ( & self . primary_key ) . unwrap ( ) ; // Again, this is only valid for PRIMARY KEYs of INTEGER type match & mut table_col_data { Row :: Integer ( _ ) => { for i in 0 .. cols . len ( ) { // Getting column name let key = & cols [ i ] ; if key == & self . primary_key { let val = & values [ i ] ; next_rowid = val . parse :: < i64 > ( ) . unwrap ( ) ; } } } _ => ( ) , } } } // This block checks if there are any columns from table missing // from INSERT statement. If there are, we add "Null" to the column. // We do this because otherwise the ROWID reference for each value would be wrong // Since rows not always have the same length. let column_names = self . columns . iter ( ) . map ( | col | col . column_name . to_string ( ) ) . collect :: < Vec < String > > ( ) ; let mut j : usize = 0 ; // For every column in the INSERT statement for i in 0 .. column_names . len ( ) { let mut val = String :: from ( " " ) ; let mut key = & column_names [ i ] ; if let Some ( key ) = & cols . get ( j ) { if & key . to_string ( ) == & column_names [ i ] { // Getting column name val = values [ j ] . to_string ( ) ; j += 1 ; } else { if & self . primary_key == & column_names [ i ] { continue } } } else { if & self . primary_key == & column_names [ i ] { continue } } // Getting the rows from the column name let rows_clone = Rc :: clone ( & self . rows ) ; let mut row_data = rows_clone . as_ref ( ) . borrow_mut ( ) ; let mut table_col_data = row_data . get_mut ( key ) . unwrap ( ) ; // Getting the header based on the column name let column_headers = self . get_column_mut ( key . to_string ( ) ) . unwrap ( ) ; // Getting index for column, if it exist let col_index = column_headers . get_mut_index ( ) ; match & mut table_col_data { Row :: Integer ( tree ) => { let val = val . parse :: < i32 > ( ) . unwrap ( ) ; tree . insert ( next_rowid . clone ( ) , val ) ; if let Index :: Integer ( index ) = col_index { index . insert ( val , next_rowid . clone ( ) ) ; } } Row :: Text ( tree ) => { tree . insert ( next_rowid . clone ( ) , val . to_string ( ) ) ; if let Index :: Text ( index ) = col_index { index . insert ( val . to_string ( ) , next_rowid . clone ( ) ) ; } } Row :: Real ( tree ) => { let val = val . parse :: < f32 > ( ) . unwrap ( ) ; tree . insert ( next_rowid . clone ( ) , val ) ; } Row :: Bool ( tree ) => { let val = val . parse :: < bool > ( ) . unwrap ( ) ; tree . insert ( next_rowid . clone ( ) , val ) ; } Row :: None => panic ! ( " " ) , } } self . last_rowid = next_rowid ; }
Inserts all VALUES in its approprieta COLUMNS, using the ROWID an embedded INDEX on all ROWS
Every `Table` keeps track of the `last_rowid` in order to facilitate what the next one would be.
Inserts all VALUES in its approprieta COLUMNS using the ROWID an embedded INDEX on all ROWS Every ` Table ` keeps track of the ` last_rowid ` in order to facilitate what the next one would be .
&mut self
cols
&Vec<String>
values
&Vec<String>
&mut self
cols
&Vec<String>
values
&Vec<String>