I am trying to use cfhttp to create a query out of a text file and then loop
and insert it into a database. Easy enough and works fine. However, I am
getting a forward slash in some of the fields which is causing an error.
'SOUTH OF SOUTH BLVD AND EAST OF BEACH RD\'
It is being entered into a LONGTEXT field in MySQL 5. Any way to get the '\'
to be ignored and just be entered?
Here is my script block:
<cfhttp timeout="3600" url="http://www.bpoprosonline.com/property/#ResFile#"
method="GET" name="Property" delimiter="|" textqualifier=""
firstrowasheaders="yes" />
<cfloop query="Property">
<cfquery name="loopProperty" datasource="bpopros">
Insert Into Property
(MLSNumber, ListOfficeCompany, ListOfficeId, Basement, Baths, BFK_Dimen,
BR2_Dimen, BR3_Dimen, BR4_Dimen, BR5_Dimen, City, County, Din_Dimen,
Directions, Directions_E_W, Directions_N_S, East_West, Fam_Dimen, Fireplace,
Garage, Grt_Dimen, Kit_Dimen, Lib_Dimen, ListPrice, Liv_Dimen, Lot_Dimen,
MBR_Dimen, No_Bedrooms, North_South, Remarks1, Remarks2, Remarks3, Remarks4,
Remarks5, Remarks6, School_District, State, Street_Dir, StreetName,
StreetNumber, SummerTax, Tot_Baths, Tot_Lavs, Tot_Square_Feet, Winter_Tax,
Year_Built, Zip5, Appliances, Basement_Type, Bath_Desc, Cooling, Exterior,
Foundation, Garage_Type, Heating, Other_Rooms, Site_Desc, Style, PhotoURL,
DisplayAddress, Agent, weight)
VALUES
(
<cfif #MLSNumber# EQ "">0<cfelse>#MLSNumber#</cfif>,
'#ListOfficeCompany#',
<cfif #ListOfficeId# EQ "">0<cfelse>#ListOfficeId#</cfif>,
'#Basement#',
<cfif #Baths# EQ "">0<cfelse>#Baths#</cfif>,
'#BFK_Dimen#',
'#BR2_Dimen#',
'#BR3_Dimen#',
'#BR4_Dimen#',
'#BR5_Dimen#',
'#City#',
'#County#',
'#Din_Dimen#',
'#Directions#',
'#Directions_E_W#',
'#Directions_N_S#',
'#East_West#',
'#Fam_Dimen#',
'#Fireplace#',
'#Garage#',
'#Grt_Dimen#',
'#Kit_Dimen#',
'#Lib_Dimen#',
<cfif #ListPrice# EQ "">0<cfelse>#ListPrice#</cfif>,
'#Liv_Dimen#',
'#Lot_Dimen#',
'#MBR_Dimen#',
<cfif #No_Bedrooms# EQ "">0<cfelse>#No_Bedrooms#</cfif>,
'#North_South#',
'#Remarks1#',
'#Remarks2#',
'#Remarks3#',
'#Remarks4#',
'#Remarks5#',
'#Remarks6#',
'#School_District#',
'#State#',
'#Street_Dir#',
'#StreetName#',
'#StreetNumber#',
'#SummerTax#',
<cfif #Tot_Baths# EQ "">0<cfelse>#Tot_Baths#</cfif>,
<cfif #Tot_Lavs# EQ "">0<cfelse>#Tot_Lavs#</cfif>,
<cfif #Tot_Square_Feet# EQ "">0<cfelse>#Tot_Square_Feet#</cfif>,
'#Winter_Tax#',
<cfif #Year_Built# EQ "">0<cfelse>#Year_Built#</cfif>,
<cfif #Zip5# EQ "">0<cfelse>#Zip5#</cfif>,
'#Appliances#',
'#Basement_Type#',
'#Bath_Desc#',
'#Cooling#',
'#Exterior#',
'#Foundation#',
'#Garage_Type#',
'#Heating#',
'#Other_Rooms#',
'#Site_Desc#',
'#Style#',
'#PhotoURL#',
'#DisplayAddress#',
0,
<cfif #ListOfficeId# EQ 340169>1<cfelse>0</cfif>)
</cfquery>
</cfloop>
Thanks

Signature
Wally Kolcz
MyNextPet.org
Founder / Developer
586.871.4126
WebDev - 09 Sep 2007 17:20 GMT
In short, I need to search for and escape the \ character in a field prior
to insert.
WebDev - 09 Sep 2007 17:51 GMT
Ok, first I am looking for the character using <cfif #field# CONTAINS
"\">'Error'<cfelse>'#field#'</cfif> and that is working so far. Now I just
need to escape the \.
I am going to try replace(#field#, "\", "\\", "ALL").
Will that work or any better ideas?
Dan Bracuk - 09 Sep 2007 23:13 GMT
What happened when you tried it? Did you have a similar problem with apostrophes?
cfqueryparam will probably escape all the weird characters you are likely to encounter.
WebDev - 09 Sep 2007 23:27 GMT
It seemed to have worked. I managed to loop and insert 55,345 records
without a hitch. I may move it to a cfqueryparam and see if that works too.
> What happened when you tried it? Did you have a similar problem with
> apostrophes?
>
> cfqueryparam will probably escape all the weird characters you are likely
> to encounter.