Nasir
Nasir

Reputation: 750

Azure offline sqlite store sync questions related to primary key, data types mapping

I am working on azure offline sync using sqlite. and have couple of questions. I am new to android and azure

  1. Is it possible to define primary_key in local sqlite store (When i am working on azure apis)? Because i see in android column types supported are very few. What if i need a primary key which would help to work on offline data (may be for performance or any reason)

    ColumnDataType: Boolean, Integer, Real, String, Date, DateTimeOffset, Other localStore.defineTable("FR_Tbl_Items",tableDefinition);

  2. Another problem i am facing is, As per ToDoItem example of microsoft, First i should have one class for table (ToDoItem) define all the columns then use it to create MobileServiceTable object to fetch the data from azure. But if we need offline sync again we have to use defineTable function. This doesn't take ToDoItem class as argument. We have to define again in hash map and pass it. Why is it like this? Or is there any other way to do it?

private MobileServiceTable mToDoTable; and public void defineTable(String tableName, Map columns)

EDIT: I know sqlite supports primary key, but looks like azure doesn't support. I don't see any provision to create table with primary key

private void define_Tbl_ChangedTable_Table(DBManager localStore) throws MobileServiceLocalStoreException {
    Map<String, ColumnDataType> tableDefinition = new HashMap<String, ColumnDataType>();
    tableDefinition.put("id", ColumnDataType.String);
    tableDefinition.put("lastupdatetime", ColumnDataType.Date);
    localStore.defineTable("Tbl_ChangedTable", tableDefinition);
}
  1. Is there any place i can see data type mapping between Azure/Android/Sqlite ? Azure shows Number, Data as column type, What i should use in Table class for Number (can i use Number,Date classes of Java) then finally what data type i should chose from ColumnDataType

Upvotes: 0

Views: 564

Answers (2)

Will Shao - MSFT
Will Shao - MSFT

Reputation: 1207

@Nasir,

If you'd like to use Azure Table Storage to store your data, the solution will become easy for your Question 1 & Question 2,as well as you will not occur the third question.

Actually, we can use primary key on Azure SQL database. However if you wants to sync up the primary key to Azure SQL database, this key should be a field not as the primary key on Azure SQL database.

Presume you use the azure Table Storage, you will sync up your data and redefine all the columns when you store your data into it. Because Azure Table storage is No-SQL datastore, it can be match your requirement. Also, you can store your primary key value as partition Key or row key in azure storage. Please refer to this documents about how to use Azure Table storage in Azure mobile Service . If I misunderstood, please let me know.

Upvotes: 1

Peter Pan
Peter Pan

Reputation: 24128

For Question 1, you can define primary key in local store. There were the similar threads had been answered, please refer to Is it possible to apply primary key on the text fields in android database and how to add primary key to text datatype in android sqlite?. And from SQLite offical document http://www.sqlite.org/datatype3.html, it only support 5 kind of data type.

Continue for Question 3, SQLite Datatypes NULL, INTEGER, REAL, TEXT and BLOB are respectively mapping Java datatypes null, int & long(according to the magnitude of the integer value), double, String and using the JDBC function ResultSet.getBinaryStream(). If you want to save or read other datatypes, you just need to serialize or deserialize between type String and the other type with SQLite TEXT or BLOB type.

For Question 2, The MobileService APIs designed by MS Azure for Android Client & offline data sync are based on the best practise with the languge feature in the long term support. So MS supply the guideline document to help developers using them easily and avoid implementing the same features byself, please refer to https://azure.microsoft.com/en-us/documentation/articles/mobile-services-android-how-to-use-client-library/ and https://azure.microsoft.com/en-us/documentation/articles/mobile-services-android-get-started-offline-data/ to try to do it.

Upvotes: 2

Related Questions