Error while writing in DB.

72 views
Skip to first unread message

Ashish Asawa

unread,
Sep 21, 2018, 1:47:52 PM9/21/18
to FMDB
Hi,
I am getting following error while inserting data in db. I am using FMDB queue. I am using single queue only throughout the app.

Error Domain=FMDatabase Code=11 “database disk image is malformed” UserInfo={NSLocalizedDescription=database disk image is malformed
Error inserting batch: database disk image is malformed
Error inserting batch: database disk image is malformed

Gus Mueller

unread,
Sep 21, 2018, 1:48:47 PM9/21/18
to fm...@googlegroups.com
Are you able to do any selects? I'm guessing that what you're pointing sqlite to isn't a database it can read.

-gus

Vladislav Schegolev

unread,
Sep 21, 2018, 1:59:28 PM9/21/18
to fm...@googlegroups.com
Such error may occur if you executed some sql operation at some time that shouldnt be executed in transaction such like ATTACH or related to SQLCipher ‘set key’ op. There are some modification operations that shouldn’t be executed in transaction.

сб, 22 сент. 2018 г. в 0:48, Gus Mueller <g...@flyingmeat.com>:
--
You received this message because you are subscribed to the Google Groups "FMDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fmdb+uns...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

С уважением,
Владислав.

Ashish Asawa

unread,
Sep 22, 2018, 7:00:22 PM9/22/18
to FMDB
Hi, In my FMDB manager class, these are the two functions I have created to handle sql statements

 

    // multiple statements, create, delete, update


func execute
(sqlStatements statements: String ) -> (Bool, String?) {

 

       
var result:(Bool, String?) = (false, nil)

        databaseQueue
.inTransaction { (db, rollback) in

           
if !db.executeStatements(statements) {

               
//TODO: Logging

                debugPrint
("Failed to perform \(statements) into the database.")

                debugPrint
(db.lastError(), db.lastErrorMessage())

                rollback
.initialize(to: true)

                result
.1 = db.lastErrorMessage()

           
} else {

                result
.0 = true

           
}

       
}

       
return result

   
}


// fetch records

    func execute
(selectQuery query: String, values:[Any]?) -> (FmdbSelectQueryResult) {

       
var result:(FMResultSet?, String?) = (nil, nil)

        databaseQueue
.inTransaction { (db, rollback) in

           
do {

                let results
= try db.executeQuery(query, values: values)

                result
.0 = results

           
} catch {

                result
.1 = error.localizedDescription

                rollback
.pointee = true

           
}

       
}

       
return result

 

   
}



And database queue is a singleton queue. 

Gus Mueller

unread,
Sep 22, 2018, 7:08:11 PM9/22/18
to fm...@googlegroups.com
I would double check that the path you're trying to open the database at is actually a database. Try copying it over to your mac, and then running sqlite3 on it as well.

-gus
Reply all
Reply to author
Forward
0 new messages