Guest User

Untitled

a guest
Jun 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. /* get the id of the customer. */
  2. int
  3. Transaction::getCustomerId (const int tran_id) {
  4. /* declare a sql query object. */
  5. QSqlQuery query;
  6.  
  7. /* prepare a sql query with place holders. */
  8. query.prepare("SELECT cust.id FROM customer AS cust INNER JOIN transacts AS tran ON cust.id = tran.cust_id WHERE tran.id = :tran_id");
  9.  
  10. /* bind values to the query placeholders. */
  11. query.bindValue(":tran_id", tran_id);
  12.  
  13. /* execute the query. */
  14. query.exec();
  15.  
  16. /* the customer's id (assume not found). */
  17. int cust_id = -1;
  18.  
  19. /* try to get the first record. */
  20. if (query.next()) {
  21. /* get the id of the customer. */
  22. cust_id = query.value(0).toInt();
  23. }
  24.  
  25. /* return the id of the customer. */
  26. return cust_id;
  27. }
Add Comment
Please, Sign In to add comment