Re: [sqlite] Peculiar activity in an SQLite-using InDesign plug-in on the Macintosh

2011-08-05 Thread john darnell
 
 Not that I think they're the problem, but just for completeness, do some error
 reporting on _initialize and _open and _prepare too.
 
 Simon.

Sigh.  I removed the error checking from the email because I am of the same 
opinion, and because I wanted to provide as simple a piece of code as I could.

Thanks for what help you gave.  It pointed me in the right direction, I think.
John
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Peculiar activity in an SQLite-using InDesign plug-in on the Macintosh

2011-08-05 Thread john darnell
 
 Thanks for what help you gave.  It pointed me in the right direction, I think.

Simon:

   The problem is resolved.  It turns out that I was calling a function to save 
data to a child table.  That function had a prepare statement that had never 
been finalized.  

   Though it's embarrassing to admit my dumb mistakes, I kinda feel like you 
deserve to know since you provided so much assistance.  Thanks again, and if 
you are ever in Brookfield, MO, lunch is on me.

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


Re: [sqlite] Peculiar activity in an SQLite-using InDesign plug-in on the Macintosh

2011-08-05 Thread Simon Slavin

On 5 Aug 2011, at 4:34pm, john darnell wrote:

   The problem is resolved.  It turns out that I was calling a function to 
 save data to a child table.  That function had a prepare statement that had 
 never been finalized.  
 
   Though it's embarrassing to admit my dumb mistakes, I kinda feel like you 
 deserve to know

John, we're all wasted days chasing the wrong cause of an error, and it's great 
to know you've figured out the problem.  Happy hacking.

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


[sqlite] Peculiar activity in an SQLite-using InDesign plug-in on the Macintosh

2011-08-04 Thread john darnell
Hello people.

I apologize for the vagueness of this email, but all I can really hope for is 
some ideas to pursue, I think.

I have an InDesign plug-in that scans numerous InDesign documents (there are no 
limits, but a common number would be around 100) for certain names and stores 
that information plus the page number in an SQLite table.   Each record is 
stored as it is found so there is no massive storage even at the end of a block 
or anything.

The name of the DB file I use is IndexData.db.  On certain versions (but not 
all versions) of the plugin, during the processing, an IndexData.db-Journal 
file is created.  It is always empty at the end of a run.

I have had several instances where I scan several documents and build up, say, 
1000 records in my SQLite table.  I then select several more documents for 
scanning and the number of records are halved in my SQLite table.  This is 
always associated with the advent of a system File Open dialog that is empty of 
all files in the folder I am working, when it should have between 60 and 100 
files.

Has anyone working a Mac ever experienced something like this?

John A.M. Darnell
Senior Programmer
john.darn...@walsworth.com
660.258.2104 ext.4108 OFFICE
www.walsworth.com




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


Re: [sqlite] Peculiar activity in an SQLite-using InDesign plug-in on the Macintosh

2011-08-04 Thread Simon Slavin

On 4 Aug 2011, at 8:28pm, john darnell wrote:

 The name of the DB file I use is IndexData.db.  On certain versions (but not 
 all versions) of the plugin, during the processing, an IndexData.db-Journal 
 file is created. It is always empty at the end of a run.

I'm not sure where you close your database handle, and what you mean by 'end of 
a run', but when you have used sqlite3_close() to close all handles to a SQLite 
database that file should no longer exist.  If you still have a file with that 
name on your disk, something has gone wrong, and you should figure out why.  
Can you make absolutely sure sqlite3_close() has been called correctly and does 
not return an error ?

 I have had several instances where I scan several documents and build up, 
 say, 1000 records in my SQLite table.  I then select several more documents 
 for scanning and the number of records are halved in my SQLite table.  This 
 is always associated with the advent of a system File Open dialog that is 
 empty of all files in the folder I am working, when it should have between 60 
 and 100 files.
 
 Has anyone working a Mac ever experienced something like this?

Not me.  Please use Disk Utility to check your disk for corrupt structure.

Things like you describe remind me of cases where the OS has run out of file 
handles but I can't imagine this happening under OS X.

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


Re: [sqlite] Peculiar activity in an SQLite-using InDesign plug-in on the Macintosh

2011-08-04 Thread john darnell
 
 I'm not sure where you close your database handle, and what you mean by 'end 
 of
 a run', but when you have used sqlite3_close() to close all handles to a 
 SQLite
 database that file should no longer exist.  If you still have a file with 
 that name on
 your disk, something has gone wrong, and you should figure out why.  Can you
 make absolutely sure sqlite3_close() has been called correctly and does not 
 return
 an error ?

