Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

exclude erroneous returns / line feeds from count() ?

Status
Not open for further replies.

admoore

IS-IT--Management
May 17, 2002
224
US
I am updating legacy php code which imports csv data to a mySQL database. The code includes error checking which compares the number of imported rows to the number of lines found in the import file. The problem is that a small percentage of records includes returns or line feeds enclosed within fields. MySQL will happily load the data; but, when I count() the number of lines in the source, the number is artificially inflated due to the enclosed returns & line-feeds.

At present, the code is simply patched to force the counts into an equal condition.

I am looking for a solution to more accurately count the lines in the import file, ignoring the enclosed returns and line-feeds. Any suggestion is appreciated...

imported file can be large, so also trying to avoid loading file as array...

Thanks in advance...
-Allen M.
 
The question is whether you really need to check the import got all lines. The easiest to get the number of CSV records is counting newly imported records in the target table, as delimited text fields are read correctly.

If there is any reason like check constraints rejecting records find out using a staging table that doesn't have such rules and can therefore simply import all rows in any case. Then you have your reference count.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top