Commit 7baa091f by karade

Update generator.c

parent b34d0175
Showing with 32 additions and 2 deletions
......@@ -151,7 +151,7 @@ void PrintTable(MYSQL_RES *result)
void insertPersonIntoTable(MYSQL* con, users data)
{
char query[1024];
char query[1024]; //salvestan mysql päringu stringi
sprintf(query, "INSERT INTO users (documentNum, firstName, "
"lastName, dateOfBirth, email, residency, checkedIn, seat,"
......@@ -162,10 +162,40 @@ void insertPersonIntoTable(MYSQL* con, users data)
printf("DEBUG:%s\n\n", query);
if (mysql_query(con, query)) {
if (mysql_query(con, query)) { //päring serverile
printf("Error inserting Users into MySQL table: %s\n", mysql_error(con));
exit(EXIT_FAILURE);
}
char bookingCode[9];
const char letters[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int i;
for (i = 0; i < 8; i++) //broneeringunumbri genereerimine
{
bookingCode[i] = letters[GetRand(0, 35)];
}
bookingCode[8] = '\0';
//päring et saada kätte viimane sisestatud väljale loodud ID
if (mysql_query(con, "SELECT last_insert_id();"))
{
finish_with_error(con);
}
MYSQL_RES *result = mysql_store_result(con);
MYSQL_ROW row;
row = mysql_fetch_row(result);
int res = atoi(row[0]);
sprintf(query, "INSERT INTO bookings (bookingNumber, flight_id, user_id)"
"VALUES ('%s', %d, %d);"
,bookingCode, data.flight_id, res);
if (mysql_query(con, query)) {
printf("Error creating bookings for the users: %s\n", mysql_error(con));
exit(EXIT_FAILURE);
}
}
MYSQL* connectToMySQLServer()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment