Title: [636] trunk/activerecord-jdbc: Correct implementation of insert_bind and update_bind
Revision
636
Author
olabini
Date
2007-06-18 09:29:57 -0400 (Mon, 18 Jun 2007)

Log Message

Correct implementation of insert_bind and update_bind

Modified Paths


Diff

Modified: trunk/activerecord-jdbc/lib/active_record/connection_adapters/jdbc_adapter.rb (635 => 636)


--- trunk/activerecord-jdbc/lib/active_record/connection_adapters/jdbc_adapter.rb	2007-06-18 11:00:33 UTC (rev 635)
+++ trunk/activerecord-jdbc/lib/active_record/connection_adapters/jdbc_adapter.rb	2007-06-18 13:29:57 UTC (rev 636)
@@ -339,6 +339,14 @@
         connection.adapter = self
       end
 
+      def insert_bind(*args)
+        @connection.insert_bind *args
+      end
+
+      def update_bind(*args)
+        @connection.update_bind *args
+      end
+
       def modify_types(tp)
         tp
       end

Modified: trunk/activerecord-jdbc/src/java/JdbcAdapterInternalService.java (635 => 636)


--- trunk/activerecord-jdbc/src/java/JdbcAdapterInternalService.java	2007-06-18 11:00:33 UTC (rev 635)
+++ trunk/activerecord-jdbc/src/java/JdbcAdapterInternalService.java	2007-06-18 13:29:57 UTC (rev 636)
@@ -711,19 +711,19 @@
      */
     public static IRubyObject insert_bind(IRubyObject recv, IRubyObject[] args) throws SQLException {
         Ruby runtime = recv.getRuntime();
-        Arity.checkArgumentCount(runtime, args, 3, 4);
+        Arity.checkArgumentCount(runtime, args, 3, 7);
         Connection c = (Connection)recv.dataGetStruct();
         PreparedStatement ps = null;
         try {
-            ps = c.prepareStatement(RubyString.objAsString(args[0]).toString());
+            ps = c.prepareStatement(RubyString.objAsString(args[0]).toString(), Statement.RETURN_GENERATED_KEYS);
             setValuesOnPS(ps, runtime, args[1], args[2]);
             ps.executeUpdate();
+            return unmarshal_id_result(runtime, ps.getGeneratedKeys());
         } finally {
             try {
                 ps.close();
             } catch(Exception e) {}
         }
-        return args.length > 5 ? args[5] : runtime.getNil();
     }
 
     /*
@@ -731,7 +731,7 @@
      */
     public static IRubyObject update_bind(IRubyObject recv, IRubyObject[] args) throws SQLException {
         Ruby runtime = recv.getRuntime();
-        Arity.checkArgumentCount(runtime, args, 3, 1);
+        Arity.checkArgumentCount(runtime, args, 3, 4);
         Connection c = (Connection)recv.dataGetStruct();
         PreparedStatement ps = null;
         try {
_______________________________________________
Jruby-extras-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/jruby-extras-devel

Reply via email to