title: Insert UIImage Into database using FMDB
body: <p>I have a sqlite database created by Navicat contains table called <code>EDITED_PHOTOS</code> and this table has two columns:</p>
  
  <p>1- ID which is primary integer and auto increment.</p>
  
  <p>2- IMAGE type is blob</p>
  
  <p><a href="https://i.stack.imgur.com/kSsHP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kSsHP.png" alt="enter image description here"></a></p>
  
  <p>First I am converting the <code>UIImage</code> into <code>NSData</code> unwrapped and then using FMDB database queue to execute the query in block.</p>
  
  <pre><code>    let imageToData = UIImagePNGRepresentation(image)
      queue!.inTransaction { db, rollback in
  
          do {
  
              let value =  try db.executeQuery("INSERT INTO EDITED_IMAGES VALUES (?,?)", values: ["\'NULL\'",imageToData!])
  
              print(value)
  
          }catch {
  
  
          }
  
      }
  </code></pre>
  
  <p>The insert statement is executed and returns <code>FMResultSet</code> without any errors. the path of database is correct and the table is found but the insert query is not being inserted properly maybe ? but its not producing any error ?</p>
  
  <p>I have checked the database on the device after executing the insert by downloading the application container from Xcode, the table is empty of records. or Also by checking the number of records in table programmatically.</p>
  
  <p>My next attempt to insert the query is using <code>executeStatements</code>, so what i did is the following: </p>
  
  <pre><code>let value =  db.executeStatements("INSERT INTO EDITED_IMAGES VALUES (\'NULL\',\(imageToData!))")
  </code></pre>
  
  <p>Since <code>NSData</code> representation is similar to this : <code>&lt;89504e47 0d0a1a0a 0000000d .............&gt;</code></p>
  
  <p>executing this query generates an error :  <code>Error inserting batch: near "&lt;": syntax error</code></p>
  
  <p>I have tried to using FMDatabase without queue but it has exactly the same issue.</p>