Running my code, I get this error.
android.database.sqlite.SQLiteException: no such table: STORE (code 1): , while compiling: INSERT OR REPLACE INTO STORE(TOTAL_TEXT......
I have read some forums and I still don't have any idea of why the system looks for this STORE table. In any part of the code, there is no referment to any STORE table because it doesn't exist in my Cloud FireBase. The table that I have is called Stores.
One of the most popular solution is to disable Instant Run but I can't because I need it for the rest of the code.
Going throw Logcat, I see that the issue is due to SugarRecord.save(store);
of FirebaseDatabaseHelper.java
.
My code is this.
FirebaseDatabaseHelper.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());
}
}
});
}
Store.java
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 + '\'' +
'}';
}
}
Logcat
11-17 16:24:43.580 9133-9133/com.example.ves.gennaio3 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.ves.gennaio3, PID: 9133
android.database.sqlite.SQLiteException: no such table: STORE (code 1): , while compiling: INSERT OR REPLACE INTO STORE(TOTAL_TEXT,ADDRESS,MAIL,TOTAL_XPOINT,PHONE,CURRENCY,CITY,OWNER,DATE_FORMAT,ID,NAME,PRICE_SEPARATOR,POSTAL_CODE,TAX_CODE,STORE_ID,COUNTRY) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:887)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:498)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1469)
at com.orm.SugarRecord.save(SugarRecord.java:280)
at com.orm.SugarRecord.save(SugarRecord.java:260)
at com.example.ves.gennaio3.firebase.FirebaseDatabaseHelper$8.onComplete(FirebaseDatabaseHelper.java:198)
at com.google.android.gms.tasks.zzj.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
it does not really matter how the remote node on Firebase is being called ...you have to rename the local table
Stores
toSTORE
- as it is being expected by theORM
's naming conventions. have checked the documentation, but there are no annotations available for mapping table names - as they would exist for Room. but when looking at the source code there seems to be a @Table annotation, which possibly would permit the mapping: