Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* get the id of the customer. */
- int
- Transaction::getCustomerId (const int tran_id) {
- /* declare a sql query object. */
- QSqlQuery query;
- /* prepare a sql query with place holders. */
- 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");
- /* bind values to the query placeholders. */
- query.bindValue(":tran_id", tran_id);
- /* execute the query. */
- query.exec();
- /* the customer's id (assume not found). */
- int cust_id = -1;
- /* try to get the first record. */
- if (query.next()) {
- /* get the id of the customer. */
- cust_id = query.value(0).toInt();
- }
- /* return the id of the customer. */
- return cust_id;
- }
Add Comment
Please, Sign In to add comment