-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: SQL Server 6.5 and setMaxResults(..) [no LIMIT or TOP]
PostPosted: Thu Jul 14, 2005 5:53 pm 
Newbie

Joined: Thu Jul 14, 2005 5:39 pm
Posts: 12
Location: Ann Arbor, MI
Hiya, brand-newbie here.

While I'm actually using SQL Server 2000 for a project, but I'm forced to set it to SQL Server 6.5 compatibility, which means if I want to select out only 10 results, I cannot use LIMIT, nor can I use TOP -- 6.5 uses "SET ROWCOUNT(#); ... SET ROWCOUNT(0);"

I tried both SQL Server drivers, but Hibernate -- I'm using 3.0.5 -- only goes back in compatibility as far as SQL Server 7, because when I setMaxResults(10) during a query, the generated query is trying to use the TOP keyword, which is, of course, throwing an exception.


I've created a SQLServer65Dialect class (subclassing org.hibernate.dialect.SQLServer7Dialect) which simply overrides the getLimitString(String querySelect, int offset, int limit) method as follows:

Code:
    public String getLimitString(String querySelect, int offset, int limit) {
        if (offset>0) throw new UnsupportedOperationException("sql server has no offset");
        return new StringBuffer( querySelect.length()+8 )
            .append("SET ROWCOUNT " + limit + "; ")
            .append(querySelect)
            .append("; SET ROWCOUNT 0;") // Resetting the rowcount to unlimited
            .toString();
    }



I'm assuming there was no other way, since SQLServerDialect is for SQL Server 2K and SQLServer7Dialect clearly only goes back so far as 7.0 compliance. If I'm not wrong in that, should I submit this class via JIRA?

Thanks,
Jim


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.