Swap Insert for Update When Key Exists

When synchronizing tables or databases, sometimes it is useful to have a way to update a row if there is already an entry for a key. Using the MySQL syntax, ON DUPLICATE KEY UPDATE, it is possible to insert a row if it doesn’t exist or update it if there is already a row with that key.

[Read the rest of this entry...]

OpenID vs OAuth

After attending the recent BarCamp, I realized how much talent the Orlando community has. Central Florida seems to be booming with web developers and start-ups. There was one such company that did about 3.5 presentations on the first day (I missed out on the second day). The .5 part was what interested me most. It was titled “ Fuck OpenID“. Which I was definitely interested in since Jason Buckner and I did a presentation at the previous BarCamp about OpenID, and threw in a quick plug for TinyID.us.

[Read the rest of this entry...]

Multiple Inserts with a Subquery

Inserting multiple rows into a table is simple.

INSERT INTO table1 (id) VALUES (1), (2)

But what if you want to use a subquery to replace the explicit query with something more dynamic. This should be possible, however, searching the internet didn’t get me (or my colleagues) any closer to figuring this out. The obvious attempt of replacing (1), (2) with (subquery) resulted in the error your subquery returns multiple records

In the end we discovered that removing VALUES from the query gave the desired effect.

INSERT INTO table1 (id) (SELECT id FROM table2)

Executing the above query will insert a row into table1 for every result returned by the subquery.

How to Break a MySQL Left Join

Care must be taken when placing conditions on the results of the right-hand table of a LEFT JOIN because it could easily become a normal JOIN since MySQL is using a NULL row for every column in the right-hand table when no records exist.

[Read the rest of this entry...]

Web-Based Version Management

This is an idea to help with CyTE, but I’d like to start seeing this idea applied to other web-based software as well. Having an interface to update the software easily and keep a revision history would help web-based apps become closer to desktop apps. Programs like Adobe Flash Player will check for updates periodically, download them, and install them. It would be nice for web-based apps such as phpBB3 or CyTE to have similar possibilities.

The plan is to have a page in an admin section that will check the project’s svn repository (a tag like latest-stable will help). If there is something newer than the current version, it will check if any of the files have been modified locally (since it’s open source). If there are modifications it will predict whether there will be conflicts or not. There will be a button to update the code. Before it updates, a backup will be made. Rollback options will be provided for local backups and each revision in the repository will be able to be installed. This should provide maximum flexibility combined with ease of use. The biggest obstacle of this at the moment is there isn’t a package written in php that handles svn without needing required modules in php. Being able to use this on any server with php5 is the biggest requirement.