Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip error values and insert into tables #266

Open
SrujanMungara opened this issue May 13, 2022 · 8 comments
Open

Skip error values and insert into tables #266

SrujanMungara opened this issue May 13, 2022 · 8 comments

Comments

@SrujanMungara
Copy link

SrujanMungara commented May 13, 2022

Do we have Insert Ignore option in SqfEntity?

Requirement:
I have 3 unique values in a statement, 4th value is a duplicate, followed by 2 unique values. When using batchCommit for insertion, rollback is happening. If tried to insert without batchStart and batchCommit, only first 3 values are inserted and remaining values are getting skipped. I need only 4th value to be skipped and all the unique 5 values to insert into the table.

Can u please suggest a solution for the above issue? @hhtokpinar

@SrujanMungara SrujanMungara changed the title Skip error values and insert into DB Skip error values and insert into tables May 13, 2022
@hhtokpinar
Copy link
Owner

Hi,
I've added optional parameters into saveAll method and batchCommit. re-generate the models after upgrading to the latest version

  MyDbModel.batchCommit({bool? exclusive, bool? noResult, bool? continueOnError})
  .... 
  saveAll({bool? exclusive, bool? noResult, bool? continueOnError})


@SrujanMungara
Copy link
Author

can u please update the same method for upsert also?

@hhtokpinar
Copy link
Owner

updated upsertAll method too

@SrujanMungara
Copy link
Author

I need only few fields of the table to be updated and it has to be done for n number of values, looping, which i need to perform using single upsert function instead of upsertall/saveall

@hhtokpinar
Copy link
Owner

hhtokpinar commented May 17, 2022

You could use the single functions like save() or upsert like below

MyDbModel().batchStart() 
// do single save/upsert
item1.save(ignoreBatch:false)
item2.upsert(...., ignoreBatch:false)
... 
MyDbModel().batchCommit(continueOnError:true)

@SrujanMungara
Copy link
Author

SrujanMungara commented May 17, 2022

@hhtokpinar

If i use ignoreBatch: false, when an error value is hit, all the values are getting rolledback and table has 0 values. But if i use Ignorebatch: true, the values are getting inserted till the error value is hit and is getting exited from loop with the next correct values not inserting.

Both the processes are happening when using batchCommit(continueOnError: true)

@SrujanMungara
Copy link
Author

@hhtokpinar

Any update please

@SrujanMungara
Copy link
Author

@hhtokpinar

Any update please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants