SQlite database corrupt , PHP and multithread C program accessing same database

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
18 messages Options
Reply | Threaded
Open this post in threaded view
|

SQlite database corrupt , PHP and multithread C program accessing same database

mon siong
 Hello
My sqlite database corrupt recently, I suspecting this is due to the two different instances of SQLIte running on unix . And two different global variables is used .
(By refering to the thread: http://mailinglists.sqlite.org/cgi-bin/mailman/private/sqlite-users/2016-May/066648.html)

We are using PHP to read and writes the database , and at the same time a multithread c program is performing read and write to the same database .

PHP is using sqlite3 library (http://php.net/manual/en/book.sqlite3.php)
and C program is handle the sqlite using Serialized.

Both of them are accessing the same DB at the same time . This can cause DB corrupt ?

RegardsBryan
_______________________________________________
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: SQlite database corrupt , PHP and multithread C program accessing same database

Simon Slavin-3

On 23 Jun 2016, at 3:52am, mon siong <[hidden email]> wrote:

> PHP is using sqlite3 library (http://php.net/manual/en/book.sqlite3.php)
> and C program is handle the sqlite using Serialized.
>
> Both of them are accessing the same DB at the same time . This can cause DB corrupt ?

No.  These two work correctly together.  You should get no corruption from using these two together.

Are you using any PRAGMA commands ?

What is the result of "PRAGMA journal_mode" ?

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: SQlite database corrupt , PHP and multithread C program accessing same database

mon siong

PHP use 3.7.7.1 and my c program use 3.8.4.3 . Different version of sqlite is fine ?
I tried WAL and Delete Journal Mode , both type cause the db to corrupt .

Under which scenario, two different global variables will be used ?
 

    On Thursday, June 23, 2016 11:13 AM, Simon Slavin <[hidden email]> wrote:
 

 
On 23 Jun 2016, at 3:52am, mon siong <[hidden email]> wrote:

> PHP is using sqlite3 library (http://php.net/manual/en/book.sqlite3.php)
> and C program is handle the sqlite using Serialized.
>
> Both of them are accessing the same DB at the same time . This can cause DB corrupt ?

No.  These two work correctly together.  You should get no corruption from using these two together.

Are you using any PRAGMA commands ?

What is the result of "PRAGMA journal_mode" ?

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
Reply | Threaded
Open this post in threaded view
|

Re: SQlite database corrupt , PHP and multithread C program accessing same database

Scott Hess
In reply to this post by Simon Slavin-3
On Wed, Jun 22, 2016 at 8:13 PM, Simon Slavin <[hidden email]> wrote:
> On 23 Jun 2016, at 3:52am, mon siong <[hidden email]> wrote:
>> PHP is using sqlite3 library (http://php.net/manual/en/book.sqlite3.php)
>> and C program is handle the sqlite using Serialized.
>>
>> Both of them are accessing the same DB at the same time . This can cause DB corrupt ?
>
> No.  These two work correctly together.  You should get no corruption from using these two together.

I wonder if it would be worthwhile to provide a PRAGMA (or function)
which returned a blob derived from the VFS pointer, perhaps hashed.
Then you could very easily verify if multiple higher-level libraries
are sharing the same underlying sqlite library, because that operation
would return the same result in both cases.

I'm suggesting to derive from the VFS pointer because if separate
sqlite libraries were sharing the same Unix VFS I think the POSIX
locking problem would not occur.  sqlite_source_id() is _really_
close, but technically could be identical for distinct sqlite
libraries linked into the same process.

Sorry if I'm too tired to make sense,
scott
_______________________________________________
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: SQlite database corrupt , PHP and multithread C program accessing same database

Scott Robison-2
In reply to this post by mon siong
On Jun 22, 2016 9:25 PM, "mon siong" <[hidden email]> wrote:
>
>
> PHP use 3.7.7.1 and my c program use 3.8.4.3 . Different version of
sqlite is fine ?
> I tried WAL and Delete Journal Mode , both type cause the db to corrupt .
>
> Under which scenario, two different global variables will be used ?

Is either process accessing the files over a networked file system or are
both processes on a single computer accessing a local file system?

>
>
>     On Thursday, June 23, 2016 11:13 AM, Simon Slavin <
[hidden email]> wrote:
>
>
>
> On 23 Jun 2016, at 3:52am, mon siong <[hidden email]> wrote:
>
> > PHP is using sqlite3 library (http://php.net/manual/en/book.sqlite3.php)
> > and C program is handle the sqlite using Serialized.
> >
> > Both of them are accessing the same DB at the same time . This can
cause DB corrupt ?
>
> No.  These two work correctly together.  You should get no corruption
from using these two together.

>
> Are you using any PRAGMA commands ?
>
> What is the result of "PRAGMA journal_mode" ?
>
> 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
_______________________________________________
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: SQlite database corrupt , PHP and multithread C program accessing same database

mon siong

Both processes on a single computer accessing a local file system. The sqlite file is store in USB drive , and I notice if the database corrupt , the journal or shm file is also corrupt . 
 

    On Thursday, June 23, 2016 12:48 PM, Scott Robison <[hidden email]> wrote:
 

 On Jun 22, 2016 9:25 PM, "mon siong" <[hidden email]> wrote:
>
>
> PHP use 3.7.7.1 and my c program use 3.8.4.3 . Different version of
sqlite is fine ?
> I tried WAL and Delete Journal Mode , both type cause the db to corrupt .
>
> Under which scenario, two different global variables will be used ?

Is either process accessing the files over a networked file system or are
both processes on a single computer accessing a local file system?

>
>
>    On Thursday, June 23, 2016 11:13 AM, Simon Slavin <
[hidden email]> wrote:
>
>
>
> On 23 Jun 2016, at 3:52am, mon siong <[hidden email]> wrote:
>
> > PHP is using sqlite3 library (http://php.net/manual/en/book.sqlite3.php)
> > and C program is handle the sqlite using Serialized.
> >
> > Both of them are accessing the same DB at the same time . This can
cause DB corrupt ?
>
> No.  These two work correctly together.  You should get no corruption
from using these two together.

>
> Are you using any PRAGMA commands ?
>
> What is the result of "PRAGMA journal_mode" ?
>
> 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
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: SQlite database corrupt , PHP and multithread C program accessing same database

mon siong

You have idea why the journal and shm file is corrupt  ?


From the previous Thread (http://mailinglists.sqlite.org/cgi-bin/mailman/private/sqlite-users/2016-January/063830.html),  you mention to use showdb to check the DB corrupt . Where to download the showdb program ?
 

    On Thursday, June 23, 2016 12:57 PM, mon siong <[hidden email]> wrote:
 

 
Both processes on a single computer accessing a local file system. The sqlite file is store in USB drive , and I notice if the database corrupt , the journal or shm file is also corrupt . 
 



       On Thursday, June 23, 2016 12:48 PM, Scott Robison <[hidden email]> wrote:
 

 On Jun 22, 2016 9:25 PM, "mon siong" <[hidden email]> wrote:
>
>
> PHP use 3.7.7.1 and my c program use 3.8.4.3 . Different version of
sqlite is fine ?
> I tried WAL and Delete Journal Mode , both type cause the db to corrupt .
>
> Under which scenario, two different global variables will be used ?

Is either process accessing the files over a networked file system or are
both processes on a single computer accessing a local file system?

>
>
>    On Thursday, June 23, 2016 11:13 AM, Simon Slavin <
[hidden email]> wrote:
>
>
>
> On 23 Jun 2016, at 3:52am, mon siong <[hidden email]> wrote:
>
> > PHP is using sqlite3 library (http://php.net/manual/en/book.sqlite3.php)
> > and C program is handle the sqlite using Serialized.
> >
> > Both of them are accessing the same DB at the same time . This can
cause DB corrupt ?
>
> No.  These two work correctly together.  You should get no corruption
from using these two together.

>
> Are you using any PRAGMA commands ?
>
> What is the result of "PRAGMA journal_mode" ?
>
> 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


_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: SQlite database corrupt , PHP and multithread C program accessing same database

Scott Robison-2
On Thu, Jun 23, 2016 at 11:08 AM, mon siong <[hidden email]> wrote:

>
> You have idea why the journal and shm file is corrupt  ?
>

My first thought was a remote file system. My next instinct is to suspect
the USB device or interface is suspect. Can you try it on an internal hard
drive? Is this on a virtual machine of any sort?


>
>
> From the previous Thread (
> http://mailinglists.sqlite.org/cgi-bin/mailman/private/sqlite-users/2016-January/063830.html),
> you mention to use showdb to check the DB corrupt . Where to download the
> showdb program ?
>
>
>     On Thursday, June 23, 2016 12:57 PM, mon siong <[hidden email]>
> wrote:
>
>
>
> Both processes on a single computer accessing a local file system. The
> sqlite file is store in USB drive , and I notice if the database corrupt ,
> the journal or shm file is also corrupt .
>
>
>
>
>        On Thursday, June 23, 2016 12:48 PM, Scott Robison <
> [hidden email]> wrote:
>
>
>  On Jun 22, 2016 9:25 PM, "mon siong" <[hidden email]> wrote:
> >
> >
> > PHP use 3.7.7.1 and my c program use 3.8.4.3 . Different version of
> sqlite is fine ?
> > I tried WAL and Delete Journal Mode , both type cause the db to corrupt .
> >
> > Under which scenario, two different global variables will be used ?
>
> Is either process accessing the files over a networked file system or are
> both processes on a single computer accessing a local file system?
>
> >
> >
> >    On Thursday, June 23, 2016 11:13 AM, Simon Slavin <
> [hidden email]> wrote:
> >
> >
> >
> > On 23 Jun 2016, at 3:52am, mon siong <[hidden email]> wrote:
> >
> > > PHP is using sqlite3 library (
> http://php.net/manual/en/book.sqlite3.php)
> > > and C program is handle the sqlite using Serialized.
> > >
> > > Both of them are accessing the same DB at the same time . This can
> cause DB corrupt ?
> >
> > No.  These two work correctly together.  You should get no corruption
> from using these two together.
> >
> > Are you using any PRAGMA commands ?
> >
> > What is the result of "PRAGMA journal_mode" ?
> >
> > 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
>
>
> _______________________________________________
> 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
>



--
Scott Robison
_______________________________________________
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: SQlite database corrupt , PHP and multithread C program accessing same database

mon siong
Thanks I will try internal hard drive. This is not virtual machine , my application is running on linux ARM .

1) Make sure I need to check SQLITE_OK before i proceed to perform next task 2) Move the sqlite file to Internal hard drive
2) Add sqlite_3_config error log callback to find out which code cause the DB corrupt3) use showdb to check the corrupted db . (where to download the showdb ? )

Please suggest me what else I need to do to prevent DB corrupt happen again (1 & 2) or if the db does corrupt how can i analyse which code is causing the db corrupt .




    On Friday, June 24, 2016 1:27 AM, Scott Robison <[hidden email]> wrote:
 

 On Thu, Jun 23, 2016 at 11:08 AM, mon siong <[hidden email]> wrote:

>
> You have idea why the journal and shm file is corrupt  ?
>

My first thought was a remote file system. My next instinct is to suspect
the USB device or interface is suspect. Can you try it on an internal hard
drive? Is this on a virtual machine of any sort?


>
>
> From the previous Thread (
> http://mailinglists.sqlite.org/cgi-bin/mailman/private/sqlite-users/2016-January/063830.html),
> you mention to use showdb to check the DB corrupt . Where to download the
> showdb program ?
>
>
>    On Thursday, June 23, 2016 12:57 PM, mon siong <[hidden email]>
> wrote:
>
>
>
> Both processes on a single computer accessing a local file system. The
> sqlite file is store in USB drive , and I notice if the database corrupt ,
> the journal or shm file is also corrupt .
>
>
>
>
>        On Thursday, June 23, 2016 12:48 PM, Scott Robison <
> [hidden email]> wrote:
>
>
>  On Jun 22, 2016 9:25 PM, "mon siong" <[hidden email]> wrote:
> >
> >
> > PHP use 3.7.7.1 and my c program use 3.8.4.3 . Different version of
> sqlite is fine ?
> > I tried WAL and Delete Journal Mode , both type cause the db to corrupt .
> >
> > Under which scenario, two different global variables will be used ?
>
> Is either process accessing the files over a networked file system or are
> both processes on a single computer accessing a local file system?
>
> >
> >
> >    On Thursday, June 23, 2016 11:13 AM, Simon Slavin <
> [hidden email]> wrote:
> >
> >
> >
> > On 23 Jun 2016, at 3:52am, mon siong <[hidden email]> wrote:
> >
> > > PHP is using sqlite3 library (
> http://php.net/manual/en/book.sqlite3.php)
> > > and C program is handle the sqlite using Serialized.
> > >
> > > Both of them are accessing the same DB at the same time . This can
> cause DB corrupt ?
> >
> > No.  These two work correctly together.  You should get no corruption
> from using these two together.
> >
> > Are you using any PRAGMA commands ?
> >
> > What is the result of "PRAGMA journal_mode" ?
> >
> > 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
>
>
> _______________________________________________
> 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
>



--
Scott Robison
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: SQlite database corrupt , PHP and multithread C program accessing same database

Scott Robison-2
On Thu, Jun 23, 2016 at 7:47 PM, mon siong <[hidden email]> wrote:

> Thanks I will try internal hard drive. This is not virtual machine , my
> application is running on linux ARM .
>
> 1) Make sure I need to check SQLITE_OK before i proceed to perform next
> task 2) Move the sqlite file to Internal hard drive
> 2) Add sqlite_3_config error log callback to find out which code cause the
> DB corrupt3) use showdb to check the corrupted db . (where to download the
> showdb ? )
>
> Please suggest me what else I need to do to prevent DB corrupt happen
> again (1 & 2) or if the db does corrupt how can i analyse which code is
> causing the db corrupt


It's hard to suggest what to do to prevent corruption when it seems you're
already doing those things.


> .
>
>
>
>
>     On Friday, June 24, 2016 1:27 AM, Scott Robison <
> [hidden email]> wrote:
>
>
>  On Thu, Jun 23, 2016 at 11:08 AM, mon siong <[hidden email]> wrote:
>
> >
> > You have idea why the journal and shm file is corrupt  ?
> >
>
> My first thought was a remote file system. My next instinct is to suspect
> the USB device or interface is suspect. Can you try it on an internal hard
> drive? Is this on a virtual machine of any sort?
>
>
> >
> >
> > From the previous Thread (
> >
> http://mailinglists.sqlite.org/cgi-bin/mailman/private/sqlite-users/2016-January/063830.html
> ),
> > you mention to use showdb to check the DB corrupt . Where to download the
> > showdb program ?
> >
> >
> >    On Thursday, June 23, 2016 12:57 PM, mon siong <[hidden email]>
> > wrote:
> >
> >
> >
> > Both processes on a single computer accessing a local file system. The
> > sqlite file is store in USB drive , and I notice if the database corrupt
> ,
> > the journal or shm file is also corrupt .
> >
> >
> >
> >
> >        On Thursday, June 23, 2016 12:48 PM, Scott Robison <
> > [hidden email]> wrote:
> >
> >
> >  On Jun 22, 2016 9:25 PM, "mon siong" <[hidden email]> wrote:
> > >
> > >
> > > PHP use 3.7.7.1 and my c program use 3.8.4.3 . Different version of
> > sqlite is fine ?
> > > I tried WAL and Delete Journal Mode , both type cause the db to
> corrupt .
> > >
> > > Under which scenario, two different global variables will be used ?
> >
> > Is either process accessing the files over a networked file system or are
> > both processes on a single computer accessing a local file system?
> >
> > >
> > >
> > >    On Thursday, June 23, 2016 11:13 AM, Simon Slavin <
> > [hidden email]> wrote:
> > >
> > >
> > >
> > > On 23 Jun 2016, at 3:52am, mon siong <[hidden email]> wrote:
> > >
> > > > PHP is using sqlite3 library (
> > http://php.net/manual/en/book.sqlite3.php)
> > > > and C program is handle the sqlite using Serialized.
> > > >
> > > > Both of them are accessing the same DB at the same time . This can
> > cause DB corrupt ?
> > >
> > > No.  These two work correctly together.  You should get no corruption
> > from using these two together.
> > >
> > > Are you using any PRAGMA commands ?
> > >
> > > What is the result of "PRAGMA journal_mode" ?
> > >
> > > 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
> >
> >
> > _______________________________________________
> > 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
> >
>
>
>
> --
> Scott Robison
> _______________________________________________
> 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
>



--
Scott Robison
_______________________________________________
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: SQlite database corrupt , PHP and multithread C program accessing same database

mon siong
Hi Scott

            Open the database without close can cause DB corrupt ?

    On Friday, June 24, 2016 12:24 PM, Scott Robison <[hidden email]> wrote:
 

 On Thu, Jun 23, 2016 at 7:47 PM, mon siong <[hidden email]> wrote:

> Thanks I will try internal hard drive. This is not virtual machine , my
> application is running on linux ARM .
>
> 1) Make sure I need to check SQLITE_OK before i proceed to perform next
> task 2) Move the sqlite file to Internal hard drive
> 2) Add sqlite_3_config error log callback to find out which code cause the
> DB corrupt3) use showdb to check the corrupted db . (where to download the
> showdb ? )
>
> Please suggest me what else I need to do to prevent DB corrupt happen
> again (1 & 2) or if the db does corrupt how can i analyse which code is
> causing the db corrupt


It's hard to suggest what to do to prevent corruption when it seems you're
already doing those things.


> .
>
>
>
>
>    On Friday, June 24, 2016 1:27 AM, Scott Robison <
> [hidden email]> wrote:
>
>
>  On Thu, Jun 23, 2016 at 11:08 AM, mon siong <[hidden email]> wrote:
>
> >
> > You have idea why the journal and shm file is corrupt  ?
> >
>
> My first thought was a remote file system. My next instinct is to suspect
> the USB device or interface is suspect. Can you try it on an internal hard
> drive? Is this on a virtual machine of any sort?
>
>
> >
> >
> > From the previous Thread (
> >
> http://mailinglists.sqlite.org/cgi-bin/mailman/private/sqlite-users/2016-January/063830.html
> ),
> > you mention to use showdb to check the DB corrupt . Where to download the
> > showdb program ?
> >
> >
> >    On Thursday, June 23, 2016 12:57 PM, mon siong <[hidden email]>
> > wrote:
> >
> >
> >
> > Both processes on a single computer accessing a local file system. The
> > sqlite file is store in USB drive , and I notice if the database corrupt
> ,
> > the journal or shm file is also corrupt .
> >
> >
> >
> >
> >        On Thursday, June 23, 2016 12:48 PM, Scott Robison <
> > [hidden email]> wrote:
> >
> >
> >  On Jun 22, 2016 9:25 PM, "mon siong" <[hidden email]> wrote:
> > >
> > >
> > > PHP use 3.7.7.1 and my c program use 3.8.4.3 . Different version of
> > sqlite is fine ?
> > > I tried WAL and Delete Journal Mode , both type cause the db to
> corrupt .
> > >
> > > Under which scenario, two different global variables will be used ?
> >
> > Is either process accessing the files over a networked file system or are
> > both processes on a single computer accessing a local file system?
> >
> > >
> > >
> > >    On Thursday, June 23, 2016 11:13 AM, Simon Slavin <
> > [hidden email]> wrote:
> > >
> > >
> > >
> > > On 23 Jun 2016, at 3:52am, mon siong <[hidden email]> wrote:
> > >
> > > > PHP is using sqlite3 library (
> > http://php.net/manual/en/book.sqlite3.php)
> > > > and C program is handle the sqlite using Serialized.
> > > >
> > > > Both of them are accessing the same DB at the same time . This can
> > cause DB corrupt ?
> > >
> > > No.  These two work correctly together.  You should get no corruption
> > from using these two together.
> > >
> > > Are you using any PRAGMA commands ?
> > >
> > > What is the result of "PRAGMA journal_mode" ?
> > >
> > > 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
> >
> >
> > _______________________________________________
> > 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
> >
>
>
>
> --
> Scott Robison
> _______________________________________________
> 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
>



--
Scott Robison
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: SQlite database corrupt , PHP and multithread C program accessing same database

Simon Slavin-3

On 26 Jun 2016, at 4:11pm, mon siong <[hidden email]> wrote:

>             Open the database without close can cause DB corrupt ?

Not if the software and hardware is working correctly.  The next time you open the database SQLite will work out that it wasn't closed correctly and will restore the database to good data.

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: SQlite database corrupt , PHP and multithread C program accessing same database

mon siong
Thanks Simon . I intend to do error log callback .  I want to terminate my program when an operation could potentially cause my DB to corrupt to identify which code actually cause this .

Which Result code that i need to capture which could potentially cause my DB to corrupt ?

SQLite Result Codes
 
|  
|   |  
SQLite Result Codes
   |  |

  |

 
 

    On Monday, June 27, 2016 12:19 AM, Simon Slavin <[hidden email]> wrote:
 

 
On 26 Jun 2016, at 4:11pm, mon siong <[hidden email]> wrote:

>            Open the database without close can cause DB corrupt ?

Not if the software and hardware is working correctly.  The next time you open the database SQLite will work out that it wasn't closed correctly and will restore the database to good data.

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
Reply | Threaded
Open this post in threaded view
|

Re: SQlite database corrupt , PHP and multithread C program accessing same database

Simon Slavin-3

On 27 Jun 2016, at 3:53pm, mon siong <[hidden email]> wrote:

> I intend to do error log callback .  I want to terminate my program when an operation could potentially cause my DB to corrupt to identify which code actually cause this .
>
> Which Result code that i need to capture

All API calls should return SQLITE_OK except for sqlite_step() which can return SQLITE_ROW or SQLITE_DONE too.  Any other code indicates a fault and your program when it sees them, before more harm is done.

> which could potentially cause my DB to corrupt ?

There are no SQLite calls which can corrupt your database.  Trapping result codes will not tell you which call caused database corruption.  It will only tell you that the database is already corrupt.

It is rare for any call to SQLite to cause database corruption.  Almost all causes of database corruption are either

A) faults in your program outside SQLite calls, for example part of your program overwriting memory that SQLite was using
B) faulty hardware

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: SQlite database corrupt , PHP and multithread C program accessing same database

Simon Slavin-3
Sorry, that should read

> All API calls should return SQLITE_OK except for sqlite_step() which can return SQLITE_ROW or SQLITE_DONE too.  Any other code indicates a fault and your program

... should crash ...

> when it sees them, before more harm is done.

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: SQlite database corrupt , PHP and multithread C program accessing same database

mon siong
Yes , I always do this check before i proceed next step .  if(rc != SQLITE_OK){ }

I just crash my database with 1 thread keep reading , another thread keep inserting . Here is how i open the DB connection .

rc = sqlite3_open_v2(DEFAULT_FAILTS_DB, &db,SQLITE_OPEN_READWRITE|SQLITE_OPEN_SHAREDCACHE|SQLITE_OPEN_FULLMUTEX,NULL);
 

    On Monday, June 27, 2016 11:34 PM, Simon Slavin <[hidden email]> wrote:
 

 Sorry, that should read

> All API calls should return SQLITE_OK except for sqlite_step() which can return SQLITE_ROW or SQLITE_DONE too.  Any other code indicates a fault and your program

... should crash ...

> when it sees them, before more harm is done.

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
Reply | Threaded
Open this post in threaded view
|

Re: SQlite database corrupt , PHP and multithread C program accessing same database

Simon Slavin-3

On 28 Jun 2016, at 4:24pm, mon siong <[hidden email]> wrote:

> Yes , I always do this check before i proceed next step .  if(rc != SQLITE_OK){ }

Very good.

> I just crash my database with 1 thread keep reading , another thread keep inserting . Here is how i open the DB connection .
>
> rc = sqlite3_open_v2(DEFAULT_FAILTS_DB, &db,SQLITE_OPEN_READWRITE|SQLITE_OPEN_SHAREDCACHE|SQLITE_OPEN_FULLMUTEX,NULL);

I still cannot think of a reason that your programs should corrupt the database.  I can only guess that you have bad hardware somewhere.

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: SQlite database corrupt , PHP and multithread C program accessing same database

LincolnBurrows
This post has NOT been accepted by the mailing list yet.
In reply to this post by mon siong
Sometimes, the corruption is only or mostly in indexes, in which case it would be possible to get some or most records by trying to dump the entire database with .dump, and use those commands to create a new database. However, this is not always possible. the easiest and most reliable way is to restore the database file from the backup. for more information see Causes Behind SQLite Corruption & How to Repair SQLite Databases