Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. void insertEmployee(MYSQL* conn, Employee const& emp)
  2. {
  3.     if (conn != nullptr)
  4.     {
  5.         std::string fmt = "INSERT INTO employees(employeeNumber, lastName, firstName, extension, email, officeCode, reportsTo, jobTitle) "
  6.             "VALUES (%d, \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", %s, \"%s\")";
  7.  
  8.         std::vector<char> v(2000);
  9.  
  10.         sprintf(&v[0], v.size(), fmt,
  11.             emp.empNum,
  12.             emp.lastName,
  13.             emp.firstName,
  14.             emp.extension,
  15.             emp.email,
  16.             "1",
  17.             emp.reportsTo,
  18.             emp.jobTitle
  19.         );
  20.  
  21.         if (mysql_query(conn, const_cast<char const*>(v.data())) == 0)
  22.             std::cout << "Employee successfully added, check to verify by checking the number of the employee from the main menu, or using your DBMS application" << std::endl;
  23.         else
  24.             std::cout << "Error occurred: " << mysql_errno(conn) << " " << mysql_error(conn) << std::endl;
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement