title: Inserting NSData into SQLite on the iPhone
body: <p>So far I've managed to create this method for inserting into a SQLite database on the iPhone:</p>
  
  <pre><code>- (void) insertToDB :(NSString *)Identifier :(NSString *)Name
  {
      sqlite3 *database;
  
      if(sqlite3_open([databasePath UTF8String], &amp;database) == SQLITE_OK)
      {
          char *sql1 = "INSERT INTO table VALUES ('";
          const char *sql2 = [Identifier cStringUsingEncoding:[NSString defaultCStringEncoding]];
          char *sql3 = "', '";
          const char *sql4 = [Name cStringUsingEncoding:[NSString defaultCStringEncoding]];
          char *sql5 = "')";
  
          char *sqlStatement[255];
          strcpy(sqlStatement, sql1);
          strcat(sqlStatement, sql2);
          strcat(sqlStatement, sql3);
          strcat(sqlStatement, sql4);
          strcat(sqlStatement, sql5);
  
          sqlite3_stmt *compiledStatement;
  
          if(sqlite3_prepare_v2(database, sqlStatement, -1, &amp;compiledStatement, NULL) == SQLITE_OK)
          {
              sqlite3_last_insert_rowid(database);
              sqlite3_reset(compiledStatement);
          }
  
          sqlite3_finalize(compiledStatment);
      }
      sqlite3_close(database);
  }
  </code></pre>
  
  <p>Now I'm looking at storing an image in the database. So far I've <a href="https://stackoverflow.com/questions/643682/reading-and-writing-images-to-an-sqlite-db-for-iphone-use">found this</a>:</p>
  
  <pre><code>UIImage *cachedImage = [UIImage imageNamed:@"Icon.png"];
  NSData *dataForImage = UIImagePNGRepresentation(cachedImage);
  </code></pre>
  
  <p>But i'm having trouble trying to insert this NSData into the char array which makes the sqlStatement. Anyone got an idea how to do this?</p>
  
  <p>(I have a field in the database of type blob for this).</p>
  
  <p>Thanks</p>