ISSUE with ColdFusion TRANSACTION and Data Concurrency - coldfusion

I am creating and assigning a value in a variable at the top of the function. But somehow the value gets replaced with other user's table record. This happened when two users doing transaction at same time with different records. Also it is happening only once in a while.
I have mentioned the issue in comments in below code.
<cffunction name="functionname" output="true">
<cfargument name="formData">
<cftransaction action="begin">
<cftry>
<cfquery name="getDoc_no" datasource="#variables.dsn#">
SELECT CONCAT(TO_CHAR(SYSDATE,'YYYY'),WORK_REQ_SEQ.NEXTVAL) as NEXT_NO FROM DUAL
</cfquery>
<cfset doc_no_seq=getDoc_no.NEXT_NO> <!---creating variable doc_no_seq --->
<cfquery name="getWo_no" datasource="#variables.dsn#">
SELECT WORK_ORDER_SEQ.nextval as NEXT_NO FROM DUAL
</cfquery>
<cfset Trns_seq=getWo_no.NEXT_NO> <!--- creating variable Trns_seq --->
<cfquery name="insert1" datasource="#variables.dsn#">
INSERT into WORK_ORDER
(
DOC_NO,
TRANS_ID
)
Values
(
<cfqueryparam value="#doc_no_seq#" cfsqltype="cf_sql_integer">, <!--- Inserted CORRECT doc_no_seq value --->
<cfqueryparam value="#Trns_seq#" cfsqltype="cf_sql_integer"> <!--- Inserted CORRECT Trns_seq value --->
)
</cfquery>
<cfif isdefined("IdnoRes") and IdnoRes gt 0>
<cfloop from="1" to="#IdnoRes#" index="q">
<cfif trim(Evaluate("rsc_grp_id_#q#")) is not "" and trim(Evaluate("qty_#q#")) is not "">
<cfquery name="insert2" datasource="#variables.dsn#">
INSERT into REQ_RESOURCE_DTLS
(
DOC_NO ,
TRANS_ID
)
Values
(
<cfqueryparam value="#doc_no_seq#" cfsqltype="cf_sql_integer">, <!--- Inserted WRONG doc_no_seq value --->
<cfqueryparam value="#Trns_seq#" cfsqltype="cf_sql_integer"> <!--- Inserted WRONG Trns_seq value --->
)
</cfquery>
</cfif>
</cfloop>
</cfif>
<cfif isdefined("Idnojob") and Idnojob gt 0>
<cfloop from="1" to="#Idnojob#" index="q">
<cfif trim(Evaluate("frm_des_#q#")) is not "" and trim(Evaluate("to_des_#q#")) is not "">
<cfquery name="insert3" datasource="#variables.dsn#">
INSERT into JOB_SEQ_DTLS
(
DOC_NO ,
TRANS_ID
)
Values
(
<cfqueryparam value="#doc_no_seq#" cfsqltype="cf_sql_integer">, <!--- Inserted WRONG doc_no_seq value --->
<cfqueryparam value="#Trns_seq#" cfsqltype="cf_sql_integer"> <!--- Inserted WRONG Trns_seq value --->
)
</cfquery>
</cfif>
</cfloop>
</cfif>
<cftransaction action="commit" />
<cfcatch type="any">
<cftransaction action="rollback" />
</cfcatch>
</cftry>
</cftransaction>
<cfreturn 1>

Related

How to handle accents characters in Spanish websites in Mura

