Showing posts with label SQL. Show all posts
Showing posts with label SQL. Show all posts

Sunday, May 27, 2007

useful mysql sql

\c cancel current sql
\q quit mysql command shell

mysql> select 'a' union select 3;
+---+
| a |
+---+
| a |
| 3 |
+---+
2 rows in set (0.29 sec)

Saturday, May 12, 2007

SQL Transaction in Rails

http://snippets.dzone.com:80/posts/show/3995


def fetch_value
sql = ActiveRecord::Base.connection();
sql.execute "SET autocommit=0";
sql.begin_db_transaction
id, value =
sql.execute("SELECT id, value FROM sometable WHERE used=0 LIMIT 1 FOR UPDATE").fetch_row;
sql.update "UPDATE sometable SET used=1 WHERE id=#{id}";
sql.commit_db_transaction

value;
end