public
Created

  • Download Gist
arel_ibm_db_visitor.diff
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
From 0c3e07e35581052c2058fdc835a05e085c9b8af0 Mon Sep 17 00:00:00 2001
From: Praveen Devarao <praveendrl@in.ibm.com>
Date: Mon, 7 Feb 2011 20:24:36 +0530
Subject: [PATCH] Added visitor ibm_db to handle ibm_db specifics
 
---
lib/arel/visitors.rb | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
 
diff --git a/lib/arel/visitors.rb b/lib/arel/visitors.rb
index 8410b2b..6370b1b 100644
--- a/lib/arel/visitors.rb
+++ b/lib/arel/visitors.rb
@@ -6,6 +6,7 @@ require 'arel/visitors/postgresql'
require 'arel/visitors/mysql'
require 'arel/visitors/mssql'
require 'arel/visitors/oracle'
+require 'arel/visitors/ibm_db'
require 'arel/visitors/join_sql'
require 'arel/visitors/where_sql'
require 'arel/visitors/order_clauses'
@@ -22,6 +23,7 @@ module Arel
'oracle_enhanced' => Arel::Visitors::Oracle,
'sqlite' => Arel::Visitors::SQLite,
'sqlite3' => Arel::Visitors::SQLite,
+ 'ibm_db' => Arel::Visitors::IbmDB,
}
ENGINE_VISITORS = Hash.new do |hash, engine|
--
1.6.0
 
 
From 6228ece599f06450e6369e21efaf2d8ec75d6036 Mon Sep 17 00:00:00 2001
From: Praveen Devarao <praveendrl@in.ibm.com>
Date: Mon, 7 Feb 2011 20:29:53 +0530
Subject: [PATCH] Added visitor ibm_db to handle ibm_db specifics
 
---
lib/arel/visitors/ibm_db.rb | 52 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 52 insertions(+), 0 deletions(-)
create mode 100644 lib/arel/visitors/ibm_db.rb
 
diff --git a/lib/arel/visitors/ibm_db.rb b/lib/arel/visitors/ibm_db.rb
new file mode 100644
index 0000000..6e2ebcd
--- /dev/null
+++ b/lib/arel/visitors/ibm_db.rb
@@ -0,0 +1,52 @@
+# +-----------------------------------------------------------------------+
+# | |
+# | Copyright (c) 2011 IBM Corporation |
+# | |
+# | Permission is hereby granted, free of charge, to any person obtaining |
+# | a copy of this software and associated documentation files (the |
+# | "Software"), to deal in the Software without restriction, including |
+# | without limitation the rights to use, copy, modify, merge, publish, |
+# | distribute, sublicense, and/or sell copies of the Software, and to |
+# | permit persons to whom the Software is furnished to do so, subject to |
+# | the following conditions: |
+# | |
+# | The above copyright notice and this permission notice shall be |
+# | included in all copies or substantial portions of the Software. |
+# | |
+# | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
+# | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
+# | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.|
+# | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR |
+# | ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
+# | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
+# | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
+# | |
+# +-----------------------------------------------------------------------+
+
+#
+# Author: Praveen Devarao <praveendrl@in.ibm.com>
+#
+
+module Arel
+ module Visitors
+ class IbmDB < Arel::Visitors::ToSql
+ def visit_Arel_Nodes_SelectStatement o
+ limit = offset = nil
+ sqlSegment = [
+ o.cores.map { |x| visit_Arel_Nodes_SelectCore x }.join,
+ ("ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty?),
+ ].compact.join ' '
+
+ # Add limit offset segments
+ limit = o.limit.expr if o.limit
+ offset = o.offset.expr if o.offset
+ @engine.connection.add_limit_offset!(sqlSegment,{:limit=>limit,:offset=>offset})
+
+ # Append lock clause and join
+ [ sqlSegment,
+ (visit(o.lock) if o.lock),
+ ].compact.join ' '
+ end
+ end
+ end
+end
--
1.6.0

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.