Importing a text file
Hi,
i've been happily importing a 1.5mb "|" delimited txt file into my web database for the past few years using cfhttp with the code below;
----------------------------------------------------
<cfhttp method="get" textqualifier=" " firstrowasheaders="no" delimiter="|" username="xxxxx" password="xxxxxx" name="test" url="http://xxxxxxxx/xxx/xxxxxxx.txt">
<cfloop query="test">
<cfquery datasource="#client.DSN#" username="#client.UserName#" passWord="#client.PassWord#">
INSERT INTO products (product, description, unitofmeas, SOH, Price, discount)
VALUES ('#test.column_1#', '#test.column_2#', '#test.column_3#', '#test.column_4#', '#test.column_5#', '#test.column_6#')
</cfquery>
</cfloop>
-----------------------------------------------------
Recently my web server is throwing an error "Request aborted due to heavy load" and the transaction fails. I suspect my web host has limited or put some restriction on cfhttp or something like this that is causing my process to fail. Until i get some answers from my web host I'm trying alternate methods that may be more efficient to do the update but im having all sorts of problems with null value float values (columns - SOH, Price).
------------------------------------------------------
<cffile action="read" file="d:\inetpub\xxxxxx\xxx\xxxxxxxx.txt" variable="txtfile">
<cfloop index="index" list="#txtfile#" delimiters="#chr(10)##chr(13)#">
<cfquery name="importtxt" datasource="#client.DSN#" username="#client.UserName#" passWord="#client.PassWord#">
INSERT INTO products (product, description, unitofmeas, SOH, Price, discount)
VALUES
('#gettoken('#index#',1, '|')#',
'#gettoken('#index#',2, '|')#',
'#gettoken('#index#',3, '|')#',
#gettoken('#index#',4, '|')#',
'#gettoken('#index#',5, '|')#',
'#gettoken('#index#',6, '|')#')
</cfquery>
</cfloop>
----------------------------------------------------
when i run the code above i get the following error.
----------------------------------------------------
[Macromedia][SQLServer JDBC Driver][SQLServer]Error converting data type varchar to float.
INSERT INTO products_bretttest (product, description, unitofmeas, SOH, Price, discount) VALUES ('43667', 'OBSTAPEWIPES8051X150-OBS', 'ROL', '0.000', 'C3', '')
--------------------------------------------------
It looks like what is happening is when my process hits the first line in the txt file where price(column5) has a null value, it's shifting the string discount(column6) value into column 5.
Does anybody know what i can do to handle these null value floats in my text file to get around the error? Or if someone has a better or more efficient way to read a text file and insert it into a dtabase table, that would be great as well?
Thanks in advance
Brett
