I have uc_store version 2009-10-30

I have had Ubercart for a while and whenever you changed the country column country_id from a SERIAL to an INTEGER, it moved from being first to being last in the table. It is always like that in PostgreSQL when you add a new column, copy the old to the new and then remove the old. Anyway... This means using an INSERT without specifying the column names fails.

  • warning: pg_query() [function.pg-query]: Query failed: ERROR: invalid input syntax for integer: "CHL" in [...]/includes/database.pgsql.inc on line 139.
  • user warning: query: INSERT INTO uc_countries VALUES (152, 'Chile', 'CL', 'CHL', 1) in [...]/sites/all/modules/ubercart/uc_store/countries/chile_152_1.cif on line 6.
                             Table "public.uc_countries"
       Column       |          Type          |               Modifiers                
--------------------+------------------------+----------------------------------------
 country_name       | character varying(255) | not null default ''::character varying
 country_iso_code_2 | character(2)           | not null default ''::bpchar
 country_iso_code_3 | character(3)           | not null default ''::bpchar
 version            | smallint               | not null default 0
 country_id         | int_unsigned           | not null
Indexes:
    "uc_countries_pkey" PRIMARY KEY, btree (country_id)
    "uc_countries_country_name_idx" btree (country_name)

The following works:

function chile_install() {
  // VALUES = Country ID, Country Name, 2-digit Code, 3-digit Code, File Version
  db_query("INSERT INTO {uc_countries} (country_id, country_name, country_iso_code_2, country_iso_code_3, version) VALUES (152, 'Chile', 'CL', 'CHL', 1)");

  [...]

The patch is a fix for all the countries.

Thank you.
Alexis Wilke

Comments

Island Usurper’s picture

Is that maybe the wrong patch?

AlexisWilke’s picture

StatusFileSize
new80.73 KB

Well... there is indeed a remote chance that was the wrong patch... 8-)

tr’s picture

Status: Active » Needs review

The column type was changed in #610664: country_id declared as serial; isn't.

Does this issue affect *new* installations on PostgreSQL or just upgrades from a previous UC version? From your description it sounds like it was the db_change_field() call (i.e. ALTER TABLE) in uc_store_update_6005() that resulted in the column order being changed, so new installations should be safe.

The documentation on how to create a .cif file will also have to change, and a bug report will have to be filed against all contributed .cifs ...

tr’s picture

Status: Needs review » Fixed

I tested the patch on MySQL to make sure it didn't break anything. I also fixed algeria_12_1.cif, bahrain_48_2.cif, and pakistan_586_1.cif, which weren't included in your patch.

AlexisWilke’s picture

Hi TR,

The problem could occur again on other upgrades, but yes, it only appeared on upgrades (after the call to the db_change_field()). Now I agree that the order should not be changed, but that's how PostgreSQL does it... We have no control over it. In all circumstances, it is much safer to have the column names repeated to make sure you don't get an error.

And the additional countries, I think, were not included in the version I had at the time I generated the patch. Thank you for taking care of those.

Alexis

AlexisWilke’s picture

Assigned: Unassigned » AlexisWilke
Status: Fixed » Active
StatusFileSize
new713 bytes

Looks like Saudi Arabia was missed in our patches...

AlexisWilke’s picture

StatusFileSize
new713 bytes

Sorry, the previous patch is inverted!

There is the correct one:

tr’s picture

Thanks for catching that. Committed.

tr’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.