When I query a DB table with an XML column
<cfquery name="qryData">
DECLARE #data xml = '<ul class="xoxo"><li><span><b>Config</b> [<var>1</var>]:</span><code>compliance</code></li></ul>'
SELECT #data AS Conf
</cfquery>
It crashed when converted to WDDX
<cfwddx action = "cfml2wddx" input = "#qryData#" output = "wddxText">
Adobe Bugbase: https://bugbase.adobe.com/index.cfm?event=bug&id=4152876
Is there a better workaround than Casting to varchar(max) ?
This issue was corrected with ColdFusion 2016 update 3
https://helpx.adobe.com/coldfusion/kb/coldfusion-2016-update-3.html
Related
I cannot figure this out. My company recently upgraded our ColdFusion Server from CF9 to CF2021. One of my pages uses queries of queries to run. Prior to the upgrade the page worked fine. However after the upgrade the query of query where statement is not returning any results. Even though the original query has the data. The data is coming from DB2 data source in case that changed with the new version.
<cfquery name = "query_data_sample" dbtype="query">
SELECT
SAMPLE_DATE
, SAMPLE_NBR
, SAMPLE_MISC_NBR
, SUM (RECD_QTY) AS TTL_RECD_QTY
, SUM (MISC_QTY_1) AS TTL_MISC_QTY_1
, SUM ( 1 ) AS TTL_COUNT
FROM original_query_result
WHERE 1=1
AND SAMPLE_DATE = <cfqueryparam value = "#original_query_result.SAMPLE_DATE#" cfsqltype = "CF_SQL_DATE">
AND SAMPLE_NBR = <cfqueryparam value = "#trim(original_query_result.SAMPLE_NBR)#" cfsqltype = "CF_SQL_CHAR">
AND SAMPLE_MISC_NBR = <cfqueryparam value = "#trim(original_query_result.SAMPLE_MISC_NBR)#" cfsqltype = "CF_SQL_CHAR">
GROUP BY
SAMPLE_DATE
, SAMPLE_NBR
, SAMPLE_MISC_NBR
</cfquery>
When I comment out the AND statements and dump out the above query I can see the output of the original_query_result with all the TTL values and Sample rows. However if I want to grab just one row with the AND statements then the query comes back as not finding the row. I am doing a cfoutput query = original_query_result and trying to get the total quantity to display on each row in my output grid table.
Any help would be greatly appreciated. I have been trying to figure this out for more then a week now.
I saw something similar a while back and found this post:
https://web.archive.org/web/20180210052449/http://blog.dkferguson.com/index.cfm/2010/2/17/Using-Querie-of-Queries-with-CFDirectory
Basically I had to CAST the date and use cfqueryparam (as you are):
SAMPLE_DATE = CAST(<cfqueryparam value="#original_query_result.SAMPLE_DATE#" cfsqltype="CF_SQL_DATE"> AS date)
The post said they had to cast both sides but I didn't find this.
I am using Taffy framework for creating api endpoints. In one of my endpoint I need to display time in particular format say hh:mm:ss, I used timeformat method in CFC file to get the desired result, but when I hit the endpoint I am getting January, 01 1970 17:00:00. Any suggestions?
Note:For field "clientHoursOfOperationOpenTime" Time value is returned from Mysql, I am querying the DB in CFC file and formatting the clientHoursOfOperationOpenTimevalue.
<cfset var getLocationHours = QueryNew('') >
<cfquery name="getLocationHours" datasource="#appSettings.DSN#">
Select some fields here
</cfquery>
<cfset getLocationHours.clientHoursOfOperationOpenTime= "#timeFormat(getLocationHours.clientHoursOfOperationOpenTime, 'hh:mm:ss')#">
<cfreturn getLocationHours >
When I dump this field getLocationHours.clientHoursOfOperationOpenTime I am getting the formatted value. But when I use taffy, I am getting the format issue.
I am creating a new query object with
<cfset LOCAL.Query = QueryNew( "" ) />
I am then building up a complicated data set from an array that was passed in.
My query object looks perfect.
How do I then add the SQL text and datasource to the query so that I can execute it?
I am going to be inserting the data using a passed in datasource and insert statement.
If I'm understanding you correctly, in order to use SQL and retrieve data from your query object you will use CFQUERY. Instead of a 'datasource' attribute you will use 'dbtype="query"'. The table name of the query will be your query object. For example:
<cfquery dbtype="query" name="myQry">
SELECT * FROM LOCAL.Query
</cfquery>
You cannot add new records with an INSERT statement. You must use the function: QUERYADDROW() and, possibly, QUERYSETCELL().
For instance, :
<cfset queryAddRow(LOCAL.Query, {"id"=1,"title"="Hello world"})>
Or:
<cfset queryAddRow(LOCAL.Query)>
<cfset querySetCell(LOCAL.Query, "id", "1")>
<cfset querySetCell(LOCAL.Query, "title", "Hello world")>
Dan answered the question for me.
I was hoping to be able to modify the query object and add the datasource and SQL but after much study I was unable to do so.
The correct answer is DanĀ“s comment about a new query object.
I am moving one of our applications from ColdFusion 9.01 to ColdFusion 11 and encountered a situation where I cannot get the date formatted the way I want it using "DateFormat". I read through the docs since things have changed in CF versions, but I honestly can't figure out why this isn't working. It worked beautifully in CF 9. I know it's probably something very easy, but I am just not seeing it.
The query (Oracle DB) provides me a list of the last 30 days and the loop is simply to reformat the date output from "2014-07-01 00:00:00.0" to a more friendly looking display of 01-Jul-2014 except that I cannot get it to format as "dd-mmm-yyyy" it just spits back the original output from the query. I hard coded the date where normally there would be a cfquerparam. Any ideas?
<cfquery name="qryDateArray" datasource="#request.db#">
select trunc(to_date('07/01/2014', 'mm/dd/yyyy') + 1 - rownum) as ref_date
from dual connect by rownum <= 30
</cfquery>
<cfloop from="1" to="#qryDateArray.recordcount#" index="j">
<cfset qryDateArray.ref_date[j] = DateFormat(qryDateArray.ref_date[j], "dd-mmm-yyyy")>
</cfloop>
<cfoutput>
<cfdump var="#qryDateArray#">
</cfoutput>
I could not test this on CF11 since I do not have it handy. I did verify that your code though returns results as you explained when I ran it on my CF10 environment here. So what you can do is add a column to the query object and define it as a varchar and add your formatted data to that. This in turn dumped out the formatted dates.
<cfquery name="qryDateArray" datasource="#request.db#">
select trunc(to_date('07/01/2014', 'mm/dd/yyyy') + 1 - rownum) as ref_date
from dual connect by rownum <= 30
</cfquery>
<cfset aryData = [] />
<cfloop from="1" to="#qryDateArray.recordcount#" index="j">
<cfset ArrayAppend(aryData, DateFormat(qryDateArray.ref_date[j], "dd-mmm-yyyy")) />
</cfloop>
<cfset QueryAddColumn(qryDateArray, "STRDATE", "VarChar", aryData) />
<cfoutput>
<cfdump var="#qryDateArray#">
</cfoutput>
If dependent on the query column names then could use something like Ben's method explained here to do some renaming of the columns: http://www.bennadel.com/blog/357-ask-ben-changing-coldfusion-query-column-names.htm
It'd be great if you'd given us a portable test case rather than one that relies on your database, but I suspect it is because ColdFusion has become more rigid with its type management of query columns.
So CF considers your ref_date column to be of type date, so when you try to put the formatted string back into the query column, CF tries (and succeeds) to convert the string back into a date.
Aside:
I have to wonder why you don't format the data string in the DB from the outset, and just return it the way you need it, rather than returning something else, then looping over the thing to adjust it..?
I am trying to retrieve CLOB data from our Oracle database. the code is the following:
<cfstoredproc datasource="#request.site.datasource#" procedure="GETPAGESWITHMETADATA" result="myResults">
<cfprocparam cfsqltype="CF_SQL_VARCHAR" type="in" value="News">
<cfprocparam cfsqltype="CF_SQL_VARCHAR" type="in" value="News Pages">
<cfprocparam cfsqltype="CF_SQL_CLOB" type="out" variable="XML">
<cfprocresult name="rs1">
</cfstoredproc>
<cfdump var="#myResults#">
<cfoutput>#XML#</cfoutput>
<cfcatch type="any">
<cfdump var="#cfcatch#">
</cfcatch>
</cftry>
Basically, the output of the stored procedure is:
select dbms_xmlquery.getxml(queryCtx) INTO XML from dual;
I checked the data sources on the server and the "Enable long text retrieval (CLOB)." option is checked for every data source.
Surprisingly, instead of getting the XML result on screen, I get a very short string:
[C#74897f5e
It looks like a handle id instead of the content itself.
How can I retrieve the complete content of the XML?
For reference, the data source is using macromedia drivers with TNS name:
Driver class: macromedia.jdbc.MacromediaDriver
As #MarkAKruger suggested, returning a table from the procedure solved the issue.
The following PL/SQL code did the trick:
create or replace
PACKAGE PCK_Commonspot
AS
type t_clob IS record (metadata CLOB) ;
type t_clob_tab IS TABLE OF t_clob;
FUNCTION GetPagesWithMetadataAsRS(FormName varchar2, CategoryName varchar2)
RETURN t_clob_tab pipelined;
END PCK_Commonspot;
The package body contains the following code:
FUNCTION GetPagesWithMetadataAsRS(FormName varchar2, CategoryName varchar2)
RETURN t_clob_tab pipelined
IS
r t_clob;
BEGIN
GETPAGESWITHMETADATA(FormName, CategoryName, r.metadata) ;
pipe row(r) ;
RETURN;
END;
The function GETPAGESWITHMETADATA is the one returning a CLOB into r.metadata
Here, the trick is around returning a piped table.
It becomes super nice on the ColdFusion side because the call is really simple:
<cfquery name="Test" datasource="myDS" maxrows="1">
SELECT * FROM TABLE(PCK_Commonspot.GetPagesWithMetadataAsRS('abc','def'))
</cfquery>
<cfset XML = Xmlparse(Test.Metadata)>
Thanks Mark!
Check your datasource settings in the CF Administrator. Under the advanced settings, there are check boxes to allow BLOB and CLOB data to be returned. If they are unchecked you potentially could get truncated data returned in your queries
Even though Jaepetto has already answered his question, I thought I'd contribute another answer for posterity.
I was having similar problems returning CLOB data into CF8 from Oracle 11g. The original solution (that wasn't working) was roughly:
<cfquery name="GetDoc" DATASOURCE=myDS>
SELECT CLOBDATA FROM FILES WHERE FILES.FILEID = #FileID#
</cfquery>
This query would complete successfully, but GetDoc.CLOBDATA would always be an empty string. It turned out that retrieving CLOB data using cfquery would always do this, but if I wrapped it up in a stored proc then it worked. I assume this is some quirk of the JDBC drivers we're using.
Anyway, the CF guts of my solution was as follows. Note the use of CF_SQL_LONGVARCHAR instead of CF_SQL_CLOB - using CF_SQL_CLOB gave me the weird handle ID value that Jaepetto was seeing.
<cfstoredproc PROCEDURE="GETCLOB" DATASOURCE=myDS >
<CFPROCPARAM TYPE="IN" CFSQLTYPE="CF_SQL_INTEGER" DBVARNAME="pFileID" value="#fileID#"/>
<CFPROCPARAM TYPE="OUT" CFSQLTYPE="CF_SQL_LONGVARCHAR" DBVARNAME="pClob" VARIABLE="vClob" />
</cfstoredproc>
<!--- Dump the clob to the local filesystem --->
<cfscript>
fstream = CreateObject("java", "java.io.FileOutputStream").init(filepath, JavaCast("boolean","true"));
outStream = CreateObject("java", "java.io.BufferedOutputStream").init(fstream);
outStream.write(#toBinary(vClob)#);
outStream.flush();
outStream.close();
</cfscript>