Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Service guidance

New Here ,
Feb 11, 2009 Feb 11, 2009
I am calling a web service in ColdFusion 8 that outputs an xml ( phonebook.xml) with almost 1,000 records.
Since I dont quite understand how it works I would like to know if the below grabs the 2 records only from the web service. Or does the script below grab all 1,000 records and put it in the CFHTTP.FileContent and then the cfc grabs the 2 records that are output?

<cfhttp url=" http://localhost:8500/TestingCF/phonebook.xml" method="GET" resolveurl="No" ></cfhttp>
<cfset mydoc = XmlParse(CFHTTP.FileContent)>


<cfset xmlObject = xmlParse(mydoc)/>

<cfset size = "#arrayLen(xmlObject["phonebook"].xmlChildren)#">

<cfset myquery = QueryNew("cat, firstName, lastName, phone,email")>

<cfset temp = QueryAddRow(myquery, #size#)>


<cfloop index="i" from = "1" to = "#size#">
<cfset temp = QuerySetCell(myquery, "cat",
#mydoc.phonebook.contact.XMLAttributes['category']#, #i#)>
<cfset temp = QuerySetCell(myquery, "firstName",
#mydoc.phonebook.contact.firstName.XmlText#, #i#)>
<cfset temp = QuerySetCell(myquery, "lastName",
#mydoc.phonebook.contact.lastName.XmlText#, #i#)>
<cfset temp = QuerySetCell(myquery, "phone",
#mydoc.phonebook.contact.phone.XmlText#, #i#)>
<cfset temp = QuerySetCell(myquery, "email",
#mydoc.phonebook.contact.email.XmlText#, #i#)>
</cfloop>
<cfinvoke component="pbook_meths" method="sortLName" returnVariable="Result">
<cfinvokeargument name="q_obj" value="#myquery#">
</cfinvoke>


<table border=1 width=500 align=center>
<th>category</th><th>fist name</th><th>last
name</th><th>phone</th><th>email</th>
<cfoutput query="Result">
<tr>
<td>#cat#</td><td>#firstName#</td>
<td>#lastName#</td> <td>#phone#</td>
<td>#email#</td>
</tr>
</cfoutput>
</table>


The cfc

<cffunction name="sortLName" access="remote" returnType="query">
<cfargument name="q_obj" required="Yes" >
<cftry>
<cfquery name="pbTest" dbType="query">
SELECT *
FROM arguments.q_obj
where lastname = 'Smith'
</cfquery>
<cfcatch type="Any">
<P><cfoutput>#cfcatch.message#</cfoutput></P>
</cfcatch>
</cftry>
<cfreturn pbTest>
</cffunction>

The output:

category fist name last name phone email
friend John Smith 412-555-1212 johnsmith@email.com
friend Jane Smith 412-555-1212 janesmith@email.com


I hope Iam only grabbing 2 records each time the web service is called and not 1000 records?
229
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 11, 2009 Feb 11, 2009
LATEST
Well, I haven't tested anything, but it looks like you basically grab an XML file (not sure how it is generated) then put the data into a query object by looping it. If there are 1000 lines of data then your query object will be 1000 lines (of course). Then your invoking a function passing the query object as an argument. The function then seems to grab any data that has the last name of Smith. You are getting all of the columns with * but only getting two records for smith because your WHERE clause is filtering it. So in a word, YES, the query only returns / gets two records based on your criteria. If you didn't have the WHERE clause I imagine it would get everything (1000).

Basically, your code grabs a file with 1000 lines and then puts this into a query object. All your CFC does is grab a subset of this data using SQL. Your query object is still 1000 lines though. The query will be fast, but if you're getting performance issues, it will be because of the XML files size itself.

Mikey.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources