Skip to main content
Participant
Jul 19, 2020 10:37 PM UTC
Question

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

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 is closed to new replies. Start a new post to keep the conversation going.

8 replies

BKBK
Community Expert
Community Expert
Aug 5, 2020 9:43 AM UTC

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

Translate
Participant
Aug 5, 2020 11:32 AM UTC

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

 

 

Translate
BKBK
Community Expert
Community Expert
Aug 5, 2020 2:43 PM UTC

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?

Translate