The issue I am encountering is when a user is on the Spanish website, they are not able to see all results if their type the word incorrectly. Meaning, if their character does not have the accent above the character, the results will show blank.
For example, if the user types the word "Medico" without the accent on top of the "é", the search will return blank.
I am using a Mura, a CMS which the search is created. I was able to locate the function where it does search based on the user input. However, I am not able to clearly understand how the query is being implemented.
I am trying to modify the function so that it uses the collation, which I found an example on how to use on stackoverflow, which would handle the accents for Spanish or any other language(s).
I figure it should go after "where" and have a cfif statement where if it is the spanish site, to incorporate the collation.
<cfif #siteID# = "SpanishSite" />
//here would go the collation on keywords, titles, etc.
Note that the query is done in coldfusion:
<cffunction name="getPublicSearch" returntype="query" access="public" output="false">
<cfargument name="siteid" type="string" required="true">
<cfargument name="keywords" type="string" required="true">
<cfargument name="tag" type="string" required="true" default="">
<cfargument name="sectionID" type="string" required="true" default="">
<cfargument name="categoryID" type="string" required="true" default="">
<cfargument name="tagGroup" type="string" required="true" default="">
<cfset var rsPublicSearch = "">
<cfset var w = "">
<cfset var c = "">
<cfset var categoryListLen=listLen(arguments.categoryID)>
<cfquery attributeCollection="#variables.configBean.getReadOnlyQRYAttrs(name='rsPublicSearch',maxrows=1000)#">
<!--- Find direct matches with no releasedate --->
select tcontent.contentid,tcontent.contenthistid,tcontent.siteid,tcontent.title,tcontent.menutitle,tcontent.targetParams,tcontent.filename,tcontent.summary,tcontent.tags,
tcontent.restricted,tcontent.releaseDate,tcontent.type,tcontent.subType,
tcontent.restrictgroups,tcontent.target ,tcontent.displaystart,tcontent.displaystop,0 as Comments,
tcontent.credits, tcontent.remoteSource, tcontent.remoteSourceURL,
tcontent.remoteURL,tfiles.fileSize,tfiles.fileExt,tcontent.fileID,tcontent.audience,tcontent.keyPoints,
tcontentstats.rating,tcontentstats.totalVotes,tcontentstats.downVotes,tcontentstats.upVotes, 0 as kids,
tparent.type parentType,tcontent.nextn,tcontent.path,tcontent.orderno,tcontent.lastupdate, tcontent.created,
tcontent.created sortdate, 0 priority,tcontent.majorVersion, tcontent.minorVersion, tcontentstats.lockID, tcontentstats.lockType,
tcontent.expires,tfiles.filename as assocFilename, tcontentfilemetadata.altText as fileAltText,
CASE WHEN tcontent.title = <cfqueryparam cfsqltype="cf_sql_varchar" value="#renderTextParamValue(arguments.keywords)#">
or tcontent.menuTitle = <cfqueryparam cfsqltype="cf_sql_varchar" value="#renderTextParamValue(arguments.keywords)#"> THEN 0 ELSE 1 END AS superSort
from tcontent Left Join tfiles ON (tcontent.fileID=tfiles.fileID)
Left Join tcontent tparent on (tcontent.parentid=tparent.contentid
and tcontent.siteid=tparent.siteid
and tparent.active=1)
Left Join tcontentstats on (tcontent.contentid=tcontentstats.contentid
and tcontent.siteid=tcontentstats.siteid)
Left Join tcontentfilemetadata on (tcontent.fileid=tcontentfilemetadata.fileid
and tcontent.contenthistid=tcontentfilemetadata.contenthistid)
<cfif len(arguments.tag)>
Inner Join tcontenttags on (tcontent.contentHistID=tcontenttags.contentHistID)
</cfif>
where
(tcontent.Active = 1
AND tcontent.Approved = 1
AND tcontent.siteid = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.siteID#"/> )
AND
(
tcontent.Display = 2
AND
(
(tcontent.DisplayStart <= <cfqueryparam cfsqltype="cf_sql_timestamp" value="#now()#">
AND (tcontent.DisplayStop >= <cfqueryparam cfsqltype="cf_sql_timestamp" value="#now()#"> or tcontent.DisplayStop is null)
)
OR tparent.type='Calendar'
)
OR tcontent.Display = 1
)
AND
tcontent.type in ('Page','Folder','Calendar','File','Link','Gallery')
AND tcontent.releaseDate is null
<cfif len(arguments.sectionID)>
and tcontent.path like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#arguments.sectionID#%">
</cfif>
<cfif len(arguments.tag)>
and (
#renderTextParamColumn('tcontenttags.tag')# in (<cfqueryparam list="true" cfsqltype="cf_sql_varchar" value="#renderTextParamValue(arguments.tag)#"/> )
<cfif len(arguments.tagGroup) and arguments.tagGroup neq 'default'>
and #renderTextParamColumn('tcontenttags.taggroup')#=<cfqueryparam cfsqltype="cf_sql_varchar" value="#renderTextParamValue(arguments.taggroup)#"/>
</cfif>
)
<cfelse>
<!---
<cfloop list="#trim(arguments.keywords)#" index="w" delimiters=" ">
and
(tcontent.Title like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#w#%">
or tcontent.menuTitle like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#w#%">
or tcontent.metaKeywords like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#w#%">
or tcontent.summary like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#w#%">
or tcontent.body like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#w#%">)
</cfloop>
--->
and
(#renderTextParamColumn('tcontent.Title')# like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#renderTextParamValue(arguments.keywords)#%">
or #renderTextParamColumn('tcontent.menuTitle')# like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#renderTextParamValue(arguments.keywords)#%">
or #renderTextParamColumn('tcontent.metaKeywords')# like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#renderTextParamValue(arguments.keywords)#%">
or #renderTextParamColumn('tcontent.summary')# like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#renderTextParamValue(arguments.keywords)#%">
or (
tcontent.type not in ('Link','File')
and #renderTextParamColumn('tcontent.body')# like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#renderTextParamValue(arguments.keywords)#%">
)
or #renderTextParamColumn('tcontent.credits')# like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#renderTextParamValue(arguments.keywords)#%">
or tcontent.contenthistid in (
select distinct tcontent.contenthistid from tclassextenddata
inner join tcontent on (tclassextenddata.baseid=tcontent.contenthistid)
where tcontent.active=1
and tcontent.siteid=<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.siteID#"/>
and #renderTextParamColumn('tclassextenddata.attributeValue')# like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#renderTextParamValue(arguments.keywords)#%">
))
</cfif>
and tcontent.searchExclude=0
<cfif categoryListLen>
and tcontent.contentHistID in (
select tcontentcategoryassign.contentHistID from
tcontentcategoryassign
inner join tcontentcategories
ON (tcontentcategoryassign.categoryID=tcontentcategories.categoryID)
where (<cfloop from="1" to="#categoryListLen#" index="c">
tcontentcategories.path like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#listgetat(arguments.categoryID,c)#%"/>
<cfif c lt categoryListLen> or </cfif>
</cfloop>)
)
</cfif>
#renderMobileClause()#
union all
<!--- Find direct matches with releasedate --->
select tcontent.contentid,tcontent.contenthistid,tcontent.siteid,tcontent.title,tcontent.menutitle,tcontent.targetParams,tcontent.filename,tcontent.summary,tcontent.tags,
tcontent.restricted,tcontent.releaseDate,tcontent.type,tcontent.subType,
tcontent.restrictgroups,tcontent.target ,tcontent.displaystart,tcontent.displaystop,0 as Comments,
tcontent.credits, tcontent.remoteSource, tcontent.remoteSourceURL,
tcontent.remoteURL,tfiles.fileSize,tfiles.fileExt,tcontent.fileID,tcontent.audience,tcontent.keyPoints,
tcontentstats.rating,tcontentstats.totalVotes,tcontentstats.downVotes,tcontentstats.upVotes, 0 as kids,
tparent.type parentType,tcontent.nextn,tcontent.path,tcontent.orderno,tcontent.lastupdate, tcontent.created,
tcontent.releaseDate sortdate, 0 priority,tcontent.majorVersion, tcontent.minorVersion, tcontentstats.lockID, tcontentstats.lockType,
tcontent.expires,tfiles.filename as assocFilename, tcontentfilemetadata.altText as fileAltText,
CASE WHEN tcontent.title = <cfqueryparam cfsqltype="cf_sql_varchar" value="#renderTextParamValue(arguments.keywords)#">
or tcontent.menuTitle = <cfqueryparam cfsqltype="cf_sql_varchar" value="#renderTextParamValue(arguments.keywords)#"> THEN 0 ELSE 1 END AS superSort
from tcontent Left Join tfiles ON (tcontent.fileID=tfiles.fileID)
Left Join tcontent tparent on (tcontent.parentid=tparent.contentid
and tcontent.siteid=tparent.siteid
and tparent.active=1)
Left Join tcontentstats on (tcontent.contentid=tcontentstats.contentid
and tcontent.siteid=tcontentstats.siteid)
Left Join tcontentfilemetadata on (tcontent.fileid=tcontentfilemetadata.fileid
and tcontent.contenthistid=tcontentfilemetadata.contenthistid)
<cfif len(arguments.tag)>
Inner Join tcontenttags on (tcontent.contentHistID=tcontenttags.contentHistID)
</cfif>
where
(tcontent.Active = 1
AND tcontent.Approved = 1
AND tcontent.siteid = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.siteID#"/> )
AND
(
tcontent.Display = 2
AND
(
(tcontent.DisplayStart <= <cfqueryparam cfsqltype="cf_sql_timestamp" value="#now()#">
AND (tcontent.DisplayStop >= <cfqueryparam cfsqltype="cf_sql_timestamp" value="#now()#"> or tcontent.DisplayStop is null)
)
OR tparent.type='Calendar'
)
OR tcontent.Display = 1
)
AND
tcontent.type in ('Page','Folder','Calendar','File','Link','Gallery')
AND tcontent.releaseDate is not null
<cfif len(arguments.sectionID)>
and tcontent.path like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#arguments.sectionID#%">
</cfif>
<cfif len(arguments.tag)>
and (
#renderTextParamColumn('tcontenttags.tag')# in (<cfqueryparam list="true" cfsqltype="cf_sql_varchar" value="#renderTextParamValue(arguments.tag)#"/> )
<cfif len(arguments.tagGroup) and arguments.tagGroup neq 'default'>
and #renderTextParamColumn('tcontenttags.taggroup')#=<cfqueryparam cfsqltype="cf_sql_varchar" value="#renderTextParamValue(arguments.taggroup)#"/>
</cfif>
)
<cfelse>
<!---
<cfloop list="#trim(arguments.keywords)#" index="w" delimiters=" ">
and
(tcontent.Title like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#w#%">
or tcontent.menuTitle like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#w#%">
or tcontent.metaKeywords like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#w#%">
or tcontent.summary like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#w#%">
or tcontent.body like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#w#%">)
</cfloop>
--->
and
(#renderTextParamColumn('tcontent.Title')# like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#renderTextParamValue(arguments.keywords)#%">
or #renderTextParamColumn('tcontent.menuTitle')# like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#renderTextParamValue(arguments.keywords)#%">
or #renderTextParamColumn('tcontent.metaKeywords')# like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#renderTextParamValue(arguments.keywords)#%">
or #renderTextParamColumn('tcontent.summary')# like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#renderTextParamValue(arguments.keywords)#%">
or
(
tcontent.type not in ('Link','File')
and #renderTextParamColumn('tcontent.body')# like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#renderTextParamValue(arguments.keywords)#%">
)
or #renderTextParamColumn('tcontent.credits')# like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#renderTextParamValue(arguments.keywords)#%">
or tcontent.contenthistid in (
select distinct tcontent.contenthistid from tclassextenddata
inner join tcontent on (tclassextenddata.baseid=tcontent.contenthistid)
where tcontent.active=1
and tcontent.siteid=<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.siteID#"/>
and #renderTextParamColumn('tclassextenddata.attributeValue')# like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#renderTextParamValue(arguments.keywords)#%">
))
</cfif>
and tcontent.searchExclude=0
<cfif categoryListLen>
and tcontent.contentHistID in (
select tcontentcategoryassign.contentHistID from
tcontentcategoryassign
inner join tcontentcategories
ON (tcontentcategoryassign.categoryID=tcontentcategories.categoryID)
where (<cfloop from="1" to="#categoryListLen#" index="c">
tcontentcategories.path like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#listgetat(arguments.categoryID,c)#%"/>
<cfif c lt categoryListLen> or </cfif>
</cfloop>)
)
</cfif>
#renderMobileClause()#
ORDER BY supersort, priority, <cfif variables.configBean.getDBType() neq 'nuodb'>sortdate<cfelse>releasedate</cfif> desc
</cfquery>
<cfreturn rsPublicSearch />
My question is: Where should the collation go in the query above? Or is there a better approach than using collation in the query?
Or should I reach out to Mura and see if a new framework would need to be implemented to achieve what I am looking for?
Any help is appreciated
To expand on my comment.
const userInput = 'Médico';
const parsedInput = userInput.replace(/é/gmi, 'e').toLowerCase();
Then you take the that and store it in the database, so if the user searches for medico, Medico, MEDIcO, or any variant of that then it'll always be available to retrieve it from the database.
I can also write this in Spanish if it's easier for you to understand, but SO guidelines prefer English.
Here's a StackBlitz to kind of show you what I mean.

notify a user if there are no matching records found - coldfusion

How do you create something to notify a user if there are no matching records found with the queries you run?
I have a queries.cfm that I run like this:
<cfset result = {} />
<cftry>
<cfset date1 = CREATEODBCDATETIME(form.StartDate & '00:00:00')>
<cfset date2 = CREATEODBCDATETIME(form.EndDate & '23:59:59')>
<cfquery datasource="#application.dsn#" name="GetEmployeeInfo">
SELECT trans_location, date, associate
FROM cl_checklists
WHERE date >= <cfqueryparam value="#date1#" cfsqltype="cf_sql_timestamp" />
AND date <= <cfqueryparam value="#date2#" cfsqltype="cf_sql_timestamp" />
AND trans_location IN ( <cfqueryparam value="#FORM.location#" cfsqltype="cf_sql_varchar" list="true" /> )
AND associate IN ( <cfqueryparam value="#FORM.EmployeeName#" cfsqltype="cf_sql_varchar" list="true" /> )
</cfquery>
<cfquery datasource="#application.dsn#" name="GetLocationInfo">
SELECT trans_location, date, associate
FROM cl_checklists
WHERE date >= <cfqueryparam value="#date1#" cfsqltype="cf_sql_timestamp" />
AND date <= <cfqueryparam value="#date2#" cfsqltype="cf_sql_timestamp" />
AND trans_location IN ( <cfqueryparam value="#FORM.location#" cfsqltype="cf_sql_varchar" list="true" /> )
</cfquery>
<cffunction name="getop_id" access="public" returntype="string">
<cfargument name="associate" >
<cfquery name="spitOutop_id" datasource="#application.userinfo_dsn#">
SELECT assoc_name
FROM dbo.tco_associates
WHERE assoc_id= #arguments.associate#
</cfquery>
<cfreturn spitOutop_id.assoc_name >
</cffunction>
<cfquery name="allAssociatesQry" dbtype="query">
SELECT DISTINCT associate, COUNT(*) AS associateCount FROM GetEmployeeInfo GROUP BY associate ORDER BY associate
</cfquery>
<table border="1" id="Checklist_Stats">
<thead>
<th><strong>Associate Name</strong></th>
<th><strong>Location</strong></th>
<th><strong>Checklists Generated by Associate</strong></th>
<th><strong>Checklists Generated by Selected Location(s)</strong></th>
<th><strong>Associate Percentage of Location Total</strong></th>
</thead>
<tbody>
<!--- aggregate variables --->
<cfset aggrAssociateChecklist = 0>
<cfset aggrLocationChecklist = 0>
<cfloop query="allAssociatesQry">
<!--- get Associate's name --->
<cfset thisAssociateCode = trim(allAssociatesQry.associate)>
<cfset thisAssociateName = getop_id(thisAssociateCode) />
<!--- 1.1 get all trans_location code and total counts for the current Associate --->
<cfquery name="allLocCodeForAssociateQry" dbtype="query">
SELECT trans_location,count(trans_location) AS locCntr FROM GetEmployeeInfo WHERE associate='#thisAssociateCode#' GROUP BY trans_location ORDER BY trans_location
</cfquery>
<!--- 1.2 get the aggregate of checklist count generated by the current Associate for each location --->
<cfquery name="qTotalChecklistCountForAssociate" dbtype="query">
SELECT SUM(locCntr) AS totalAssocChecklist FROM allLocCodeForAssociateQry
</cfquery>
<!--- 2.1 get the total location checklist for each location available for the current Associate --->
<cfquery name="allLocChecklistForAssociateQry" dbtype="query">
SELECT trans_location,count(trans_location) AS totalLocCount FROM GetLocationInfo WHERE trans_location IN (#QuotedValueList(allLocCodeForAssociateQry.trans_location)#) GROUP BY trans_location ORDER BY trans_location
</cfquery>
<!--- 2.2 get the aggregate of location checklist generated by the current Associate --->
<cfquery name="qTotalLocChecklistForAssociate" dbtype="query">
SELECT SUM(totalLocCount) AS totalLocChecklist FROM allLocChecklistForAssociateQry
</cfquery>
<!--- display record for the current Associate --->
<cfoutput query="allLocCodeForAssociateQry">
<tr>
<!---<td><strong>#thisAssociateCode#</strong></td>--->
<td><strong>#thisAssociateName#</strong></td>
<td>#allLocCodeForAssociateQry.trans_location#</td>
<td>#allLocCodeForAssociateQry.locCntr#</td>
<td>#allLocChecklistForAssociateQry['totalLocCount'][CurrentRow]#</td>
<td>#NumberFormat((allLocCodeForAssociateQry.locCntr/allLocChecklistForAssociateQry['totalLocCount'][CurrentRow]) * 100, '9.99')#%</td>
</tr>
<cfset thisAssociateName = "" />
</cfoutput>
<!--- 3.1 get sub total for each Associate group --->
<cfset totalAssocChecklist = qTotalChecklistCountForAssociate.totalAssocChecklist>
<cfset totalLocChecklist = qTotalLocChecklistForAssociate.totalLocChecklist>
<!--- 3.2 add to the aggregate --->
<cfset aggrAssociateChecklist += totalAssocChecklist>
<cfset aggrLocationChecklist += totalLocChecklist>
<!--- display sub total for each Associate group --->
<cfoutput>
<tr>
<td>Associate Total</td>
<td></td>
<td>#totalAssocChecklist#</td>
<td>#totalLocChecklist#</td>
<td>#NumberFormat((totalAssocChecklist/totalLocChecklist) * 100, '9.99')#%</td>
</tr>
</cfoutput>
</cfloop>
<!--- display calculated aggregate at the end of the result --->
<!--- <cfoutput>
<tr>
<td><strong>Total</strong></td>
<td></td>
<td>#aggrAssociateChecklist#</td>
<td>#aggrLocationChecklist#</td>
<td>#NumberFormat((aggrAssociateChecklist/aggrLocationChecklist) * 100, '9.99')#%</td>
</tr>
</cfoutput>--->
</tbody>
</table>
<cfcatch type="any">
<cfset result.error = CFCATCH.message >
<cfset result.detail = CFCATCH.detail >
</cfcatch>
</cftry>
But I am trying to notify the user when no results come back based on there search.
I was trying to do a catch for the results if there 0 do something but have been unsuccessful. Would any Cold Fusion gurus like to assist me in how you alert your users when there query came back empty.
I tried:
<cfif #allAssociatesQry# is 0>
<cfif #allAssociatesQry# is null>
<cfif #allAssociatesQry# is "">
<cfif allAssociatesQry is 0>
<cfif allAssociatesQry is null>
<cfif allAssociatesQry is "">
Don't use try/catch. That's for code that doesn't run successfully. All you need is this:
<cfquery name="q">
sql
</cfquery>
<cfif q.recordcount is 0>
code for no records
<cfelse>
display records
</cfif>

Database entry cfqueryparam dynamic session variable value

How do you create a cfqueryparam for a dynamic variable? How do I write the value for something like this..
Dynamic Session Variables:
<cfset session.checkout.info["firstname_#Add#"]=form["firstname_#Add#"]>
<cfset session.checkout.info["middlename_#Add#"]=form["middlename_#Add#"]>
<cfset session.checkout.info["lastname_#Add#"]=form["lastname_#Add#"]>
Database Entry:
<cfquery datasource="Titlesbymail" name="InsertEntry">
INSERT INTO owner (firstname, middlename, lastname)
VALUES (<cfqueryparam value="#session.checkout.info.firstname#" cfsqltype="CF_SQL_VARCHAR">
<cfqueryparam value="#session.checkout.info.middlename#" cfsqltype="CF_SQL_VARCHAR">,
<cfqueryparam value="#session.checkout.info.lastname#" cfsqltype="CF_SQL_VARCHAR">
</cfquery>
I believe you just do it like this :
<cfloop index="Add" from="1" to="#session.checkout.quantity.pcount#" step="1">
<cfif structKeyExists(session, "checkout")>
<cfquery datasource="Titlesbymail" name="InsertEntry">
INSERT INTO owner (firstname, middlename, lastname)
VALUES (
<cfqueryparam value='#form["firstname_#Add#"]#' cfsqltype='cf_sql_varchar' />
, <cfqueryparam value='#form["middlename_#Add#"]#' cfsqltype='cf_sql_varchar' />
, <cfqueryparam value='#form["lastname_#Add#"]#' cfsqltype='cf_sql_varchar' />
</cfquery>
</cfif>
</cfloop>

getting same error on different circumstances

Please consider the code below:
I am getting JSON data based on the date range I am specifying on the url & I am deserializing it as folows:
<cfhttp url="#urladdress#" method="GET" resolveurl="Yes" throwonerror="Yes">
<cfset cfData=DeserializeJSON(CFHTTP.FileContent)>
<cfset arraylen = ArrayLen(cfdata)>
I am grabbing the data and inserting into MySQL database as follows:
<cfquery datasource="XX.X.XX.XXX" name="qCoulmnInsert">
INSERT INTO Mytable
(aol_int,
android_Phone_int,
androidTablet_int,
apple_mail_int,
blackberry_int,
Eudora_int,
gMail_int,
Hotmail_int,
lotus_notes_int,
other_int,
other_webmail_int,
Outlook_int,
Postbox_int,
sparrow_int,
thunderbird_int,
windowsLiveMail_int,
yahoo_int,
iPad_int,
iphone_int,
iPod_int,
<!--- FOR DATES --->
startdate_dt,
enddate_dt,
date_dt)
VALUES
<!--- loop through your array --->
<cfloop from="1" to="#arrayLen(cfData)#" index="i">
( <!--- 1 --->
<cfif structKeyExists(cfData[i], "open")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i]["open"]["aol"]#">
<cfelse>
NULL
</cfif>,
<!--- 2 --->
<cfif structKeyExists(cfData[i], "open")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i]["open"]["Android Phone"]#">
<cfelse>
NULL
</cfif>,
<!--- 3 --->
<cfif structKeyExists(cfData[i], "open")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i]["open"]["Android Tablet"]#">
<cfelse>
NULL
</cfif>,
<!--- 4 --->
<cfif structKeyExists(cfData[i], "open")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i]["open"]["Apple Mail"]#">
<cfelse>
NULL
</cfif>,
<!--- 5 --->
<cfif structKeyExists(cfData[i], "open")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i]["open"]["Blackberry"]#">
<cfelse>
NULL
</cfif>,
<!--- 6 --->
<cfif structKeyExists(cfData[i], "open")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i]["open"]["Eudora"]#">
<cfelse>
NULL
</cfif>,
<!--- 7 --->
<cfif structKeyExists(cfData[i], "open")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i]["open"]["gmail"]#">
<cfelse>
NULL
</cfif>,
<!--- 8 --->
<cfif structKeyExists(cfData[i], "open")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i]["open"]["hotmail"]#">
<cfelse>
NULL
</cfif>,
<!--- 9 --->
<cfif structKeyExists(cfData[i], "open")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i]["open"]["Lotus Notes"]#">
<cfelse>
NULL
</cfif>,
<!--- 10 --->
<cfif structKeyExists(cfData[i], "open")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i]["open"]["Other"]#">
<cfelse>
NULL
</cfif> ,
<!--- 11 --->
<cfif structKeyExists(cfData[i], "open")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i]["open"]["Other Webmail"]#">
<cfelse>
NULL
</cfif>,
<!--- 12 --->
<cfif structKeyExists(cfData[i], "open")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i]["open"]["Outlook"]#">
<cfelse>
NULL
</cfif> ,
<!--- 13 --->
<cfif structKeyExists(cfData[i], "open")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i]["open"]["Postbox"]#">
<cfelse>
NULL
</cfif> ,
<!--- 14 --->
<cfif structKeyExists(cfData[i], "open")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i]["open"]["Thunderbird"]#">
<cfelse>
NULL
</cfif> ,
<!--- 15 --->
<cfif structKeyExists(cfData[i], "open")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i]["open"]["Sparrow"]#">
<cfelse>
NULL
</cfif> ,
<!--- 16 --->
<cfif structKeyExists(cfData[i], "open")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i]["open"]["Windows Live Mail"]#">
<cfelse>
NULL
</cfif> ,
<!--- 17 --->
<cfif structKeyExists(cfData[i], "open")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i]["open"]["Yahoo"]#">
<cfelse>
NULL
</cfif> ,
<!--- 18 --->
<cfif structKeyExists(cfData[i], "open")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i]["open"]["iPad"]#">
<cfelse>
NULL
</cfif> ,
<!--- 19 --->
<cfif structKeyExists(cfData[i], "open")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i]["open"]["iPhone"]#">
<cfelse>
NULL
</cfif> ,
<!--- 20 --->
<cfif structKeyExists(cfData[i], "open")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i]["open"]["iPod"]#">
<cfelse>
NULL
</cfif> ,
<!--- FOR DATES --->
<cfif structKeyExists(cfData[i], "startdate_dt")>
<cfqueryparam CFSQLTYPE="CF_SQL_DATE" value="#cfData[i].startdate_dt#">
<cfelse>
NULL
</cfif>,
<cfif structKeyExists(cfData[i], "enddate_dt")>
<cfqueryparam CFSQLTYPE="CF_SQL_DATE" value="#cfData[i].enddate_dt#">
<cfelse>
NULL
</cfif>,
<cfif structKeyExists(cfData[i], "date")>
<cfqueryparam CFSQLTYPE="CF_SQL_DATE" value="#cfData[i].date#">
<cfelse>
NULL
</cfif>
)
<cfif i neq arrayLen(cfData)>,</cfif>
</cfloop>
</cfquery>
Problem I am facing:
When the JSON data does not has "Lotus Notes" in it, I get an error "Element Lotus Notes is undefined in a CFML structure referenced as part of an expression. "
an points to the line <cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i]["open"]["Lotus Notes"]#">
When it has Lotus Notes in the JSON , it picks up some other element and I got the error "Element Eudora is undefined in a CFML structure referenced as part of an expression. "
and points to the line <cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i]["open"]["Eudora"]#"> in above code
Here is the sample JSON with Lotus Notes on date Jan 01
and here it is without Lotus Notes (from Jan 02) field where I get Eudora error
I don't understand where I am wrong. Please advise
You only need a single check for whether cfData[i].Open exists - if it doesn't all those ints are going to be null, so just output 20 nulls. (Or perhaps don't bother with the insert at all - depends what's going on here).
Also, you don't need explicit hard-coded logic for every single one - just use a loop and check the existence inside the loop with a single piece of code - i.e:
<cfif StructKeyExists(cfData[i],'open')>
<cfloop index="Key" array=#['aol','Android Phone','Android Tablet','etc']# >
,
<cfif StructKeyExists( cfData[i].open , Key ) >
<cfqueryparam value=#cfData[i].open[Key]# cfsqltype="cf_sql_integer" />
<cfelse>
<cfqueryparam value="" null=true />
</cfif>
</cfloop>
<cfelse>
#RepeatString( ',null' , 20 )#
</cfif>
I don't understand why you don't check before you reference. This is how I'd write it.
<!--- 1 --->
<cfset data = cfData[i]>
<cfset isVarDefined = isDefined("variables.data.open.aol")>
<cfset value = isVarDefined ? data.open.aol : "">
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#value#" null="#!isVarDefined#">
<!--- 2 --->
<!--- very similar to the code above... --->

