Android SugarRecord尝试使用不存在的表

时间:2018-11-12 22:28:32

标签: android sugarorm

运行我的代码,出现此错误。

  

android.database.sqlite.SQLiteException:没有这样的表:STORE(代码   1):,编译时:INSERT或REPLACE INTO STORE(TOTAL_TEXT ......

我已经阅读了一些论坛,但我仍然不知道为什么系统会查找此 STORE 表。在代码的任何部分,都没有引用任何 STORE 表,因为该表在我的Cloud FireBase中不存在。我拥有的表称为 Stores

最流行的解决方案之一是禁用“即时运行”,但是我不能,因为其余的代码都需要它。

扔Logcat,我发现问题是由于SugarRecord.save(store);的{​​{1}}造成的。

我的代码是这个。

FirebaseDatabaseHelper.java

FirebaseDatabaseHelper.java

Store.java

public static void getAllStores(final StoresSyncedListener storesSyncedListener)
    {
        FirebaseFirestore db = FirebaseFirestore.getInstance();
        log("getAllStores");
        db.collection("Stores")
                .get()
                .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>()
                {
                    @Override
                    public void onComplete(@NonNull Task<QuerySnapshot> task)
                    {
                        log("task.toString " + task.toString());
                        log("task.isSuccessful " + task.isSuccessful());
                        if (task.isSuccessful())
                        {
                            log("task.getResult " + task.getResult().size());
                            for (QueryDocumentSnapshot document : task.getResult())
                            {
                                Store store = document.toObject(Store.class);
                                store.setStoreId(document.getId());
                                //save all stores to local Sugar database
                                SugarRecord.save(store);
                            }
                            log("task.SugarRecord.saveInTx B");

                            storesSyncedListener.onStoresSynced(true);
                        }
                        else
                        {
                            storesSyncedListener.onStoresSynced(false);
                            logError("Error getting documents: ", task.getException());
                        }
                    }
                });
    }

Logcat

public class Store extends SugarRecord
{
    @Unique
    private String storeId;
    private String address;
    private String city;
    private String country;
    private String mail;
    private String phone;
    private String postalCode;
    private String taxCode;
    private String name;
    private float totalXpoint;
    private String priceSeparator;
    private String totalText;
    private String dateFormat;
    private String currency;

    public Store()
    {
        super();
    }

    public String getOwner()
    {
        return owner;
    }

    public void setOwner(String owner)
    {
        this.owner = owner;
    }

    private String owner;


    public String getStoreId()
    {
        return storeId;
    }

    public void setStoreId(String storeId)
    {
        this.storeId = storeId;
    }

    public String getAddress()
    {
        return address;
    }

    public void setAddress(String address)
    {
        this.address = address;
    }

    public String getCity()
    {
        return city;
    }

    public void setCity(String city)
    {
        this.city = city;
    }

    public String getCountry()
    {
        return country;
    }

    public void setCountry(String country)
    {
        this.country = country;
    }

    public String getMail()
    {
        return mail;
    }

    public void setMail(String mail)
    {
        this.mail = mail;
    }

    public String getPhone()
    {
        return phone;
    }

    public void setPhone(String phone)
    {
        this.phone = phone;
    }

    public String getPostalCode()
    {
        return postalCode;
    }

    public void setPostalCode(String postalCode)
    {
        this.postalCode = postalCode;
    }

    public String getTaxCode()
    {
        return taxCode;
    }

    public void setTaxCode(String taxCode)
    {
        this.taxCode = taxCode;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public float getTotalXpoint()
    {
        return totalXpoint;
    }

    public void setTotalXpoint(float totalXpoint)
    {
        this.totalXpoint = totalXpoint;
    }

    public String getPriceSeparator()
    {
        return priceSeparator;
    }

    public void setPriceSeparator(String priceSeparator)
    {
        this.priceSeparator = priceSeparator;
    }

    public String getTotalText()
    {
        return totalText;
    }

    public void setTotalText(String totalText)
    {
        this.totalText = totalText;
    }

    public String getDateFormat()
    {
        return dateFormat;
    }

    public void setDateFormat(String dateFormat)
    {
        this.dateFormat = dateFormat;
    }

    public String getCurrency()
    {
        return currency;
    }

    public void setCurrency(String currency)
    {
        this.currency = currency;
    }

    @Override
    public String toString()
    {
        return "Stores{" +
                "storeId='" + storeId + '\'' +
                ", address='" + address + '\'' +
                ", city='" + city + '\'' +
                ", country='" + country + '\'' +
                ", mail='" + mail + '\'' +
                ", phone='" + phone + '\'' +
                ", postalCode='" + postalCode + '\'' +
                ", taxCode='" + taxCode + '\'' +
                ", name='" + name + '\'' +
                ", totalXpoint=" + totalXpoint +
                ", priceSeparator='" + priceSeparator + '\'' +
                ", totalText='" + totalText + '\'' +
                ", dateFormat='" + dateFormat + '\'' +
                ", currency='" + currency + '\'' +
                '}';
    }
}

1 个答案:

答案 0 :(得分:0)

在Firebase上如何调用远程节点并不重要...您必须将本地表Stores重命名为STORE-{{1}所期望的}的命名约定。已经检查了documentation,但是没有可用于映射表名称的注释-因为它们将存在于Room中。但是在查看source code时似乎有一个@Table注释,这可能会允许映射:

ORM