Exemple #1
0
//Polls the database for this customer by ID and returns
Customer *Database::getCustomer(int customerId) {

	// create and open database
	SQLiteDatabase *pDatabase = this->connect();
	SQLiteStatement *pStmt = this->createStatement(pDatabase);

	pStmt->Sql("SELECT firstName, lastName, emailAddress, PIN FROM Customer where customerId = ?");
	pStmt->BindInt(1, customerId);
	pStmt->Execute();

	//Build the customer attributes from the returned query
	string lastName = pStmt->GetColumnString(0);
	string firstName = pStmt->GetColumnString(1);
	string emailAddress = pStmt->GetColumnString(2);
	int pin = pStmt->GetColumnInt(3);

	pStmt->FreeQuery();

	//Build and return a customer object
	return new Customer(customerId, firstName, lastName, emailAddress, pin);
}
Exemple #2
0
//Get a customer's account by customerId
Account *Database::getAccount(int custId){

	// create and open database
	SQLiteDatabase *pDatabase = this->connect();
	SQLiteStatement *pStmt = this->createStatement(pDatabase);

	//Query by CustomerId
	pStmt->Sql("SELECT * FROM Account where customerId = ?");
	pStmt->BindInt(1, custId);
	pStmt->Execute();

	//Account Table: accountId, customerId, balance, accountType
	int accountId = pStmt->GetColumnInt(0);
	int customerId = pStmt->GetColumnInt(1);
	double balance = pStmt->GetColumnDouble(2);
	string accountStatus = pStmt->GetColumnString(3);
	string accountType = pStmt->GetColumnString(4);

	pStmt->FreeQuery();

	// return the account to the calling function
	return new Account(accountId, customerId, balance, accountStatus,accountType);
}
Exemple #3
0
//Return a customer from the database based on email address
Customer *Database::getCustomer(string email) {

	// create and open database
	SQLiteDatabase *pDatabase = this->connect();
	SQLiteStatement *pStmt = this->createStatement(pDatabase);

	//Query the database for a customer with this specific email address
	pStmt->Sql("SELECT customerId, firstName, lastName, emailAddress, PIN FROM Customer where emailAddress = ?");
	pStmt->BindString(1, email);
	pStmt->Execute();

	//Parse customer attributes from returned query
	int customerId = pStmt->GetColumnInt(0);
	string firstName = pStmt->GetColumnString(1);
	string lastName = pStmt->GetColumnString(2);
	string emailAddress = pStmt->GetColumnString(3);
	int pin = pStmt->GetColumnInt(4);

	pStmt->FreeQuery();

	//Build and return a customer object
	return new Customer(customerId, firstName, lastName, emailAddress, pin);
}