Finding images not referenced in a DB table

I get a query of all the files (images) in a directory
<cfset local.teamBase = "#GetDirectoryFromPath(GetBaseTemplatePath())#teamlogo\">
<cfdirectory action="LIST" directory="#local.teamBase#" name="rc.qryTeamLogo">
I later loop over all these filenames, skipping those that are in use
<select name="Logo" <cfif deleted>disabled="disabled"</cfif>>
<option></option>
<cfloop query="rc.qryTeamLogo">
<cfif name EQ mylogo>
<option value="#name#" selected>#name#</option>
<cfelseif request.objTeam.isUsed(name) EQ 1 OR name EQ "thumbs.db">
<!--- Do not show --->
<cfelse>
<option value="#name#">#name#</option>
</cfif>
</cfloop>
</select>
The isUsed() function looks like
<cffunction name="isUsed" returntype="boolean" output="false">
<cfargument name="logo" required="true" type="string">
<cfquery name="qryUsed" datasource="#application.DSN#">
SELECT logo
FROM CCF.team
WHERE logo = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.logo#">
AND Deleted = 0
</cfquery>
<cfif qryUsed.recordcount EQ 0>
<cfreturn false>
</cfif>
<cfreturn true>
</cffunction>
The problem with this is as more and more files get added, this gets slower and slower.
What I would really like a single query that can assemble the whole thing
You can run one query before your select box
<cfquery name="qryLogos" datasource="#application.DSN#">
SELECT logo
FROM CCF.team
WHERE logo IN (<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#valueList(rc.qryTeamLogo.name)#" list="true">)
AND Deleted = 0
</cfquery>
Then set all those logo's into an array and add thumbs.db too, so you have one less check to do.
<cfset allLogs = listToArray(valueList(qryLogos.logo))>
<cfset arrayAppend(allLogs,'thumbs.db')>
and then change your elseif to this
<cfelseif arrayFind(allLogs,name)>
<!--- don't display --->
Load the file information into XML. Shread the XML into a table and JOIN on that.
<cfset local.teamBase = "#GetDirectoryFromPath(GetBaseTemplatePath())#teamlogo\">
<cfset local.qryTeamLogo = DirectoryList(local.teamBase, false, "query")>
<cfsavecontent variable="local.xmlTeamLogo">
<ul class="xoxo">
<cfoutput query="local.qryTeamLogo">
<li><code>#xmlformat(name)#</code></li>
</cfoutput>
</ul>
</cfsavecontent>
<cfquery name="local.qryResult">
DECLARE #xmlTeamLogo xml = <cfqueryparam cfsqltype="CF_SQL_varchar" value="#local.xmlTeamLogo#">
SELECT Value AS Name
FROM dbo.udfXOXORead(#xmlTeamLogo)
WHERE NOT Value IN (
SELECT Logo
FROM CCF.Team WITH (NOLOCK)
WHERE Deleted = 0
)
</cfquery>
The Table Valued Function
create function [dbo].[udfXOXORead](#xmlData xml)
returns #tblmessage TABLE (
[value] nvarchar(max) NULL
)
as
begin
INSERT INTO #tblMessage
SELECT Tbl.Col.value('(code)[1]', 'nvarchar(max)') AS [value]
FROM #xmlData.nodes('/ul/li') Tbl(Col)
RETURN
end