SQLite: save the current contents to a file

I have a save SQLIte function that save data into a sqlite file (using four + 1 Tables).

When I use the save MenuHandler to a unique file name: eveything works fine. Even the read MenuHandler is OK.

BUT, when I want to save the data into itself (using the same file name I already use: a standard save) I get error messages about Table(s) already exists.
Nota: OS X display a message stating the file already exists and I click in “over write” (the previous version).

This is in no way that I can see in the Xojo documentation to go around that.

Clue(s) ?
Advice(s) ?

Nota: The data comes from a ListBox, but in the context, this does not matter.

When you click “over write”, you are giving the app permission to replace the file. It does not delete the file; that is the responsibility of the app. You must check whether the folderitem exists and delete it if it does. Then you can create a new file to over write the old one.

Hi Tim,

this is OK for me, but when I do that with a text from a TextField (or TextArea), the file previous contents is cleared. Same apply with an image in the Preview (OS X, or Paint in Windows).

To be completely honest, I was surprised by the behavior.

BTW: are-you telling me that I have to delete the file before starting to write another one to replace it ?
(or better: rename it, save the data into the new file, then if everything is OK, delete the original file ?)

Remember: Xojo do not tell me (programmatically speaking) that I want to overwrite an existing file. Or if it does, I do not know.

[quote=248889:@Emile Schwarz]

Remember: Xojo do not tell me (programmatically speaking) that I want to overwrite an existing file. Or if it does, I do not know.[/quote]
It doesn’t have to. The mere fact that you got a Folderitem back means that the user either changed the name or selected a file that exists and needs to be replaced.

[quote=248889:@Emile Schwarz]Hi Tim,

this is OK for me, but when I do that with a text from a TextField (or TextArea), the file previous contents is cleared.
[/quote]
That is because you are using a mechanism (Create) that explicitly overwrites the file if it exists. If you used Append, on the other hand, it would add the new text to the previous contents. Databases append by default.

[quote]Same apply with an image in the Preview (OS X, or Paint in Windows).
[/quote]
That’s because they delete the file before they write the new one. Just like you should.

[quote]To be completely honest, I was surprised by the behavior.
[/quote]
The default behavior for text and image files is to replace the previous contents. That is not the default behavior for databases. You just learned something new. Your expectation comes from the fact that you are thinking about the database the same way you think about text and image files: like a flat file.

[quote]BTW: are-you telling me that I have to delete the file before starting to write another one to replace it ?
(or better: rename it, save the data into the new file, then if everything is OK, delete the original file ?)
[/quote]
Yes. Just like you would (should) with any other flat file. Delete/Rename it first, then write a new one.

That’s because Xojo is treating the file like a database. You want to treat it the same as a text file. That’s OK, you just have to remember to delete it first.

After looking around in the sqlite-doc-3110000.zip file, I found: DROP TABLE.

It does what I wanted: clearing the file contents, but keep it on disk (just like a File Save).

BTW: in my previous statement I forgot the Xojo BinaryClass (BS): to overwrite the BS contents, one have to put the BinaryStream.Position to 0.

Ah, memory, when you fails !

Tim, Greg: thank you.