Re: [sqlite] help to get the value of file change counter

2011-09-13 Thread Michael Stephenson
Just a guess, but you may have to use one of the Pager functions to examine
the buffer for database page 1, which is always pinned in memory and which
represents the first  bytes of the database file.

-Original Message-
From: sqlite-users-boun...@sqlite.org
[mailto:sqlite-users-boun...@sqlite.org] On Behalf Of Akash Agrawal
Sent: Tuesday, September 13, 2011 9:08 AM
To: General Discussion of SQLite Database; Simon Slavin
Subject: Re: [sqlite] help to get the value of file change counter

hii

thank you for suggestion.
but when reading the value from sqlite header it printing same value no
change i can see i pasting the c++ code below

/CODE***
*/
#include 
#include 
using namespace std;

int main ()
{

  FILE * pFile;
  int c;

  int n = 0;
  char fcc[35] = {0};
  int i = 0;
  int j =0;
  while(j < 4)
  {
  int n = 0;
  sleep(10);  // sleep is used so that i can make any change in
database so that value of counter will change

  pFile=fopen ("demo.sqlite","r");   //demo.sqlite is my sqlite  file

  if (pFile==NULL)
  {
  perror ("Error opening file");
  exit(-1);
  }
  else
  {
  do
  {
  c = fgetc (pFile);
  n++;

  if(n >23 && n < 28)
  {
  printf("%x",c);// printing the value of header whic in
hex format
  i++;
  }
  }while (c != EOF);
  fclose (pFile);
  cout< wrote:

>
> On 12 Sep 2011, at 1:35pm, Richard Hipp wrote:
>
> > On Mon, Sep 12, 2011 at 8:02 AM, Igor Tandetnik 
> > 
> wrote:
> >
> >> Simon Slavin  wrote:
> >>> 
> >>>
> >>> int sqlite3_total_changes(sqlite3*);
> >>>
> >>> My understanding (which might be wrong) is that this count 
> >>> includes all changes made by all connections to that database: not 
> >>> only changes made using your connection but also chances made by
> another
> >>> computer, process, or thread.
> >>
> >> I'm 99% sure your understanding is wrong [snip]
> >
> > Igor is right.  The sqlite3_total_changes() function only reports 
> > the
> number
> > of rows that have been changed by the same database connection that
> issued
> > the sqlite3_total_changes() call.
>
> Okay,  I find that page in the documentation ambiguous then.  Could 
> that sentence, or something like it, be added for clarity ?
>
> > There is no API for accessing the database change counter.  But you 
> > can
> read
> > it yourself by looking at bytes 24-27 of the database file.
>
> How hard would it be to implement this safely using sqlite3's own 
> filehandle to the database file ?  I know we're meant to treat 
> sqlite3* as a black box but could it be done relatively safely, with a 
> warning that it might fail under certain weird conditions ?  Would one 
> use
> sqlite3_file_control() ?
>
> Alternatively, suppose one was doing a lot of in-memory caching for a 
> SQLite database but didn't want to block other apps from accessing it.  
> Is there a clean way to say "Has anyone been messing with this but me ?" ?
>
> Simon.
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>



-- 

Akash Agrawal
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] help to get the value of file change counter

2011-09-13 Thread Akash Agrawal
hii

thank you for suggestion.
but when reading the value from sqlite header it printing same value no
change i can see i pasting the c++ code below

/CODE/
#include 
#include 
using namespace std;

int main ()
{

  FILE * pFile;
  int c;

  int n = 0;
  char fcc[35] = {0};
  int i = 0;
  int j =0;
  while(j < 4)
  {
  int n = 0;
  sleep(10);  // sleep is used so that i can make any change in
database so that value of counter will change

  pFile=fopen ("demo.sqlite","r");   //demo.sqlite is my sqlite  file

  if (pFile==NULL)
  {
  perror ("Error opening file");
  exit(-1);
  }
  else
  {
  do
  {
  c = fgetc (pFile);
  n++;

  if(n >23 && n < 28)
  {
  printf("%x",c);// printing the value of header whic in
hex format
  i++;
  }
  }while (c != EOF);
  fclose (pFile);
  cout< wrote:

>
> On 12 Sep 2011, at 1:35pm, Richard Hipp wrote:
>
> > On Mon, Sep 12, 2011 at 8:02 AM, Igor Tandetnik 
> wrote:
> >
> >> Simon Slavin  wrote:
> >>> 
> >>>
> >>> int sqlite3_total_changes(sqlite3*);
> >>>
> >>> My understanding (which might be wrong) is that this count includes all
> >>> changes made by all connections to that database: not
> >>> only changes made using your connection but also chances made by
> another
> >>> computer, process, or thread.
> >>
> >> I'm 99% sure your understanding is wrong [snip]
> >
> > Igor is right.  The sqlite3_total_changes() function only reports the
> number
> > of rows that have been changed by the same database connection that
> issued
> > the sqlite3_total_changes() call.
>
> Okay,  I find that page in the documentation ambiguous then.  Could that
> sentence, or something like it, be added for clarity ?
>
> > There is no API for accessing the database change counter.  But you can
> read
> > it yourself by looking at bytes 24-27 of the database file.
>
> How hard would it be to implement this safely using sqlite3's own
> filehandle to the database file ?  I know we're meant to treat sqlite3* as a
> black box but could it be done relatively safely, with a warning that it
> might fail under certain weird conditions ?  Would one use
> sqlite3_file_control() ?
>
> Alternatively, suppose one was doing a lot of in-memory caching for a
> SQLite database but didn't want to block other apps from accessing it.  Is
> there a clean way to say "Has anyone been messing with this but me ?" ?
>
> Simon.
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>



-- 

Akash Agrawal
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] help to get the value of file change counter

2011-09-12 Thread Simon Slavin

On 12 Sep 2011, at 1:35pm, Richard Hipp wrote:

> On Mon, Sep 12, 2011 at 8:02 AM, Igor Tandetnik  wrote:
> 
>> Simon Slavin  wrote:
>>> 
>>> 
>>> int sqlite3_total_changes(sqlite3*);
>>> 
>>> My understanding (which might be wrong) is that this count includes all
>>> changes made by all connections to that database: not
>>> only changes made using your connection but also chances made by another
>>> computer, process, or thread.
>> 
>> I'm 99% sure your understanding is wrong [snip]
> 
> Igor is right.  The sqlite3_total_changes() function only reports the number
> of rows that have been changed by the same database connection that issued
> the sqlite3_total_changes() call.

Okay,  I find that page in the documentation ambiguous then.  Could that 
sentence, or something like it, be added for clarity ?

> There is no API for accessing the database change counter.  But you can read
> it yourself by looking at bytes 24-27 of the database file.

How hard would it be to implement this safely using sqlite3's own filehandle to 
the database file ?  I know we're meant to treat sqlite3* as a black box but 
could it be done relatively safely, with a warning that it might fail under 
certain weird conditions ?  Would one use sqlite3_file_control() ?

Alternatively, suppose one was doing a lot of in-memory caching for a SQLite 
database but didn't want to block other apps from accessing it.  Is there a 
clean way to say "Has anyone been messing with this but me ?" ?

Simon.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] help to get the value of file change counter

2011-09-12 Thread Richard Hipp
On Mon, Sep 12, 2011 at 8:02 AM, Igor Tandetnik  wrote:

> Simon Slavin  wrote:
> > 
> >
> > int sqlite3_total_changes(sqlite3*);
> >
> > My understanding (which might be wrong) is that this count includes all
> changes made by all connections to that database: not
> > only changes made using your connection but also chances made by another
> computer, process, or thread.
>
> I'm 99% sure your understanding is wrong, and this function only reports
> changes made by the connection passed in as a parameter. There is simply no
> machinery in SQLite that would have allowed one connection to indicate to
> another how many changes it has made.
>

Igor is right.  The sqlite3_total_changes() function only reports the number
of rows that have been changed by the same database connection that issued
the sqlite3_total_changes() call.

There is no API for accessing the database change counter.  But you can read
it yourself by looking at bytes 24-27 of the database file.

Caution: if you open and close the database file on unix using some
mechanism other than SQLite and if you have other threads using SQLite at
the same time, then you will likely corrupt the database file. This is a
design bug in posix advisory locking which is impossible for us to work
around.  See paragraph 2.2 of http://www.sqlite.org/howtocorrupt.html for
further information.



> --
> Igor Tandetnik
>
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>



-- 
D. Richard Hipp
d...@sqlite.org
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] help to get the value of file change counter

2011-09-12 Thread Igor Tandetnik
Simon Slavin  wrote:
> 
> 
> int sqlite3_total_changes(sqlite3*);
> 
> My understanding (which might be wrong) is that this count includes all 
> changes made by all connections to that database: not
> only changes made using your connection but also chances made by another 
> computer, process, or thread. 

I'm 99% sure your understanding is wrong, and this function only reports 
changes made by the connection passed in as a parameter. There is simply no 
machinery in SQLite that would have allowed one connection to indicate to 
another how many changes it has made.
-- 
Igor Tandetnik

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] help to get the value of file change counter

2011-09-12 Thread Akash Agrawal
this is very helpful for me

thank  you
-- 
Regards
Akash Agrawal

On Mon, Sep 12, 2011 at 12:39 PM, Simon Slavin  wrote:

>
> On 12 Sep 2011, at 5:08am, Akash Agrawal wrote:
>
> > I'd like to be able to tell whether a SQLite database file has been
> updated
> > in any way. How would I go about implementing that?
> >
> > I find about some file change counter but how i will get the value of
> file
> > change counter through C program
>
> 
>
> int sqlite3_total_changes(sqlite3*);
>
> My understanding (which might be wrong) is that this count includes all
> changes made by all connections to that database: not only changes made
> using your connection but also chances made by another computer, process, or
> thread.
>
> Actually it might be worth clarifying the text on that page to state that
> explicitly.
>
> Simon.
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] help to get the value of file change counter

2011-09-12 Thread Simon Slavin

On 12 Sep 2011, at 5:08am, Akash Agrawal wrote:

> I'd like to be able to tell whether a SQLite database file has been updated
> in any way. How would I go about implementing that?
> 
> I find about some file change counter but how i will get the value of file
> change counter through C program



int sqlite3_total_changes(sqlite3*);

My understanding (which might be wrong) is that this count includes all changes 
made by all connections to that database: not only changes made using your 
connection but also chances made by another computer, process, or thread.

Actually it might be worth clarifying the text on that page to state that 
explicitly.

Simon.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users