2

I'm trying to output a stored procedure from Sql Server into an output of a coldfusion page. The coldfusion page calls the stored procedure correctly, but only part of the data is returned (xml is truncated). When I call the stored procedure within sql server, it gives the entire XML document with no fails. I'm wondering if Coldfusion has a limit, or am I not working the code correctly.

Here's the stored procedure:

USE [myschema]
GO
/****** Object:  StoredProcedure [dbo].[GEOIDKMLZIP]    Script Date: 9/18/2015 10:28:40 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[GEOIDKMLZIP] @Zip int
AS
DECLARE @kml XML
DECLARE @kmlout NVARCHAR(MAX)

SELECT @kml = CAST(concat('<?xml version="1.0" encoding="utf-16" ?>',
'<kml xmlns="http://www.opengis.net/kml/2.2">',
'<Document>',
'       <Style id="Licensed">
            <LineStyle>
                <color>ff000000</color>
                <width>2</width>
            </LineStyle>
            <PolyStyle>
                <color>1e1400FF</color>
                <fill>1</fill>
                <outline>1</outline>
            </PolyStyle>
        </Style>
        <Style id="NotLicensed">
            <LineStyle>
                <color>ff000000</color>
                <width>2</width>
            </LineStyle>
            <PolyStyle>
                <color>1e14F0FF</color>
                <fill>1</fill>
                <outline>1</outline>
            </PolyStyle>
        </Style>
        <Style id="Other">
            <LineStyle>
                <color>ff000000</color>
                <width>2</width>
            </LineStyle>
            <PolyStyle>
                <color>1e007800</color>
                <fill>1</fill>
                <outline>1</outline>
            </PolyStyle>
        </Style>' ,
(
            select 

                '<![CDATA[{"Zip":"' + z.ZipCode + '", "GEOID": "'+ z.GEOID+'"}]]>' as name,
                case t.IsLicensed
                    when 2 then '#Licensed'
                    when 1 then '#NotLicensed'
                    else '#Other'
                end as styleUrl, 
                polygons as Geometry
        from ZipCodeGEOID z
        join Tracts t on t.GEOID = z.GEOID
        join census_county_ref c on t.GEOID = c.GEOID
        where z.ZipCode = @Zip
FOR XML PATH('Placemark'), ELEMENTS), '</Document></kml>') AS XML)
--
-- Perform replacement of &lt; and &gt; with < and > respectively
--
SET @kmlout = REPLACE(REPLACE(REPLACE(REPLACE(CAST(@kml AS NVARCHAR(MAX)), '&lt;', '<'), '&gt;', '>'), '<Geometry>', ''), '</Geometry>', '')
SET @kmlout = REPLACE(@kmlout, 'utf-16', 'utf-8')
--
-- Return kmlout
--
SELECT @kmlout as kml

and here's zip2tractkml.cfm

<cfsetting showdebugoutput="yes">
<cfheader name="Content-Type" value="application/xml">
<cfstoredproc procedure="GEOIDKMLZIP" datasource="buyerhero">
    <cfprocparam value="#URL.ZIP#" cfsqltype="CF_SQL_INTEGER">

    <!--- One resultset is returned called "qEmployees" --->
    <cfprocresult name="response" resultset="1">
</cfstoredproc>
<cfset kml = XmlParse(response.kml)>
<cfoutput>#kml#</cfoutput>

I also tried just outputing the result with out the cfset:

<cfsetting showdebugoutput="yes">
<cfheader name="Content-Type" value="application/xml">

<cfstoredproc procedure="GEOIDKMLZIP" datasource="buyerhero">
    <cfprocparam value="#URL.ZIP#" cfsqltype="CF_SQL_INTEGER">

    <!--- One resultset is returned called "qEmployees" --->
    <cfprocresult name="kml" resultset="1">
</cfstoredproc>

<cfoutput>#kml.kmlout#</cfoutput>

but I got the same response (truncated xml). again, when I run this in SQL Server using:

EXEC    [dbo].[GEOIDKMLZIP]
        @Zip = N'53554'


GO

It works like a charm, and the XML is formatted properly. What am I missing? Thanks

arcee123
  • 101
  • 9
  • 41
  • 118
  • What kind of truncation happens? Is the xml still valid? Is it only the first subnode of the xml? You could check the _real_ data that MSSQL returns with wireshark. – Stefan Braun Sep 19 '15 at 19:36
  • The way the sproc rolls gives the xml in one single block, tags and all. When cf pulls it. It stops at some random point along the way without explanation – arcee123 Sep 19 '15 at 22:27
  • Did you check your datasource settings to ensure [CLOB/long text retrieval](http://stackoverflow.com/questions/5075215/retreving-long-text-clob-using-cfquery) is enabled? – Leigh Sep 20 '15 at 04:27
  • That was it. You are awesome. Can you put that in an answer block so I can give it credit? Thx – arcee123 Sep 20 '15 at 20:07
  • Thanks, but since an answer already exists, best to just close this thread as a dupe and vote up the existing answer :) – Leigh Sep 21 '15 at 00:34
  • How do you close a thread? – arcee123 Sep 21 '15 at 00:47

0 Answers0