In function "countries_api_csv_import_countries()" in "countries_api.module" each field has a test for empty fields from the CSV file, eg.:
$iso3 = ($row[3]) != 'NULL') ? $row[3] : "";
But as far as i can tell, empty fields in the CSV file have the entry "NULL", e.g.:
AQ,ANTARCTICA,Antarctica,NULL,NULL
Meaning, for empty fields, NULL or "NULL" will be inserted into the table "countries_api_countries" instead of an empty string. This won't work on PostgreSQL, because the field "iso3" was defined as "char(3)" in "countries_api.install".
A fix could be:
$iso2 = ($row[0] && strtoupper($row[0]) != 'NULL') ? $row[0] : "";
$name = ($row[1] && strtoupper($row[1]) != 'NULL') ? $row[1] : "";
$printable_name = ($row[2] && strtoupper($row[2]) != 'NULL') ? $row[2] : "";
$iso3 = ($row[3] && strtoupper($row[3]) != 'NULL') ? $row[3] : "";
$numcode = ($row[4] && strtoupper($row[4]) != 'NULL') ? $row[4] : "NULL";
Could you please fix this problem in a next release?
Thanks in advance.
Comments
Comment #1
neilnz commentedI came across the same problem on Postgres.
I've crafted a patch to use Schema API's drupal_write_record() to insert into the table instead of constructing the query manually. I've also changed the schema def to make iso3 properly nullable.
Patch attached.
Comment #2
mrfelton commented@neilnz: your patch contains a slight bug in line 259 was making a couple of the tests fail. I have corrected and committed to CVS (http://drupal.org/cvs?commit=345512)
In
countries_api_csv_import_countries()Should have read:
Comment #4
ahtih commentedReopening this.
The code with drupal_write_record() does not work during fresh install of the module. This is because drupal_write_record() only works for schemas defined in already fully installed modules. Since we have still not returned from countries_api_install() function at that point, drupal_write_record() will silently fail and no data gets inserted into the table.
Comment #5
claar commentedI ran into this or a similar bug on enabling this module with postgres. 10+ lines like this:
Comment #6
johnvI have MySQL running, and the install-script doesn't work for me, either, because of this commited patch.
I think the .csv file should work with empty columns, too, instead of using NULL-values.
I made the following 'patch' in
countries_api_csv_import_countries().Comment #7
mrfelton commentedThis should be resolved in git now.
Thanks.