I'm returning 2 results from a stored proc and trying to display a logo if one of them has badgeid 2. They have a badge id column with values of 1 and 2. I'm trying to do this but it won't work:
<cfif qBadges.badgeid EQ 2>
logo here
</cfif>
If I change it to 1 it will show the old logo. 2 is a new logo I just added. Thanks!
Edit
<cfstoredproc procedure="sel_MemberBadges_p" datasource="DSN">
<cfprocparam type="In" cfsqltype="CF_SQL_INTEGER" value="#ID#">
<cfprocresult name="qBadges">
</cfstoredproc>
<cfif qBadges.badgeid EQ 2>
new logo here
<cfelseif qBadges.badgeid EQ 1>
old logo
</cfif>
Do this
<cfif qBadges.badgeid[1] EQ 2>
new logo here
<cfelseif qBadges.badgeid[2] EQ 1>
old logo
</cfif>
It is because unless you specify what row you want it will return the first one.
Try dumping out the result so you can see the badge id values:
<cfstoredproc procedure="sel_MemberBadges_p" datasource="DSN">
<cfprocparam type="In" cfsqltype="CF_SQL_INTEGER" value="#ID#">
<cfprocresult name="qBadges">
</cfstoredproc>
<cfdump var="#qBadges#" />
<cfabort />
<cfif qBadges.badgeid EQ 2>
new logo here
<cfelseif qBadges.badgeid EQ 1>
old logo
</cfif>
Related
I am trying to compare images and find if they are same or not. Images can have same name but the actual image might be different. The code that I have so far.
<cfset dirToReadFrom = #ExpandPath( '../properties-feed/unzipped/' )# />
<cfdirectory
action="list"
directory="#dirToReadFrom#"
listinfo="name"
name="qFile"
sort="asc"
filter="*.jpg"
/>
<cfset images = ArrayNew(1)>
<cfoutput query="qFile">
<cfset ArrayAppend(images, #qFile.name#)>
</cfoutput>
<cfset dirToCreate = #ExpandPath( './assets/images/resized/original/' )# />
<cfif not DirectoryExists(dirToCreate)>
<cfdirectory action = "create" directory = "#dirToCreate#" />
<cfoutput><p>Your directory has been created.</p></cfoutput>
</cfif>
<cfzip
action="unzip"
file="#ExpandPath( '../properties-feed/data.zip/' )#"
destination="#ExpandPath( './assets/images/resized/original/' )#"
overwrite="true"
/>
<cfset dirToReadFromOriginal = #ExpandPath( './assets/images/resized/original/' )# />
<cfdirectory
action="list"
directory="#dirToReadFromOriginal#"
listinfo="name"
name="qFileOriginal"
sort="asc"
filter="*.jpg"
/>
<cfset imagesLatest = ArrayNew(1)>
<cfoutput query="qFileOriginal">
<cfset ArrayAppend(imagesLatest, #qFileOriginal.name#)>
</cfoutput>
<!--- Loop over your current images --->
<cfloop query="qFileOriginal">
<!--- Check for a matching file name --->
<cfquery name="fileExists" dbtype="query">
SELECT
COUNT(*) AS num_Rec
FROM
qfile
WHERE
name = <cfqueryparam cfsqltype="cf_sql_varchar" value="#qFileOriginal.name#" />
</cfquery>
<!--- do we have a matching file name? --->
<cfif val(fileExists.num_rec)>
<cfimage action="read" name="newImage" source="#dirToReadFrom##qFile.name#"/>
<cfimage action="read" name="originalImage" source="#dirToReadFromOriginal##qFileOriginal.name#"/>
<cfset newImageBlob = ImageGetBlob(newImage) />
<cfset originalImageBlob = ImageGetBlob(originalImage) />
<!--- Compare --->
<cfif toString(newImageBlob) eq toString(originalImageBlob) >
Images are same
<cfelse>
DIFFERENT
</cfif>
</cfif>
</cfloop>
The code doesn't seem to be working. Can Anyone see what am I doing wrong?
Update 1 from comments
The result that I actually get is that the first images are same and the rest of images in files are different. But this is not correct as most of the images that I am comparing are same.
Update 2 from comments
It incorrectly identifies same images as being different. What I actually get is that the first two images are same and the rest is different. Which is not right as most of the images I have are same.
I've always just done this with BinaryEncode(), and then compare the resulting strings. You have to be careful though, as compression can make the files different even though they look (to the eye) exactly the same.
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
I'm wanting to update a file if a file in a central folder is newer.
Here's what I have so far but it doesn't seem to work as the months change - works OK for days and minutes.
<cfdirectory action="list" directory="#baseViewStackDir#" filter="#viewStackFileName#" name="base_fileInfo">
<!--- end --->
<cfset myViewStackDir = ExpandPath('/designer/app') />
<cfdirectory action="list" directory="#myViewStackDir#" filter="#viewStackFileName#" name="target_fileInfo">
<cfset copy = false />
<cfif DateCompare(base_fileInfo.DATELASTMODIFIED,target_fileInfo.DATELASTMODIFIED,"yyyy") GT 0 >
<cfset copy = true />
<cfelseif DateCompare(base_fileInfo.DATELASTMODIFIED,target_fileInfo.DATELASTMODIFIED,"m") GT 0>
<cfset copy = true />
<cfelseif DateCompare(base_fileInfo.DATELASTMODIFIED,target_fileInfo.DATELASTMODIFIED,"d") GT 0>
<cfset copy = true />
<cfelseif DateCompare(base_fileInfo.DATELASTMODIFIED,target_fileInfo.DATELASTMODIFIED,"h") GT 0>
<cfset copy = true />
<cfelseif DateCompare(base_fileInfo.DATELASTMODIFIED,target_fileInfo.DATELASTMODIFIED,"n") GT 0>
<cfset copy = true />
<cfelseif DateCompare(base_fileInfo.DATELASTMODIFIED,target_fileInfo.DATELASTMODIFIED,"s") GT 0>
<cfset copy = true />
</cfif>
<cfif copy EQ true>
<cffile action="copy" source="#baseViewStackDir##viewStackFileName#" destination="#myViewStackDir#"/>
</cfif>
<script type="text/javascript">
console.log("swf updated=<cfoutput>#copy# #base_fileInfo.DATELASTMODIFIED# - #target_fileInfo.DATELASTMODIFIED# ....#DateCompare(base_fileInfo.DATELASTMODIFIED,target_fileInfo.DATELASTMODIFIED,'m')#</cfoutput>");
</script>
Please can anyone spot my mistake?
As Peter and I alluded to in our comments you can change your entire script to be just this
<cfif base_fileInfo.DateLastModified GT target_fileInfo.DateLastModified>
<cffile action="copy" source="#baseViewStackDir##viewStackFileName#" destination="#myViewStackDir#"/>
</cfif>
<script type="text/javascript">
console.log("swf updated=<cfoutput>#copy# #base_fileInfo.DATELASTMODIFIED# - #target_fileInfo.DATELASTMODIFIED# ....#DateCompare(base_fileInfo.DATELASTMODIFIED,target_fileInfo.DATELASTMODIFIED,'m')#</cfoutput>");
</script>
If you're trying to autoversion your js/css files you can use something like this to read the modified date of the file and append that date to the js/css url
<cffunction Name="autoversion" access="public" returntype="string" output="false">
<cfargument Name="filepath" type="string" required="yes">
<cfset var fileDate = createObject("java","java.util.Date").init(createObject("java","java.io.File").init('C:\railo\webapps\railo\website\bootstrap\js'&Replace(arguments.filepath, '/', '\', 'ALL')).lastModified())>
<cfreturn 'https://www.mydomain.com/'&arguments.filepath&'?d='&DateFormat(fileDate, 'mmddyyyy')&TimeFormat(fileDate, 'hh')>
</cffunction>
<cfset autoversion('/bootstrap.js')>
I have a text field that I want to autosuggest values based on a query. I have a main file along with a separate file (getdata.cfc) that holds my query.
Here is the text field portion of my main file:
<cfinput name="search_query" autosuggest="url:getdata.cfc?suggestvalue={cfautosuggestvalue}" maxResultsDisplay="10" showAutoSuggestLoadingIcon="true" size="10" />
Here is the code in getdata.cfc:
<cfcomponent>
<cffunction name="get_data" access="remote" output="false">
<cfargument name="suggestvalue" required="true">
<cfquery name="get_data" datasource="#application.DSN#">
SELECT DISTINCT myItem
FROM myTable
WHERE myItem LIKE <cfqueryparam value="#suggestvalue#%"
cfsqltype="cf_sql_varchar">
ORDER BY myItem
</cfquery>
<cfif get_data.recordCount eq 1>
<cfreturn ",#get_data.myItem#">
<cfelse>
<cfreturn ValueList(get_data.myItem)>
</cfif>
</cffunction>
</cfcomponent>
The text field shows up fine, but when I type a word no autosuggest values show up. Nothing happens. The text is just displayed as I type it.
Any suggestions? Thank you!
I switched away to using jquery plugins from a lot of CF stuff, but here is an example I have that works in some old production code
<cfinput type="text" name="email" id="email" autosuggest="cfc:cfc.users.lookupEmail({cfautosuggestvalue})" maxresultsdisplayed = "25">
<cffunction name="lookupEmail" access="remote" returntype="array">
<cfargument name="search" type="any" required="false" default="">
<!--- Define variables --->
<cfset var data="">
<cfset var result=ArrayNew(1)>
<!--- Do search --->
<cfquery name="data" datasource="datasource" maxrows="25" cachedwithin="#CreateTimeSpan(0,0,30,0)#">
SELECT distinct email
FROM users
WHERE email LIKE <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.search#%">
ORDER BY email
</cfquery>
<!--- Build result array --->
<cfloop query="data">
<cfset ArrayAppend(result, email)>
</cfloop>
<!--- And return it --->
<cfreturn result>
</cffunction>
maybe this helps
also make sure you have your cfform tags around your form, and make sure that your /cfide folder is mapped to your website.
looking at your code and comparing it... it may be the way your calling the cfc (filename)
try: autosuggest="cfc:getdata.get_data.({cfautosuggestvalue})"
I usually create update statements like this. But I know there is a better way. How can I approve upon this? *Note the sample below is pseudo demo, may not run.
<cffunction name="updateEmp" returntype="void">
<cfargument name="empId" required="yes" hint="empId">
<cfargument name="firstName" required="yes" hint="firstName">
<cfargument name="lastName" required="yes" hint="lastName">
<!--- Get emp details in db --->
<cfquery datasource="#ds#" name="getEmployee">
SELECT *
FROM Employee
WHERE emp_id = <cfqueryparam
value="#arguments.empId#"
CFSQLType="CF_SQL_INTEGER">
</cfquery>
<!--- If employee is in db or if emp db details are different --->
<cfif getEmployee.recordCount eq 1
and getEmployee.firstName neq trim(arguments.firstName)
or getEmployee.lastName neq trim(arguments.lastName)>
<cfquery name="UpdateExistingEmployee" datasource="#ds#">
UPDATE Employee
SET 1 = 1
<cfif getEmployee.firstName neq trim(arguments.firstName)>
,firstName = <cfqueryparam
value="#arguments.firstName#"
CFSQLType="CF_SQL_VARCHAR" >
</cfif>
<cfif getEmployee.lastName neq trim(arguments.lastName)>
,lastName = <cfqueryparam
value="#arguments.lastName#"
CFSQLType="CF_SQL_VARCHAR" >
</cfif>
WHERE emp_id=<cfqueryparam
value="#emp_id#"
CFSQLType="CF_SQL_INTEGER">
</cfquery>
</cfif>
<!--- maybe return success? --->
</cffunction>
Edited:
<cffunction name="updateEmp" returntype="void">
<cfargument name="empId" required="yes" hint="empId">
<cfargument name="firstName" required="yes" hint="firstName">
<cfargument name="lastName" required="yes" hint="lastName">
<cfquery name="UpdateExistingEmployee" datasource="#ds#">
UPDATE Employee
SET firstName = <cfqueryparam
value="#arguments.firstName#"
CFSQLType="CF_SQL_VARCHAR" >
,lastName = <cfqueryparam
value="#arguments.lastName#"
CFSQLType="CF_SQL_VARCHAR" >
WHERE emp_id=<cfqueryparam
value="#emp_id#"
CFSQLType="CF_SQL_INTEGER">
</cfquery>
<!--- maybe return success? --->
</cffunction>
Not sure what you are trying to improve. If you just want to write less code you might just do an update:
<cffunction name="updateEmp" returntype="void">
<cfargument name="empId" required="yes" hint="empId">
<cfargument name="firstName" required="yes" hint="firstName">
<cfargument name="lastName" required="yes" hint="lastName">
<cfquery name="UpdateExistingEmployee" datasource="#ds#">
UPDATE Employee
SET firstName = <cfqueryparam value="#arguments.firstName#" CFSQLType="CF_SQL_VARCHAR">
,lastName = <cfqueryparam value="#arguments.lastName#" CFSQLType="CF_SQL_VARCHAR" >
WHERE emp_id=<cfqueryparam value="#emp_id#" CFSQLType="CF_SQL_INTEGER">
</cfquery>
</cffunction>
The check for an existing record is pretty much superfluous since the where clause will prevent any action if no emp_id matches, and why bother checking if the names match? If they do, then you just updated them to be the same, if they don't you're going to update them anyway. There's no logical reason to be doing all that checking.
Maybe check out Coldfusion ORM? Or, for something that would require less drastic changes to your codebase, you could use DataMgr (which really helps cut down on CRUD): http://datamgr.riaforge.org/