I have a really strange one today. I use 8 char a...
# cfml-general
m
I have a really strange one today. I use 8 char alpha-numeric strings for customerid in one of my apps. Been doing this for YEARS. today, cf2016 on windows, the strangest error happened, and it only (so far) has happened to this one customerid. The customerid is 304143e8, but when it comes back from the function below, it converts to 30414300000000. Its a pretty simple function for a pretty simple search and it was probably written 7+ years ago. (sorry, hit enter too soon) - Any ideas why it would only be replacing the last 2 chars with 8 0's?
Copy code
<cffunction name="hotsearch" access="remote" returntype="array">
		<cfargument name="crit" type="string" required="yes">
		<cfset var rs=structnew()>
		<cfset var ra = arraynew(1)>
		<cfset ra[1]="NOT FOUND">
		  <cfquery name="getinfo" datasource="#variables.dsn#" maxrows="50">
			select cust_id,fname,lname,mycompany,company,webmail
			from vwSearchCustomer
			where 
				(webmail like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#arguments.crit#%">
				or lname like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#arguments.crit#%">
				or mycompany like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#arguments.crit#%">
				or company like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#arguments.crit#%">
				)
			group by 1
			order by lname,fname,mycompany
			</cfquery>
			<cfif getinfo.recordcount gt 0><cfset ra[1]="OK"></cfif>
			<cfoutput query="getInfo">
				<cfset rs=structnew()>
				<cfset rs.PERSON=getInfo.cust_id>
				<cfset rs.PERSONNAME=getinfo.fname&" "&getinfo.lname>
				<cfif len(trim(getinfo.mycompany)) eq 0>
					<cfset rs.COMPANY=getinfo.company>
				<cfelse>
					<cfset rs.COMPANY=getinfo.mycompany>
				</cfif>
				
				<cfset rs.E=lcase(getinfo.webmail)>
				<cfset arrayappend(ra,rs)>
			</cfoutput>
		<cfreturn ra>
	</cffunction>
w
clearly treating the e as an exponent
m
Agreed, but straight out of the DB varchar field?
w
if you dump right after the query, it's a string?
m
one sec
w
you can always heavy hand it by javacast'ing it to a string, but unclear if cf will do whatever it wants anyway after that
m
well, it's coming out of the query and the array just fine..
w
you mean in the dump?
or actually using the value
m
yep
but when the cfc returns the value, the js console shows it converted
w
how are you serializing the return value
m
its a remote cfc call; straight out of the box
wait, it gets weirder too
w
well, it seems to be inferring that it's an exponent flag, and if it's all under the hood stuff done by cf you may just have to proactively bork it to force as string. something like
<cfset rs.PERSON = getinfo.cust_id & " ">
you'll have to trim() it of course somewhere downstream
m
here is a screenshot of the firefox console
but when I flip the RAW switch, this is what I see, {"PERSON":304143e8,"E":"omitted","PERSONNAME":"omitted","COMPANY":""}
I sure don't want to scrub all the IDs in the database and edit all the ones that end with e-number
and it does the same in FF and chrome
w
you need to somehow get that value quoted
✔️ 1
it's coming through as a 'number'
the json serializer has generally sucked up to now, and i recall having to do stupid stuff like serializing to json, and THEN when it's a string, use regex to replace 'numbers' with their quoted string equivalent
m
any ideas on how to do that? And dev is Apache, prod is IIS, same on both.
w
i think you may have to NOT rely on the built in returnformat and do the serialization yourself and return that string of json
i don't use remote access methods, so i have little insight beyond what i said above
m
gawd, I think I would rather scrub the customerids and adjust my alphanum creation routine.
w
to exclude e from the alphas? might be a decent idea. if the first char as alpha it would probably solve it as well
m
yeah, right now I am using a modded hex routine to generate the alphanums (from like 15+ years ago) Guess I'll need a new alphnum generator
or, just replace all the e's with z's
And just like that, there goes taking an extra day off..
Thanks for the input; figuring out the problem is always the hard part. Enjoy your holidays!
c
If upgrading to a newer version of ColdFusion is an option, I believe a lot of the lingering JSON serialization problems were corrected in CF2018+. Otherwise, there are a few alternative JSON Serializers out there that you can wire up. I believe there's an Application.cfc way to define an alternative JSON Serializer. Ben Nadel's custom one is one of the best I've seen: https://github.com/bennadel/JsonSerializer.cfc
w
ben always has good code, but i'd wager that his computer buzzes and flashes a red light if his typing goes beyond 80 characters wide, like playing Operation
😄 1
c
m
@cfvonner that will save me from having to change all the e-number ids, thanks!