Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2011-10

Problem with access rights in Windows Mobile?

5 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Arí Ricardo Ody

I wrote an application in Lazarus 0.9.30 with SQLite 3(I used only TSQLite3Dataset). Everything's fine 'till this morning. The application is written to run under WinCE arm devices.

I wrote a method to archive the SQLite 3 database via TZipper. I reviewed the code logic dozen of times and it seems that there is no TSQLite3Dataset open. The code of my method is:

 procedure TfrmZiparBanco.spbtnZiparClick(Sender: TObject);
 var Zipper : TZipper;
 begin
 Zipper := TZipper.Create;
 Zipper.FileName := stxtZipFile.Caption;
 try
 Zipper.Entries.AddFileEntry(stxtArqEntra.Caption,ExtractFileName(stxtArqEntra.Caption));
 ShowMessageMobile(self,'before call');
 Zipper.ZipAllFiles;
 except
 On e: Exception do
 begin;
 ShowMessage('Error zipping file = ' + e.Message);
 Abort;
 end;
 end;
 end; // spbtnZiparClick

I saw the "before call" message and after I receive:

Error zipping file = Unable to open file "\Storage Card\esteio0805.db"

The Zip file(the archive) was created, but with 0(zero) bytes in length.

I made a single program that call the same method but didn't use the database(no declare, nor Open/Close). In this case the execution of the method was successfull and the zip file was created(I tried to open it with 7zip and it opens ok).

It seems to me, that there are some components of the database(or TSQLite3Dataset) that remain opened even if I hit the Close method. As I already said above I review the logic dozen of times and it seems that there is no TSQLite3Dataset instances opened. It seems that there something locking the database file access.

The error reported occurs in the windows mobile emulator and in a HP iPAQ too.

Is it possible?

Greetings from sao Paulo - Brasil

Ricardo.'.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20111026/272f2985/attachment.html>

Reply by email

Felipe Monteiro de Carvalho
to Arí Ricardo Ody

I suppose that Close will close the file conection (correct me someone, if I am wrong)

Maybe you would try something more agressive, for example, free all datasets and check if the zip works. Then progressively stop freezing datasets until you find the one causing the problem. (although it should really be the one that use this file, so just testing on it might be just as good)

Felipe Monteiro de Carvalho

Reply by email

Arí Ricardo Ody

As usual, your suggestion solves the problem. Once I freed the 2 datasets(both use the same ".db" file) I know was used before the execution reaches the zip routine, the error with access rights disappear. In this aspect, trouble is solved, thank you.

The application has various methods that allocate open a TSQLDataset that points to the same ".db" file I'm pretending to save in my zip routine. All of these methods are closed with Close method. Depending on user options I'm thinking that I will have various copies of TSQLite3Dataset created and open. Am I right? If affirmative, how you suggest I control the execution to allow me apply the Free method on each of these TSQLite3Dataset copies? And later apply the Create again if the user return to one of those methods that allocated a copy of TSQLite3Dataset and are(the method) created in memory?

Maybe my programming technique must be changed... Or what?

Cheers

Ricardo

Earlier message 10 lines
----- Original Message ----- From: Felipe Monteiro de Carvalho Sent: 10/26/11 05:01 AM To: Lazarus mailing list Subject: Re: [Lazarus] Problem with access rights in Windows Mobile? I suppose that Close will close the file conection (correct me someone, if I am wrong) Maybe you would try something more agressive, for example, free all datasets and check if the zip works. Then progressively stop freezing datasets until you find the one causing the problem. (although it should really be the one that use this file, so just testing on it might be just as good) -- Felipe Monteiro de Carvalho -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20111026/46af94f4/attachment-0001.html>

Reply by email

Felipe Monteiro de Carvalho
to Arí Ricardo Ody

2011/10/26 "Ar? Ricardo Ody" :

The application has various methods that allocate open a TSQLDataset that points to the same ".db" file ... Maybe my programming technique must be changed... Or what?

My tipical solution is to create 1 unit which has a class which manages a dataset. And dont declare this same dataset anywhere else.

You then add a method which returns an instance of this class, but using the singleton approach it will return always the same object for all places which need it. You can check this example:

http://openpokergrid.svn.sourceforge.net/viewvc/openpokergrid/WebServer/DB/dbplayer.pas?revision=277&view=markup

Here I mixed the singleton approach with reference counting, because I dislike initialization/finalization sections. It will free the object and the dataset when the reference count reaches zero. In a tipical singleton approach it would only free in the finalization section.

Felipe Monteiro de Carvalho

Reply by email

Arí Ricardo Ody

I'll try this approach.

Thank you very much

Ricardo

Earlier message 10 lines
----- Original Message ----- From: Felipe Monteiro de Carvalho Sent: 10/26/11 06:10 AM To: Lazarus mailing list Subject: Re: [Lazarus] Problem with access rights in Windows Mobile? 2011/10/26 "Ar? Ricardo Ody" : > The application has various methods that allocate open a TSQLDataset that > points to the same ".db" file ... > Maybe my programming technique must be changed... Or what? My tipical solution is to create 1 unit which has a class which manages a dataset. And dont declare this same dataset anywhere else. You then add a method which returns an instance of this class, but using the singleton approach it will return always the same object for all places which need it. You can check this example: http://openpokergrid.svn.sourceforge.net/viewvc/openpokergrid/WebServer/DB/dbplayer.pas?revision=277&view=markup Here I mixed the singleton approach with reference counting, because I dislike initialization/finalization sections. It will free the object and the dataset when the reference count reaches zero. In a tipical singleton approach it would only free in the finalization section. -- Felipe Monteiro de Carvalho -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20111026/e3b94e52/attachment.html>

Reply by email