ar-sybase-jdbc-adapter 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +27 -0
- data/lib/arel/visitors/sybase_jtds.rb +10 -2
- data/lib/arjdbc/sybase/sybase_adapter_java.jar +0 -0
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -52,6 +52,33 @@ The problems here are:
|
|
52
52
|
|
53
53
|
I am not a Sybase expert, so *Please let me know if you are aware of more efficient ways to do limit and offset.*
|
54
54
|
|
55
|
+
== Limit and Count in Sybase ASE
|
56
|
+
|
57
|
+
There is another interesting issue with Sybase DB I have just discovered. To implement "limit" I add "TOP <limit>" to the
|
58
|
+
query and it works fine. To check how many records this query returns the obvios thing is to run something like
|
59
|
+
|
60
|
+
select count(*) from (select top 10 * from table_name) t -- DOES NOT WORK!
|
61
|
+
|
62
|
+
But it does not work! The result of this query will be total number of rows in the table. So the only solution will be to
|
63
|
+
fall back to `cursor` and get `@@rowcount` to get the number of rows.
|
64
|
+
|
65
|
+
declare crsr insensitive scroll cursor for
|
66
|
+
select * from <original query>
|
67
|
+
go
|
68
|
+
open crsr
|
69
|
+
|
70
|
+
set cursor rows <limit> for crsr
|
71
|
+
fetch absolute <offset> from crsr
|
72
|
+
|
73
|
+
select @@rowcount
|
74
|
+
|
75
|
+
close crsr
|
76
|
+
deallocate crsr
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
|
55
82
|
== Known issues
|
56
83
|
|
57
84
|
I am aware of a very strange issue where the driver does not work when the very first query uses "limit()".
|
@@ -1,9 +1,17 @@
|
|
1
1
|
module Arel
|
2
2
|
module Visitors
|
3
3
|
class SybaseJtds < Arel::Visitors::ToSql
|
4
|
+
|
5
|
+
def select_count? o
|
6
|
+
sel = o.cores.length == 1 && o.cores.first
|
7
|
+
projections = sel.projections.length == 1 && sel.projections
|
8
|
+
Arel::Nodes::Count === projections.first
|
9
|
+
end
|
10
|
+
|
11
|
+
|
4
12
|
def visit_Arel_Nodes_SelectStatement o
|
5
|
-
if o.offset
|
6
|
-
sql = super # if offset use the Java limit/offset parser
|
13
|
+
if o.offset || (o.limit && select_count?(o))
|
14
|
+
sql = super # if offset OR (limit & count) use the Java limit/offset/count parser
|
7
15
|
else
|
8
16
|
limit = o.limit
|
9
17
|
o.limit = nil
|
Binary file
|