Android Question Problem Database "Malformed" on some tables.

vecino

Well-Known Member
Licensed User
Longtime User
I'm having trouble making a copy of the BD to save.
First I close the DB, then I do a file.Copy finally I open the DB.

SQL.Close, close pending transactions, if any?
Is there a command to check if there are pending transactions and be able to execute them?
Something like:
if SQL.INTRANSACTION Then.
SQL.TRANSACTION.CLOSE

I do not know if I should also save the file -Journal of the database.

Can you orient myself with this topic?

Thanks.
 

Mahares

Expert
Licensed User
Longtime User
Can you orient myself with this topic?
Suppose you delete all records and then change your mind, and you want to rollback the deletion, the code will be for something like this. Of course it hinges on whether you can get in the database to issue those commands.:
B4X:
SQL.BeginTransaction
    Dim strQuery As String ="DELETE FROM mytable"
    SQL.ExecNonQuery(strQuery)    
    SQL.ExecNonQuery("ROLLBACK")
If all fails, you may want to attach your database for other members to see if it is corrupted or not.
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Hello, the problem apparently arises when I close the dB, I do a backup (copy.file) and then reopen it again. It's already "Malformed" when I open it again.
For what information is lost from some tables, normally the table of sales lines.
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
If the journal mode is 'wal', and it is likely to be, then there will be usually two additional files that are part of the database. Use File.ListFiles and you will see them.
Yes, there is the DB file "-Journal", and there is not the DB "Wall". I guess the latter is eliminated when closing the dB.
And, yes, the DB is created with Journal Mode "Wall".
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
I just read in the link that when the DB closes, the "Journal" must be deleted, and if it does not delete it, it is because the DB is still doing something or has any connection.

So, I ask, what do I do to close it completely? Does not it serve db.close?

Can I repeat the order several times?
Db.close.
Db.close.
Db.close.

??? I do not know what to do.
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
I can not find information to ensure the closure of the DB, the file "-journal" is always there, it is never deleted :/
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
The wal files will not be deleted when the database is closed. The database is made of these three files.
This is not what the documentation says.

The exceptions for not deleting the "journal" do not occur in this case, there is no "crash", no "power loss", no "locking_mode exclusive".
That is why I think, I believe, I deduce, it seems to me that something strange is happening and I don't know what it is. My knowledge on the subject is not enough.
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Yes, indeed, but the "wal" file is created and destroyed on exit. The one that is never destroyed is the "journal", and that is what worries me because I don't know if it is normal or if there is a problem.

Anyway, I think that running from the application: sql.execnonquery(".backup dbbackup.db") I can make backups without problems and I can sleep more relaxed. It's not good that a client calls you to say that the DB is broken when a backup has been done, that's what happened until now, and the method I was using was that:
DB.close
file.copy("data.db", "databackup.db")
DB.Inicialize(...
The DB was already broken!!!!!
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Okay, that doesn't work. I don't know how to run ".dump", nor do I know how to run ".backup".
I will continue to investigate.
Thanks, folks.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…