×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

exclude erroneous returns / line feeds from count() ?

exclude erroneous returns / line feeds from count() ?

exclude erroneous returns / line feeds from count() ?

(OP)
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.

RE: exclude erroneous returns / line feeds from count() ?

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
https://www.doschke.name

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close