Updated

Matt Cain had his best outing in nearly a month, Nate Schierholtz added three hits and made an outstanding defensive play and the San Francisco Giants beat the Arizona Diamondbacks 3-2 Thursday to complete a perfect homestand.

Eli Whiteside doubled twice to help the Giants go 6-0 at home. They swept Colorado and then Arizona to extend their season-high winning streak to six games.

Gerardo Parra, Xavier Nady and Justin Upton had two hits apiece for Arizona, which has lost four straight.

The Diamondbacks scored twice in the eighth and had the tying run at third base with one out in the ninth before Javier Lopez recorded the final two outs for his first save in nearly five years.

Cain (3-2) scattered seven hits over 7 2-3 innings in his first win since April 15. The San Francisco right-hander also survived a scary moment in the seventh when he appeared to get hit on his pitching hand on a ball thrown by Arizona starter Daniel Hudson (3-5).

Cain, who was trying to put down a sacrifice bunt, grabbed his hand and immediately dropped to his knees as manager Bruce Bochy and trainer Dave Groeschner rushed out from the dugout.

Home plate umpire Bill Miller ruled the ball hit Cain's bat and was a foul. After getting checked out, Cain stayed in the game and got the bunt down, moving Eli Whiteside from second to third. Andres Torres followed with a double and Aubrey Huff's RBI single made it 3-0.

Schierholtz, making just his 10th start of the season, made big plays in the field and at the plate to give the Giants an early boost. He singled in Cody Ross in the second to give San Francisco a 1-0 lead, then threw out Parra at second base after he singled off the wall in right the next inning.

Schierholtz, who grounded out with the bases loaded in the third, also beat out an infield single in the sixth but was stranded at third.

The Giants tacked on two more and Cain made it stand up with his best outing in nearly a month. He left after giving up back-to-back singles with two outs in the eighth.

Reliever Jeremy Affeldt got Stephen Drew to hit a sharp grounder to first but the ball glanced off Huff's glove for a hit. Parra easily scored from third to end the shutout bid.

Upton followed with an RBI single off Ramon Ramirez to cut the gap to 3-2 but Ramirez got Russell Branyan to ground out wit the tying run at second.

Ryan Roberts singled leading off the ninth for Arizona and took third on Chris Young's pinch-hit single. Lopez, working in the closer role while Brian Wilson rested after pitching in five straight games, struck out Kelly Johnson then got Parra on a swinging strikeout to end the game.

It's Lopez's first save since Sept. 12, 2006.

NOTES: Giants C Buster Posey was held out of the starting lineup after taking two foul balls off his mask on Wednesday night. "There are no concerns or issues," Bochy said. "We're just being a little careful." ... Giants RHP Santiago Casilla, on the DL since April 6 with an inflamed right elbow, is scheduled to start for Single-A San Jose on Friday. Bochy said the plan is for Casilla to throw 20-25 pitches then be stretched out to two innings in his next outing. ... Parra's error on Torres' fly ball in the third was his first of the season. ... The Giants have sold out each of their 15 home games so far.