Co-incidental, I'm also trying to get import to work today <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=49655&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />
There are 6 fields in my table: field a
to field_f.
This table is a detail table, with field a
as the master linking key (no nulls).
My primary key is concatentated, field a
+ field c
(note: PHPR supports up to 3 concatentated key fields)
All works fine with usual lists and adds.
But on Import I'm getting an error message for every line in my xls (2003) import file.
Error:
SQL query: insert into my_table
(field c
,field_b
,field_d
,field_f
) values (data_c, 'data_a', data_b, 'data_d', 'data_e', 'data_f');
DB error: Column count doesn't match value count at row 1;
The insert is trying to insert 6 fields.
But the field list for the insert only contains 4 fields instead of the 6 it should (excludes field a
and field_e)
The order of the fields in the SQL query does not match the order of any fields in the Fields Tab in PHPR, although there is not a tab specifically for the import page. There is a tab for the export page, however I have no export page.
Not sure if its relevant, but the excel I'm importing from only contains one field, that's field c
(part of the key). The first row of the excel table contains label "field c". The event import: before_insert_record uses session variables and looks-up data in other tables and gets the data for all 6 fields. The $values[] array is populated accordingly includes $rawvalues["field c"].
$values["field a"] = $_SESSION["field a"];
$values["field_b"] = $_SESSION["field_b"];
$values["field c"] = $rawvalues["field c"];
$values["field_d"] = $data["field_d"];
$values["field_e"] = $data["field_e"];
$values["field_f"] = $data["field_f"];
Its apparent that its reading the excel ok and grabbing the data. All the data is getting into the query ok. But the SQL query is getting mangled (dropping a & e). Incidentally note: Fields a & c names have embedded space, but its quoted correctly.
So my first question is, where does the import get the fields names to use and order from?
And second, why is there a mismatch in the SQL?
[Update] As an experiment, I have fully populated the excel table with all 6 columns corresponding to my field names, with dummy data (except for field c
). The import works. Only throws an error when there is a duplicate key. Since I can't add IGNORE to the insert statement, I must first lookup the key and if hit, then I return a false. When I get time I'll continue experiments to see how much of a subset I can get away with.
If it turns out I am stuck with having to define all the fields needed in the excel, I'll have to split the import into two stages with a dummy temp table with only one field defined, and then a post import event which takes that temp table and updates the real table. And solve the concurrency issue...