working, but confused
This commit is contained in:
		
							
								
								
									
										41
									
								
								Query.cpp
									
									
									
									
									
								
							
							
						
						
									
										41
									
								
								Query.cpp
									
									
									
									
									
								
							@@ -78,17 +78,32 @@ Customer query_customer_with_id(int id) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// -------------- paroking spots
 | 
					// -------------- paroking spots
 | 
				
			||||||
 | 
					
 | 
				
			||||||
vector<Park_spot>  query_all_parking_spots() {
 | 
					// vector<Park_spot>  query_all_parking_spots() {
 | 
				
			||||||
    vector<Park_spot> spots;
 | 
					//     vector<Park_spot> spots;
 | 
				
			||||||
    SQLite::Statement query(data::db, "SELECT * FROM Park_spot WHERE id > 2;");
 | 
					//     SQLite::Statement query(data::db, "SELECT * FROM Park_spot WHERE id > 0;");
 | 
				
			||||||
    // query.bind(1, 2);
 | 
					//     // query.bind(1, 2);
 | 
				
			||||||
    while (query.executeStep()) {
 | 
					//     while (query.executeStep()) {
 | 
				
			||||||
        int id = query.getColumn(0);
 | 
					//         int id = query.getColumn(0);
 | 
				
			||||||
        int taken = query.getColumn(1);
 | 
					//         int taken = query.getColumn(1);
 | 
				
			||||||
        int cid = query.getColumn(2);
 | 
					//         int cid = query.getColumn(2);
 | 
				
			||||||
        // park_customers.push_back(query_customer_with_id(cid));
 | 
					//         // park_customers.push_back(query_customer_with_id(cid));
 | 
				
			||||||
        spots.push_back({id, taken, cid});
 | 
					//         spots.push_back({id, taken, cid});
 | 
				
			||||||
    }
 | 
					//     }
 | 
				
			||||||
    return spots;
 | 
					//     return spots;
 | 
				
			||||||
}
 | 
					// }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// vector<Park_spot> populate_spots(){
 | 
				
			||||||
 | 
					//         vector<Park_spot> spots;
 | 
				
			||||||
 | 
					//     SQLite::Statement query(data::db, "SELECT * FROM Park_spot WHERE id > 0;");
 | 
				
			||||||
 | 
					//     // query.bind(1, 2);
 | 
				
			||||||
 | 
					//     while (query.executeStep()) {
 | 
				
			||||||
 | 
					//         int id = query.getColumn(0);
 | 
				
			||||||
 | 
					//         int taken = query.getColumn(1);
 | 
				
			||||||
 | 
					//         int cid = query.getColumn(2);
 | 
				
			||||||
 | 
					//         // park_customers.push_back(query_customer_with_id(cid));
 | 
				
			||||||
 | 
					//         spots.push_back({id, taken, cid});
 | 
				
			||||||
 | 
					//     }
 | 
				
			||||||
 | 
					//     return spots;
 | 
				
			||||||
 | 
					// }
 | 
				
			||||||
@@ -11,11 +11,10 @@ vector<Park_time> query_parktimes_for_customer(int cid);
 | 
				
			|||||||
vector<Customer> query_customer_with_name(string name);
 | 
					vector<Customer> query_customer_with_name(string name);
 | 
				
			||||||
Customer query_customer_with_id(int id);
 | 
					Customer query_customer_with_id(int id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
vector<Park_spot> query_all_parking_spots(); // used for initializing the parking spots at start of the program
 | 
					// vector<Park_spot> query_all_parking_spots(); // used for initializing the parking spots at start of the program
 | 
				
			||||||
 | 
					vector<Park_spot> populate_spots();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static vector<Park_spot> parking_spots = query_all_parking_spots(); // to save the parking spots in memory
 | 
					 | 
				
			||||||
static vector<Customer> park_customers; 
 | 
					 | 
				
			||||||
// save the customers that are parked in here
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif // CUSTOMER_H
 | 
					#endif // CUSTOMER_H
 | 
				
			||||||
							
								
								
									
										37
									
								
								main.cpp
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								main.cpp
									
									
									
									
									
								
							@@ -29,14 +29,35 @@ a wait function where 1 sec represents 1 hour irl.
 | 
				
			|||||||
    std::this_thread::sleep_for(seconds{sec});
 | 
					    std::this_thread::sleep_for(seconds{sec});
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int main() {
 | 
					static vector<Park_spot> parking_spots = populate_spots(); // to save the parking spots in memory
 | 
				
			||||||
    // Customer sagar = query_customer_with_name("stefan udit")[0];
 | 
					static vector<Customer> park_customers; // save the customers that are parked in here
 | 
				
			||||||
    Customer sagar = query_customer_with_id(2);
 | 
					 | 
				
			||||||
    cout << sagar.id << "," << sagar.name << "," << sagar.password;
 | 
					 | 
				
			||||||
    // cout << parking_spots.size();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // for (auto i : parking_spots){
 | 
					int main() {
 | 
				
			||||||
    //     cout << i.id << "," << i.parked_customer;
 | 
					    Customer sagar = query_customer_with_name("stefan udit")[0];
 | 
				
			||||||
    // }
 | 
					    Customer sagar1 = query_customer_with_id(2);
 | 
				
			||||||
 | 
					    cout << sagar.id << "," << sagar.name << "," << sagar.password<< "\n";
 | 
				
			||||||
 | 
					    cout << sagar1.id << "," << sagar1.name << "," << sagar1.password;
 | 
				
			||||||
 | 
					    cout << parking_spots.size();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for (auto i : parking_spots){
 | 
				
			||||||
 | 
					        cout << "\n" << i.id << "," << i.parked_customer;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					vector<Park_spot> populate_spots(){
 | 
				
			||||||
 | 
					        vector<Park_spot> spots;
 | 
				
			||||||
 | 
					    SQLite::Statement query(data::db, "SELECT * FROM Park_spot WHERE id > 0;");
 | 
				
			||||||
 | 
					    // query.bind(1, 2);
 | 
				
			||||||
 | 
					    while (query.executeStep()) {
 | 
				
			||||||
 | 
					        int id = query.getColumn(0);
 | 
				
			||||||
 | 
					        int taken = query.getColumn(1);
 | 
				
			||||||
 | 
					        int cid = query.getColumn(2);
 | 
				
			||||||
 | 
					        // park_customers.push_back(query_customer_with_id(cid));
 | 
				
			||||||
 | 
					        spots.push_back({id, taken, cid});
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return spots;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user