Skip to content
Siminov Framework edited this page Jan 17, 2016 · 10 revisions

Save Or Update

Android API: Save

    public final void saveOrUpdate() throws DatabaseException;

Note

  • If tuple is not present in table then it will insert it into table else it will update the tuple.
Android Sample: Save Or Update
    Book c = new Book();
    c.setTitle(Book.BOOK_TYPE_C);
    c.setDescription(applicationContext.getString(R.string.c_description));
    c.setAuthor(applicationContext.getString(R.string.c_author));
    c.setLink(applicationContext.getString(R.string.c_link));
  
    try {
        c.saveOrUpdate();
    } catch(DatabaseException de) {
		//Log it.
    }

iOS API: Save Or Update

    - (void)saveOrUpdate;

Note

  • If tuple is not present in table then it will insert it into table else it will update the tuple.
iOS Sample: Save Or Update
    Book *c = [[Book alloc] init];
    [c setTitle:[Book BOOK_TYPE_C]];
    [c setDescription:@"c_description"];
    [c setAuthor:@"c_author"];
    [c setLink:@"c_link"];
  
    @try {
        [c saveOrUpdate];
    } @catch(SICDatabaseException *databaseException) {
		//Log it.
    }

Windows API: Save Or Update

    public void SaveOrUpdate();

Note

  • If tuple is not present in table then it will insert it into table else it will update the tuple.
Windows Sample: Save Or Update
    Book c = new Book();
    c.SetTitle(Book.BOOK_TYPE_C);
    c.SetDescription("c_description");
    c.SetAuthor("c_author");
    c.SetLink("c_link");
  
    try 
    {
        c.SaveOrUpdate();
    } 
    catch(DatabaseException de) 
    {
		//Log it.
    }

JavaScript API: Save Or Update

    - this.saveOrUpdate = function() {};
    - this.saveOrUpdate = function(callback, transaction) {};
JavaScript Sample: Save Or Update
            /** Save Or Update Sample **/

    var c = new Book();
    c.setTitle(Book.BOOK_TYPE_C);
    c.setDescription("c_description");
    c.setAuthor("c_author");
    c.setLink("c_link");
 
    try {
        c.saveOrUpdate();
    } catch(DatabaseException de) {
		//Log it.
    }
            /** Save Or Update Async Sample **/

    var c = new Book();
    c.setTitle(Book.BOOK_TYPE_C);
    c.setDescription("c_description");
    c.setAuthor("c_author");
    c.setLink("c_link");
 
    var callback = new Callback();
    callback.onSuccess = function() {

    }
   
    c.saveOrUpdateAsync(callback);
            /** Save Or Update Async Transaction Sample **/

    var c = new Book();
    c.setTitle(Book.BOOK_TYPE_C);
    c.setDescription("c_description");
    c.setAuthor("c_author");
    c.setLink("c_link");
 
    var callback = new Callback();
    callback.onExecute = function(transaction) {

        var saveOrUpdateCallback = new Callback();
        saveOrUpdateCallback.onSuccess = function() {

        }

        c.saveOrUpdateAsync(saveOrUpdateCallback, transaction);
    }

    callback.onSuccess = function() {

    }
   
    var databaseDescriptor = c.getDatabaseDescriptor();
    Database.beginTransactionAsync(databaseDescriptor, callback);