Home
Home | Blog

iHwy Development Blog

The iHwy team shares their musings about their development experiences.

Using GIT to install OSCommerce Contributions

Posted on September 23, 2009 17:24 by Mike

Adding an oscommerce contribution to an existing site has always been a huge pain.  You have to weed through messy code and figure out where you're suppose to put in the contribution's code without breaking anything.  A lot of time the install instructions for a contribution only give you the line number to work with, and who knows if that line number is going to be accurate in your code or not.  But, today I figured out a much less painful way to do it... using git.  Now, I don't necessarily recommend doing this without first understanding git at least a little... but if you've used git before, here's what you do: 

1. figure out which version of oscommerce the site is based on (usually found part way down in includes/application_top.php; something like "define('PROJECT_VERSION', 'osCommerce 2.2-MS2');")

2. pull that code in to a git repository

3. create a branch in git for the existing site and for the oscommerce code you just pulled in (all branches are pointing at the same place at the moment)

4. checkout the new branch

5. pull down the existing site's code and copy it over everything in the git repository

6. commit changes

7. checkout the oscommerce branch

8. create a new branch for the contribution you want to install

9. check out the contribution's branch

10. install the contribution (this is now much easier since you're installing it in to the base oscommerce code)

11. commit changes

12. checkout the existing site's branch

13. tell git to merge in the contribution's branch

14. resolve any conflicts

15. commit changes

The existing site's branch should now have the contribution's code nicely merged in to it.  This works because both the existing site's branch and the contribution's branch were both based on the same base branch.  This could theoretically be used to merge in multiple contributions and / or upgrade an existing site to the latest oscommerce code base without nearly as much pain as that usually causes.  Of course there will be conflicts and you will have to manually resolve those, but with a good file merge utility, that's not nearly as bad.

 


Using IDENTITY in a SELECT

Posted on September 8, 2009 17:35 by Mike
I learned a new sql trick today... I had to figure out how to get the position of a row within a result set (in this case the rank of a user based on points). I could get back the list of all the users and their points, but I didn't see a way to have a "rank" column. Then I found that you can use "IDENTITY" inside a select statement if the select statement is going in to a temporary table. That let me get all the results back and then add in a "rank" column using IDENTITY. That also let me figure out ranks on the fly and return just a single rank for a single user. That's what this sql does:

 

 

DECLARE @sportID int
DECLARE @personID int

SELECT dbo.CalcPoints(p.HomeScore, p.VisitorScore, g.HomeScore, g.VisitorScore) AS Points, PersonID
INTO #TmpPoints
FROM Game AS g
INNER JOIN Prediction AS p ON g.GameID = p.GameID
INNER JOIN UserPrediction AS up ON p.PredictionID = up.PredictionID
INNER JOIN Team AS ht ON ht.TeamID = g.HomeTeamID
INNER JOIN Team AS vt ON vt.TeamID = g.VisitorTeamID
WHERE
(g.HomeScore IS NOT NULL) AND (g.VisitorScore IS NOT NULL)
AND (ht.SportID = @sportID OR vt.SportID = @sportID)

SELECT IDENTITY (Int, 1, 1) AS Rank, PersonID, SUM(Points) AS Points
INTO #TmpRank
FROM #TmpPoints
GROUP BY PersonID
ORDER BY Points DESC

SELECT Rank, Points FROM #TmpRank WHERE PersonID = @personID

DROP TABLE #TmpRank
DROP TABLE #TmpPoints

 

 

There may be a more efficient way to do the above with less temp tables, but that was the best I could come up with in a short time and it's still pretty darn fast for what it does. Anyway, using IDENTITY in a select is pretty useful for things like determining the rank of something in an arbitrary list. So in case you didn't know you can do that, FYI, you can ;)