CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> ASP

 CountSQL gives incorrect Record Count - Solution for Navigation

Print topic Send  topic

Author Message
marcwolf


Posts: 361
Posted: 05/04/2005, 7:26 PM

Hi All..

I had a problem that I solved and I think others have the same issue.

Often when you have a very complex SQL statement with a lot of joins that is displayed on a page with a Navigator control - you will find that there is a difference between the number of items AND what CCS thinks is the number of records.

I.e. - my SQL when run in a SQL editor brings back 14 records, BUT CCS insists that there are 16 records. And thats a problem when the number of items on a page is set at 15. One page too many on the Navigator.

Now - one can modify the CountSQL property in the BeforeBuildSelect area

  
Dim SQL  
sSQL = Replace product.datasource.Countsql, "SELECT", "SELECT DISTINCT")  
product.datasource.Countsql = sSQL   
  

to have a distinct inserted into it but often with these queries a mere Count(*) will NOT work!!!.

After much pulling of hair and digging through the CCS code I found the solution.

We know that there are 14 records returned. We can run the SQL in an independant (SqlYog for MySQL) app to see this.

So how do we get CCS to use the correct number.

The trick is in the AfterExecuteSelect. Here is my snippet and I wil explain

  
Dim iloop   
iLoop=0  
product.datasource.recordset.recordset.movefirst  
do while not product.datasource.recordset.eof()  
	iloop = iloop + 1  
	product.datasource.recordset.recordset.movenext  
loop  
product.datasource.recordset.recordset.movefirst  
product.datasource.recordset.recordcount = iloop  

What am I doing.

Firstly I am creating an empty loop variable, then moving the TRUE recordset (Not the CCS Datasource class one) to the start.
Next I loop throught doing a count until I hit the end.
Move it back to the beginning again so that CCS can work with it later
and then....

Setting the CCS DataSource class's recordcount to the correct value.

From here the Navigator will work correctly as well as any other reference to the number of records.

It is often a lot of fun digging throught all of the object references to get to the real one but it is worth it in the end.

Have fun and hope this helps

Dave

_________________
' Coding Coding Coding
Keep Those Keyboards Coding.
Raw Code!!!!!!!
View profile  Send private message
marcwolf


Posts: 361
Posted: 05/04/2005, 7:52 PM

Opps.. Don't you hate it when you have posted someing and find a bug later .. Well :-( I did..

Basically the concept above is correct except you will need to create a seperate recordset rather than the one that CCS has used

So - in the AfterExecuteSelect do this..

  
Dim iloop , rs  
iLoop=0  
set rs = dbcv_db.execute(product.datasource.sql & " where " & product.datasource.where)  
do while not rs.eof  
	iloop = iloop + 1  
	rs.movenext  
loop  
product.datasource.recordset.recordcount = iloop  

CCS seems to use the LIMIT instruction within the SQL to bring back precisely one page worth of records.. and we need all of the records.

Enjoy

Dave
_________________
' Coding Coding Coding
Keep Those Keyboards Coding.
Raw Code!!!!!!!
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.