question

ycb avatar image
ycb asked ·

Issue when querying items with name

Hi,
I use InventoryContact to load items like this:

Uri uri = InventoryContract.Item.contentUriWithAccount(CloverAccount.getAccount(getActivity()));
String where = "name LIKE '%coca%'"
CursorLoader loader = new CursorLoader(getActivity(), uri,
                            null, where, null, null);

it was working fine, but recently it crashes

Caused by: android.database.sqlite.SQLiteException: ambiguous column name: name (code 1): , while compiling: SELECT price_without_vat, item_menu_item.description AS menu_description, alternate_name, default_tax_rates, code, cost, taxable, item_group_uuid, hidden, count, uuid, unit_name, modified_time, item_menu_item.enabled AS menu_enabled, price, item_menu_item.name AS menu_name, item_menu_item.reason_code AS menu_reason_code, item.name AS name, price_type, item._id AS _id, sku, is_revenue, item_menu_item.image_filename AS menu_image_filename, color_code FROM item LEFT OUTER JOIN item_menu_item ON item.uuid=item_menu_item.item_uuid WHERE ((name LIKE '%coca%'))
 

do you have any fix for this?

Inventory
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

David Marginian avatar image
David Marginian answered ·

Can you try updating your where to "item.name LIKE '%coca%'" for now and I will look into this in more detail.

1 comment
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

the best workaround it to set projection like this :

String[] projection = {InventoryContract.Item._ID,InventoryContract.Item.UUID, InventoryContract.Item.NAME, InventoryContract.Item.ALTERNATE_NAME, InventoryContract.Item.CODE, InventoryContract.Item.COST, InventoryContract.Item.DEFAULT_TAX_RATES,InventoryContract.Item.HIDDEN, InventoryContract.Item.IS_REVENUE,InventoryContract.Item.ITEM_GROUP_UUID, InventoryContract.Item.MODIFIED_TIME, InventoryContract.Item.PRICE, InventoryContract.Item.PRICE_TYPE,
        InventoryContract.Item.PRICE_WITHOUT_VAT, InventoryContract.Item.SKU, InventoryContract.Item.UNIT_NAME};
Uri uri = InventoryContract.Item.contentUriWithAccount(CloverAccount.getAccount(getActivity()));
String where = "name LIKE '%coca%'";
CursorLoader loader = new CursorLoader(getContext(), uri,
        projection, where, null, null);
1 Like 1 ·
ycb avatar image
ycb answered ·

yes, this works,
but it is not a good thing. to put static table name 'item'.

2 comments
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

As you can see from the query, a join is being made on item_menu_item, which I assume is new. Because both item_menu_item and item have a "name" column your where clause is resulting in an ambigous query. I am not sure if this is something we recently changed or what but if it is we shouldn't be breaking backwards compat, however, I am not sure what our options are in this case. I am checking with the team that made this change to get more information.

1 Like 1 ·
ycb avatar image ycb David Marginian ♦♦ ·

ok, please notify me here when there is news about the issue.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community