<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -30,6 +30,15 @@ class MysqlSession
       SqlSession.connection.connection
     end
 
+    def query(sql)
+      connection = session_connection
+      begin
+        connection.query sql
+      rescue Exception =&gt; e
+        message = &quot;#{e.class.name}: #{e.message}: #{sql}&quot;
+        raise ActiveRecord::StatementInvalid, message
+      end
+    end
     # try to find a session with a given +session_id+. returns nil if
     # no such session exists. note that we don't retrieve
     # +created_at+ and +updated_at+ as they are not accessed anywhyere
@@ -38,7 +47,7 @@ class MysqlSession
       connection = session_connection
       connection.query_with_result = true
       session_id = Mysql::quote(session_id)
-      result = connection.query(&quot;SELECT id, data FROM sessions WHERE `session_id`='#{session_id}' LIMIT 1&quot; + (lock ? ' FOR UPDATE' : ''))
+      result = query(&quot;SELECT id, data FROM sessions WHERE `session_id`='#{session_id}' LIMIT 1&quot; + (lock ? ' FOR UPDATE' : ''))
       my_session = nil
       # each is used below, as other methods barf on my 64bit linux machine
       # I suspect this to be a bug in mysql-ruby
@@ -62,9 +71,9 @@ class MysqlSession
     # caller's responsibility to pass a valid sql condition
     def delete_all(condition=nil)
       if condition
-        session_connection.query(&quot;DELETE FROM sessions WHERE #{condition}&quot;)
+        query(&quot;DELETE FROM sessions WHERE #{condition}&quot;)
       else
-        session_connection.query(&quot;DELETE FROM sessions&quot;)
+        query(&quot;DELETE FROM sessions&quot;)
       end
     end
 
@@ -78,11 +87,11 @@ class MysqlSession
     if @id
       # if @id is not nil, this is a session already stored in the database
       # update the relevant field using @id as key
-      connection.query(&quot;UPDATE sessions SET `updated_at`=NOW(), `data`='#{Mysql::quote(data)}' WHERE id=#{@id}&quot;)
+      self.class.query(&quot;UPDATE sessions SET `updated_at`=NOW(), `data`='#{Mysql::quote(data)}' WHERE id=#{@id}&quot;)
     else
       # if @id is nil, we need to create a new session in the database
       # and set @id to the primary key of the inserted record
-      connection.query(&quot;INSERT INTO sessions (`updated_at`, `session_id`, `data`) VALUES (NOW(), '#{@session_id}', '#{Mysql::quote(data)}')&quot;)
+      self.class.query(&quot;INSERT INTO sessions (`updated_at`, `session_id`, `data`) VALUES (NOW(), '#{@session_id}', '#{Mysql::quote(data)}')&quot;)
       @id = connection.insert_id
     end
   end</diff>
      <filename>lib/mysql_session.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>5b277cc9e690e6d1a155f5fc2ff5dd23fac0a349</id>
    </parent>
  </parents>
  <author>
    <name>Frederick Cheung</name>
    <email>frederick.cheung@gmail.com</email>
  </author>
  <url>http://github.com/fcheung/smart_session_store/commit/2f172925c136a10ae2e4d600f54facc96be20aa5</url>
  <id>2f172925c136a10ae2e4d600f54facc96be20aa5</id>
  <committed-date>2009-11-03T06:24:30-08:00</committed-date>
  <authored-date>2009-11-03T06:24:30-08:00</authored-date>
  <message>wrap exceptions from queries into ActiveRecord::StatementInvalid</message>
  <tree>2d8b0221b9dfd3af189b3c248961a8f74c64359e</tree>
  <committer>
    <name>Frederick Cheung</name>
    <email>frederick.cheung@gmail.com</email>
  </committer>
</commit>
