osyrys14 Posted April 1, 2013 Share Posted April 1, 2013 I have a DB that I've been working on importing data to from text files. The data imports fine, but if its a report that has no data (or just a header) it inserts what seems to be a blank row. usually, I can delete these with a simple SELECT * FROM table WHERE name=''; to be sure, and DELETE FROM table WHERE name='';, neither of which is returning any results. Also, is there a way to check for this on the import so I won't have the empty rows to deal with in the future. Thanks so much for any help that anyone can provide. Link to comment https://forums.phpfreaks.com/topic/276371-empty-rows-in-a-table-help/ Share on other sites More sharing options...
Psycho Posted April 1, 2013 Share Posted April 1, 2013 On 4/1/2013 at 4:33 AM, osyrys14 said: . . . is there a way to check for this on the import so I won't have the empty rows to deal with in the future. Yes, of course. Simply do a check of the data before inserting. Link to comment https://forums.phpfreaks.com/topic/276371-empty-rows-in-a-table-help/#findComment-1422210 Share on other sites More sharing options...
osyrys14 Posted April 1, 2013 Author Share Posted April 1, 2013 My apologies, I worded that wrong. The rows appear to be empty, but using the SQL commands above do not find or delete them. The text files are aparently filled with something that is showing as blank, but not truly empty. And it's not on an insert statement, they are hourly files we import once a day for querying later for usage statistics. Like an activity log. Link to comment https://forums.phpfreaks.com/topic/276371-empty-rows-in-a-table-help/#findComment-1422212 Share on other sites More sharing options...
davidannis Posted April 1, 2013 Share Posted April 1, 2013 Could you have some whitespace characters, perhaps spaces or tabs in the data? Try using trim http://php.net/manual/en/function.trim.php Link to comment https://forums.phpfreaks.com/topic/276371-empty-rows-in-a-table-help/#findComment-1422213 Share on other sites More sharing options...
Psycho Posted April 1, 2013 Share Posted April 1, 2013 On 4/1/2013 at 4:52 AM, osyrys14 said: And it's not on an insert statement, they are hourly files we import once a day for querying later for usage statistics. And you are you processing those import files to create records in the database? If you are using something like MySQL "LOAD DATA" on a file that is not "clean" then you are going to end up with garbage. I'm guessing the same thing as davidannis. You should pre-process the file before creating the records to remove any invalid data. Link to comment https://forums.phpfreaks.com/topic/276371-empty-rows-in-a-table-help/#findComment-1422214 Share on other sites More sharing options...
osyrys14 Posted April 1, 2013 Author Share Posted April 1, 2013 I've recently tried using this statement, since I found another column in the row that DOES have data that I don't need, so I try this... DELETE FROM cdr WHERE tablename LIKE '%billing_file%'; Still no results, when I know billing_file is in that field, but that's just the start of the name, so I can't use tablename = 'billing_file' Link to comment https://forums.phpfreaks.com/topic/276371-empty-rows-in-a-table-help/#findComment-1422215 Share on other sites More sharing options...
osyrys14 Posted April 1, 2013 Author Share Posted April 1, 2013 That would be great Psycho. How do I go about doing that? Something built into the MySQL server, or something else I need to get? Link to comment https://forums.phpfreaks.com/topic/276371-empty-rows-in-a-table-help/#findComment-1422216 Share on other sites More sharing options...
Psycho Posted April 1, 2013 Share Posted April 1, 2013 That is for YOU to decide. I have no clue about the source of the data you are using, the requirements of the data to be stored, etc. etc. But, based upon your statements, you are getting records that should not exist. So you need to clean it up. One way would be to process the data into individual records for the database - removing/skipping any that should be considered "invalid", then running the query to insert all the valid records Link to comment https://forums.phpfreaks.com/topic/276371-empty-rows-in-a-table-help/#findComment-1422217 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.