Sqlite3 Data Base write failure cases.

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Sqlite3 Data Base write failure cases.

Prajeesh Prakash
Hi Team,

What are the possible failure cases of DB write in case of single connection. Because in my application i needs to handle those cases. Can anyone help me for the same.




Thank you
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Sqlite3 Data Base write failure cases.

Simon Slavin-3
On 17 Dec 2018, at 9:01am, Prajeesh Prakash <[hidden email]> wrote:

> What are the possible failure cases of DB write in case of single connection. Because in my application i needs to handle those cases. Can anyone help me for the same.

You state that you're using a single connection.  I will assume your software accesses the database only via a single thread, and therefore there can be no contention for using that connection.  I will also assume no other program is accessing the database at the same time as the software you're concerned about.  If those things are not true, post again explaining the exceptions.

For failure cases which can be detected by your software ...

Record the value returned from your _step() or _exec() call.  Check to see whether this value is SQLITE_OK ( which is 0 ).  If it is, the command succeeded.  If it isn't, it failed, and your program should report the failure and react to it.

It's that simple: check to see that the result is 0, and everything else is a failure.  You can unpick this slightly, and detect database rule violations (e.g. SQLITE_CONSTRAINT == 19 , indicating that you've broken database rules you included in the schema) but since your software is meant to be preventing all that, it really doesn't matter what the value is, just report or log it and quit.

For a list of result codes see

<https://sqlite.org/c3ref/c_abort.html>

If the command failed, it never the right thing to do to just have your software try again.

For failure cases which cannot be detected by your software, read

<https://www.sqlite.org/howtocorrupt.html>

Simon.


_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Sqlite3 Data Base write failure cases.

Prajeesh Prakash
Hi Simon Slavin,
Thank you for the reply. Yes I am using single thread and single connection. Can you tell me what happen if i try with multiple thread and single connection to write the data (Multiple thread trying to write into DB will it follow the serialization because of the FULLMUTEX and do the write operation one by one).

Thank You

> On December 17, 2018 at 3:16 PM Simon Slavin <[hidden email]> wrote:
>
>
> On 17 Dec 2018, at 9:01am, Prajeesh Prakash <[hidden email]> wrote:
>
> > What are the possible failure cases of DB write in case of single connection. Because in my application i needs to handle those cases. Can anyone help me for the same.
>
> You state that you're using a single connection.  I will assume your software accesses the database only via a single thread, and therefore there can be no contention for using that connection.  I will also assume no other program is accessing the database at the same time as the software you're concerned about.  If those things are not true, post again explaining the exceptions.
>
> For failure cases which can be detected by your software ...
>
> Record the value returned from your _step() or _exec() call.  Check to see whether this value is SQLITE_OK ( which is 0 ).  If it is, the command succeeded.  If it isn't, it failed, and your program should report the failure and react to it.
>
> It's that simple: check to see that the result is 0, and everything else is a failure.  You can unpick this slightly, and detect database rule violations (e.g. SQLITE_CONSTRAINT == 19 , indicating that you've broken database rules you included in the schema) but since your software is meant to be preventing all that, it really doesn't matter what the value is, just report or log it and quit.
>
> For a list of result codes see
>
> <https://sqlite.org/c3ref/c_abort.html>
>
> If the command failed, it never the right thing to do to just have your software try again.
>
> For failure cases which cannot be detected by your software, read
>
> <https://www.sqlite.org/howtocorrupt.html>
>
> Simon.
>
>
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users