Archive for November, 2008
INSERT INTO `table` (`column`,`col2`) VALUES isn’t completely worthless
by chance on Nov.14, 2008, under mysql, web dev
In most cases, when doing an insert statement I use SET to increase readability. It is also nice because I can make dynamic statements with insert/update. It is because of these two reasons I never saw any value (for lack of a better term that isn't punny) to using VALUES. That is until I ran into a situation where I wanted to have a database level solution as opposed to making an application layer solution. The situation is as follows:
- create an entry in the parent table
- create entries in the child table that depends on the last insert id of the parent table.
Now that I think about it, there may have been a way to do it procedurally in SQL but the first solution I was stuck on how to make my next INSERT statement fulfill my criteria and be readable. This is where VALUES comes in. By using VALUES instead of SET, you can do a multi-row insert statement.
example:
INSERT INTO Resource SET ModuleID=LAST_INSERT_ID(), Name='contact', Description='Contact resource in the default module'; /* multi-row insert */ INSERT INTO Privilege (ResourceID,Name,Description) VALUES (LAST_INSERT_ID(),'*','All privileges for this resource'), (LAST_INSERT_ID(),'browse','Browse only privilege for this resource'), (LAST_INSERT_ID(),'read','Read only privilege for this resource'), (LAST_INSERT_ID(),'edit','Edit only privilege for this resource'), (LAST_INSERT_ID(),'add','Add only privilege for this resource'), (LAST_INSERT_ID(),'delete','Delete only privilege for this resource');
So now, VALUES isn't completely useless after all.
stupid *nix tricks
by chance on Nov.07, 2008, under *nix, noobtip
[Edit: Seems like the -u flag is on debian systems such as Ubuntu. Did a man on a FreeBSD system and saw it didn't have the flag available.]
I use the cp and mv a lot that the -r and -f flags almost always accompany them. I also now realize I've used them for so long with so little thought that I forgot that there were other flags. My newest infatuation is the -u flag.
Basically -u lets you do a merge, which came in handy when I had to manually update wordpress for the first time. I could tell you more or you could RTFM
Looking for something?
Use the form below to search the site:
Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!
Archives
All entries, chronologically...