My apologies for my lack of clarity.  What I mean by end of a run is simply 
when I exit InDesign (and all plugins attached thereto).

I close the database frequently--at the end of the module where it is opened.

The documentation says that when I close a database transactions in progress 
are rolled back, but I cannot find a way of testing for whether a transaction 
is completed.  Is that the role of the finalize call?

Here's the sequence of events I use when I use sqlite3_close:

Result = sqlite3_step(ResultStmt);
if(Result != SQLITE_DONE)
{
Do some error/loop stuff as appropriate
}

sqlite3_finalize(ResultStmt);
sqlite3_close(db_ptr);
sqlite3_shutdown();

If there is a better/safer method, please let me know.

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


Re: [sqlite] Peculiar activity in an SQLite-using InDesign plug-in on the Macintosh

2011-08-04 Thread Simon Slavin

On 4 Aug 2011, at 11:02pm, john darnell wrote:

 The documentation says that when I close a database transactions in progress 
 are rolled back, but I cannot find a way of testing for whether a transaction 
 is completed.

SQLite does not do any tasks in the background.  There's no need to pause for 
something to complete.  There are two transaction models you can use:

A) Declared transactions explicitly using BEING TRANSACTION and END TRANSACTION 
with any number of operations between the two.
B) Do an INSERT or UPDATE operation without having used BEGIN TRANSACTION.

If you do (B), then SQLite automatically wraps that single operation in its own 
transaction.  This is slower than (A) if you're making lots of changes since it 
involves more work.

So if you didn't already know about transactions, you were doing (B).

   Is that the role of the finalize call?

The finalize call completes the operation you're finalizing.  You do it for 
each _prepare, and you should check the returned value to see you didn't get an 
error.

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


Re: [sqlite] Peculiar activity in an SQLite-using InDesign plug-in on the Macintosh

2011-08-04 Thread john darnell
 Can you
 make absolutely sure sqlite3_close() has been called correctly and does not 
 return
 an error ?

As a matter of fact, Simon, for some reason, whenever I call it in this 
particular function (and I call this function a lot), it returns an error.  The 
error is (both surprisingly and unsurprisingly) unable to close due to 
unfinalized statements.

Here's the code, as simplified as I know how to make it (you will see that the 
one prepared statement is finalized):

   int  Result;

   std::string InsertStatement = Insert into blah blah blah;  //  The Insert 
statement works whenever I can get a connection, which is the first 523 
attempts.

   Result = sqlite3_initialize();

   sqlite3 *db_ptr;
   Result = 0;

   Result = sqlite3_open_v2(DBEnginePath, db_ptr, SQLITE_OPEN_READWRITE, 
NULL); 

   sqlite3_stmt *ResultStmt;
   Result = sqlite3_prepare_v2(db_ptr, InsertStatement.c_str(), -1, 
ResultStmt, NULL);


   Result = sqlite3_step(ResultStmt);
   if((Result != SQLITE_DONE)  (Result != SQLITE_ROW))
   {
Do some error stuff
   }

  sqlite3_reset(   ResultStmt);

//  based on your comments earlier, the tests were added as you see here.
   Result = sqlite3_finalize(ResultStmt);
   if(Result != SQLITE_OK)
   {
   fprintf(stderr, Did not finalize):   //  Never saw this
   }

   sqlite3_close(   db_ptr);
   if(Result != SQLITE_OK)
   {
   fprintf(stderr, failed to close sqlite db ptr):   //  As far as I can 
tell, this msg showed up with the processing of every record.
   }


I'm not sure where I've gone wrong.

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


Re: [sqlite] Peculiar activity in an SQLite-using InDesign plug-in on the Macintosh

2011-08-04 Thread Simon Slavin

On 5 Aug 2011, at 1:05am, john darnell wrote:

 As a matter of fact, Simon, for some reason, whenever I call it in this 
 particular function (and I call this function a lot), it returns an error.  
 The error is (both surprisingly and unsurprisingly) unable to close due to 
 unfinalized statements.
 
 Here's the code, as simplified as I know how to make it (you will see that 
 the one prepared statement is finalized):

And now you're beyond what I know so I help someone else can help you.

Not that I think they're the problem, but just for completeness, do some error 
reporting on _initialize and _open and _prepare too.

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