Skip to content

Commit 00386ae

Browse files
committed
Altura guardada en BD correctamente
1 parent 967bbaa commit 00386ae

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/parking/vehicle/Vehicle.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ Vehicle::Vehicle(){
1111
l_plate = "";
1212
color = "";
1313
brand = "";
14+
height = 0;
1415
}
1516

16-
Vehicle::Vehicle(string l_plate, string color, string brand) {
17+
Vehicle::Vehicle(string l_plate, string color, string brand, float height) {
1718

1819
this->l_plate = l_plate;
1920
this->color = color;
2021
this->brand = brand;
22+
this->height = height;
2123
}
2224

2325
Vehicle::Vehicle(char* l_plate) {

src/parking/vehicle/Vehicle.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Vehicle {
1919
public:
2020

2121
Vehicle(); // Constructor por defecto
22-
Vehicle(string l_plate, string color, string brand); // Constructor completo
22+
Vehicle(string l_plate, string color, string brand, float height); // Constructor completo
2323
Vehicle(char* l_plate);
2424

2525
// Getters

src/utils/database/DBManager.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ void DBManager::prepareParkingDB() {
2626
sql = "CREATE TABLE IF NOT EXISTS vehicle("
2727
"license_plate TEXT PRIMARY KEY,"
2828
"brand TEXT,"
29-
"color TEXT)";
29+
"color TEXT,"
30+
"height REAL)";
3031

3132
code = sqlite3_exec(DB, sql.c_str(), NULL, 0, NULL);
3233

@@ -260,8 +261,9 @@ Vehicle vehicleFromRow(sqlite3_stmt* stmt) {
260261
string license((const char*) sqlite3_column_text(stmt, 0));
261262
string brand((const char*) sqlite3_column_text(stmt, 1));
262263
string color((const char*) sqlite3_column_text(stmt, 2));
264+
float height = sqlite3_column_double(stmt, 3);
263265

264-
return Vehicle(license, brand, color);
266+
return Vehicle(license, brand, color, height);
265267
}
266268

267269
Vehicle DBManager::retrieveVehicle(const char* l_plate) {
@@ -293,12 +295,13 @@ bool DBManager::insertVehicle(Vehicle& v) {
293295
sqlite3_stmt* stmt;
294296
bool success;
295297

296-
string sql = "INSERT INTO vehicle(license_plate, brand, color) VALUES (?, ?, ?)";
298+
string sql = "INSERT INTO vehicle(license_plate, brand, color, height) VALUES (?, ?, ?, ?)";
297299

298300
sqlite3_prepare_v2(DB, sql.c_str(), -1, &stmt, NULL);
299301
sqlite3_bind_text(stmt, 1, v.getLicensePlate().c_str(), -1, SQLITE_STATIC);
300302
sqlite3_bind_text(stmt, 2, v.getBrand().c_str(), -1, SQLITE_STATIC);
301303
sqlite3_bind_text(stmt, 3, v.getColor().c_str(), -1, SQLITE_STATIC);
304+
sqlite3_bind_double(stmt, 4, v.getHeight());
302305

303306
int code = sqlite3_step(stmt);
304307
if (code != SQLITE_DONE) {

0 commit comments

Comments
 (0)