Index: ogr/ogrsf_frmts/sqlite/ogrsqlitelayer.cpp
===================================================================
--- ogr/ogrsf_frmts/sqlite/ogrsqlitelayer.cpp	(revision 11439)
+++ ogr/ogrsf_frmts/sqlite/ogrsqlitelayer.cpp	(working copy)
@@ -320,16 +320,14 @@
                                  sqlite3_column_double( hStmt, iRawField ) );
             break;
 
-#ifdef notdef
           case OFTBinary:
           {
               int nBytes = sqlite3_column_bytes( hStmt, iRawField );
 
-              poFeature->SetField( iField, 
-                                   sqlite3_column_double( hStmt, iRawField ) );
+              poFeature->SetField( iField, nBytes,
+                                   (GByte*)sqlite3_column_blob( hStmt, iRawField ) );
           }
           break;
-#endif
 
           case OFTString:
             poFeature->SetField( iField, 
Index: ogr/ogrsf_frmts/sqlite/ogrsqlitetablelayer.cpp
===================================================================
--- ogr/ogrsf_frmts/sqlite/ogrsqlitetablelayer.cpp	(revision 11439)
+++ ogr/ogrsf_frmts/sqlite/ogrsqlitetablelayer.cpp	(working copy)
@@ -411,7 +411,7 @@
     ResetReading();
 
 /* -------------------------------------------------------------------- */
-/*      Do we want to "launder" the column names into Postgres          */
+/*      Do we want to "launder" the column names into SQLite            */
 /*      friendly format?                                                */
 /* -------------------------------------------------------------------- */
     if( bLaunderColumnNames )
@@ -423,7 +423,7 @@
     }
     
 /* -------------------------------------------------------------------- */
-/*      Work out the PostgreSQL type.                                   */
+/*      Work out the SQLite type.                                       */
 /* -------------------------------------------------------------------- */
     if( oField.GetType() == OFTInteger )
     {
@@ -433,6 +433,10 @@
     {
         strcpy( szFieldType, "FLOAT" );
     }
+    else if( oField.GetType() == OFTBinary )
+    {
+        strcpy( szFieldType, "BLOB" );
+    }
     else
     {
         strcpy( szFieldType, "VARCHAR" );
@@ -483,6 +487,8 @@
             pszType = "INTEGER";
         else if( poFldDefn->GetType() == OFTReal )
             pszType = "FLOAT";
+        else if( poFldDefn->GetType() == OFTBinary )
+            pszType = "BLOB";
         else
             pszType = "VARCHAR";
         
@@ -502,6 +508,8 @@
         pszType = "INTEGER";
     else if( oField.GetType() == OFTReal )
         pszType = "FLOAT";
+    else if( oField.GetType() == OFTBinary )
+        pszType = "BLOB";
     else
         pszType = "VARCHAR";
     
@@ -739,24 +747,38 @@
         oCommand +=poFeatureDefn->GetFieldDefn(iField)->GetNameRef();
         oCommand += "'";
 
-        pszRawValue = poFeature->GetFieldAsString( iField );
-        if( strchr( pszRawValue, '\'' ) != NULL )
+        if( poFeatureDefn->GetFieldDefn(iField)->GetType() == OFTBinary  )
         {
-            char *pszEscapedValue = 
-                CPLEscapeString( pszRawValue, -1, CPLES_SQL );
+            int binaryCount = 0;
+            GByte* binaryData = poFeature->GetFieldAsBinary( iField, &binaryCount );
+            char* pszHexValue = CPLBinaryToHex( binaryCount, binaryData );
+            oValues += "X'";
+            oValues += pszHexValue;
             oValues += "'";
-            oValues += pszEscapedValue;
-            oValues += "'";
-
-            CPLFree( pszEscapedValue );
+            CPLFree( pszHexValue );
         }
         else
         {
-            oValues += "'";
-            oValues += pszRawValue;
-            oValues += "'";
+            pszRawValue = poFeature->GetFieldAsString( iField );
+
+            if( strchr( pszRawValue, '\'' ) != NULL )
+            {
+                char *pszEscapedValue = 
+                    CPLEscapeString( pszRawValue, -1, CPLES_SQL );
+                oValues += "'";
+                oValues += pszEscapedValue;
+                oValues += "'";
+
+                CPLFree( pszEscapedValue );
+            }
+            else
+            {
+                oValues += "'";
+                oValues += pszRawValue;
+                oValues += "'";
+            }
         }
-            
+
         bNeedComma = TRUE;
     }
 

