-->
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.  [ 4 posts ] 
Author Message
 Post subject: query and count
PostPosted: Sat Sep 10, 2005 6:17 am 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
I have an IQuery that has some parameters and I set the paging options. I execute this query to get the results, but I also need to get the total count of items that the query would return if I wasn't using paging.

Is there anyway to get the count without completey recreating the query, parameters and all?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 10, 2005 6:27 am 
Senior
Senior

Joined: Thu Jun 02, 2005 5:03 pm
Posts: 135
Location: Paris
An excellent question, and one to which I don't have an answer, sorry! :(

I've been constructing my queries in parts as separate strings.; the SELECT clause, the FROM clause (incl. joins) and the WHERE clause.

When I need to get the count I just create a new query with the query string stating "SELECT COUNT() ", append the FROM and WHERE clause strings and then re-add the all the parameters.

A bit of a pain, but it works.

If anyone else out there has a more elegant solution I'd love to hear it too!

Cheers,

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 12, 2005 11:33 am 
Regular
Regular

Joined: Tue May 24, 2005 12:55 pm
Posts: 56
I'm not even sure how to do this in plain SQL. How would you do this with plain ADO.NET and SQL?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 12, 2005 2:54 pm 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
well with regular sql I would have a stored procedure that did the paging which also returned an output paramter of the count.

I guess with dynamic sql you would need 2 SqlCommands also.

This won't be much of an issue once the Count property feature of ICriteria gets completed. I wish this would get done before version 1.0 release.


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

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.