Import as NULL from csv

dimoss

Well-Known Member
Hi,

I wonder if it's possible to use the import csv feature and import empty values as NULL.
At the moment in the integer first the enpty values are imported as '0'.
Using the same .csv through phpmyadmin I can get the value as NULL
Thanks.
 
Did you try the csv list plugin?
There are "Import row", "After import row" "Import start" and "Import complete" hooks.
I don't know what your will get there in details, I assume some var_dumps will help.
 
Did you try the csv list plugin?
There are "Import row", "After import row" "Import start" and "Import complete" hooks.
I don't know what your will get there in details, I assume some var_dumps will help.

Hi @troester

using the following code After Import Row on list CSV plugin worked:
PHP:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->update('fab_matches')->set('player_id = NULL')->where('player_id = 0');
$db->setQuery($query);
$db->execute();

However the above runs on all rows, not only the imported ones.
How I will replace the data of the imported rows only?
Thanks.
 
I didn't use these hooks until now. But as I understand it the "After Import Row" code is run after each imported row. Your code is not related to an single row, it's running x times on the complete table.
The "Import row" tooltip says
"Code to run before each rows is imported. Modifying $formModel->formData['yourtable___yourelement'] will modify the data ..."
Try in "Import row" or "After Import row" with something like
if ($formModel->formData['yourtable___yourelement'] == '0') $formModel->formData['yourtable___yourelement'] = null;

But I'm just guessing.
 
I had already tried this and didn't work.
Searched also the forum for something similar but I couldn't find something.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top