Skip to main content
Participant
July 19, 2020
Question

missing the piece of code where i am unable to generate the results in pagination and writing file

  • July 19, 2020
  • 1 reply
  • 345 views

I have this code for CF where i am trying to fetch the rows of the tables by minimizing the load on server

 

<cfset var offset = 0>
<cfset listoverloop = "users,roles,adresses,email">

<cfloop list="#loopoverLst#" index="k">
<cfquery name="local.sTotalRecords" attributeCollection="#variables.dataAttr#">
	        		select count(1) as totalRecords 
	        		from #table#
	        	</cfquery>
	        	<cfset local.offsetrequired = local.sTotalRecords.totalRecords gte 1000 ? 'yes' : 'no'> 
	        	<cfset local.rowsTofetch = "1500">
		        <cfquery name="insertData" attributeCollection="#variables.dataAttr#">
		          SELECT 
		          	 * FROM #k# 
ORDER BY 1 DESC 
		          	OFFSET #local.offset# ROWS
						FETCH NEXT #local.rowsTofetch# ROWS ONLY 

<cfsavecontent variable="createTt">
<cfloop query="insertData">
 write my inserts 

<cfset local.offset += local.rowsTofetch>
</cfloop>
</cfsavecontent>


<cfif FileExists("#ExpandPath('#table#.sql')#")>
	        	<cffile action="append" file="#ExpandPath('#table#.sql')#" output="#createTt#">
	        <cfelse>
	        	<cffile action="write" file="#ExpandPath('#table#.sql')#" output="#createTt#">
	        </cfif>

 

but it is not doing any pagination for the records, because i am writing the records in the files

This topic has been closed for replies.

1 reply

BKBK
Community Expert
Community Expert
August 5, 2020

It is not doing any pagination for the records because you haven't used the boolean condition local.offsetrequired anywhere.

Participant
August 5, 2020

But loca.offsetrequired is a condition to check if the records are more than 1000 and if yes, then do the pagination else just query the table adn write the results, 

 

The code is basically t create the files of every table with 15500 records in it and if they are more, create more files with same tablename and an incremental value

 

 

BKBK
Community Expert
Community Expert
August 5, 2020

Sorry, I don't understand. How, and where in the code, is pagination expected to occur?

 

What does the above code do (that you don't expect it to)? What do you want it to do?