Changeset 11484

Show
Ignore:
Timestamp:
05/11/07 12:41:01 (2 years ago)
Author:
mloskot
Message:

Imported Kosta's patch fixing BLOB support in OGR SQLite driver (Ticket #1623). The patch has been tested only from C/C++ API, see the ticket. There is still no support for BLOB in scripting bindings for OGR.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/gdal/ogr/ogrsf_frmts/sqlite/ogrsqlitelayer.cpp

    r10645 r11484  
    308308        if( sqlite3_column_type( hStmt, iRawField ) == SQLITE_NULL ) 
    309309            continue; 
    310          
     310 
    311311        switch( poFieldDefn->GetType() ) 
    312312        { 
    313           case OFTInteger: 
     313        case OFTInteger: 
    314314            poFeature->SetField( iField,  
    315                                  sqlite3_column_int( hStmt, iRawField ) ); 
    316             break; 
    317  
    318           case OFTReal: 
     315                sqlite3_column_int( hStmt, iRawField ) ); 
     316            break; 
     317 
     318        case OFTReal: 
    319319            poFeature->SetField( iField,  
    320                                  sqlite3_column_double( hStmt, iRawField ) ); 
    321             break; 
    322  
    323 #ifdef notdef 
    324           case OFTBinary: 
    325           { 
    326               int nBytes = sqlite3_column_bytes( hStmt, iRawField ); 
    327  
    328               poFeature->SetField( iField,  
    329                                    sqlite3_column_double( hStmt, iRawField ) ); 
    330           } 
    331           break; 
    332 #endif 
    333  
    334           case OFTString: 
     320                sqlite3_column_double( hStmt, iRawField ) ); 
     321            break; 
     322 
     323        case OFTBinary: 
     324            { 
     325                const int nBytes = sqlite3_column_bytes( hStmt, iRawField ); 
     326 
     327                poFeature->SetField( iField, nBytes, 
     328                    (GByte*)sqlite3_column_blob( hStmt, iRawField ) ); 
     329            } 
     330            break; 
     331 
     332        case OFTString: 
    335333            poFeature->SetField( iField,  
    336                                  (const char *)  
    337                                  sqlite3_column_text( hStmt, iRawField ) ); 
    338             break; 
    339  
    340           default: 
     334                (const char *)  
     335                sqlite3_column_text( hStmt, iRawField ) ); 
     336            break; 
     337 
     338        default: 
    341339            break; 
    342340        } 
  • trunk/gdal/ogr/ogrsf_frmts/sqlite/ogrsqlitetablelayer.cpp

    r10645 r11484  
    412412 
    413413/* -------------------------------------------------------------------- */ 
    414 /*      Do we want to "launder" the column names into Postgres          */ 
     414/*      Do we want to "launder" the column names into SQLite            */ 
    415415/*      friendly format?                                                */ 
    416416/* -------------------------------------------------------------------- */ 
     
    424424     
    425425/* -------------------------------------------------------------------- */ 
    426 /*      Work out the PostgreSQL type.                                   */ 
     426/*      Work out the SQLite type.                                       */ 
    427427/* -------------------------------------------------------------------- */ 
    428428    if( oField.GetType() == OFTInteger ) 
     
    433433    { 
    434434        strcpy( szFieldType, "FLOAT" ); 
     435    } 
     436    else if( oField.GetType() == OFTBinary ) 
     437    { 
     438        strcpy( szFieldType, "BLOB" ); 
    435439    } 
    436440    else 
     
    484488        else if( poFldDefn->GetType() == OFTReal ) 
    485489            pszType = "FLOAT"; 
     490        else if( poFldDefn->GetType() == OFTBinary ) 
     491            pszType = "BLOB"; 
    486492        else 
    487493            pszType = "VARCHAR"; 
     
    503509    else if( oField.GetType() == OFTReal ) 
    504510        pszType = "FLOAT"; 
     511    else if( oField.GetType() == OFTBinary ) 
     512        pszType = "BLOB"; 
    505513    else 
    506514        pszType = "VARCHAR"; 
     
    740748        oCommand += "'"; 
    741749 
    742         pszRawValue = poFeature->GetFieldAsString( iField ); 
    743         if( strchr( pszRawValue, '\'' ) != NULL ) 
     750        if( poFeatureDefn->GetFieldDefn(iField)->GetType() == OFTBinary  ) 
    744751        { 
    745             char *pszEscapedValue =  
    746                 CPLEscapeString( pszRawValue, -1, CPLES_SQL ); 
     752            int binaryCount = 0; 
     753            GByte* binaryData = poFeature->GetFieldAsBinary( iField, &binaryCount ); 
     754            char* pszHexValue = CPLBinaryToHex( binaryCount, binaryData ); 
     755            oValues += "X'"; 
     756            oValues += pszHexValue; 
    747757            oValues += "'"; 
    748             oValues += pszEscapedValue; 
    749             oValues += "'"; 
    750  
    751             CPLFree( pszEscapedValue ); 
     758            CPLFree( pszHexValue ); 
    752759        } 
    753760        else 
    754761        { 
    755             oValues += "'"; 
    756             oValues += pszRawValue; 
    757             oValues += "'"; 
     762            pszRawValue = poFeature->GetFieldAsString( iField ); 
     763 
     764            if( strchr( pszRawValue, '\'' ) != NULL ) 
     765            { 
     766                char *pszEscapedValue =  
     767                    CPLEscapeString( pszRawValue, -1, CPLES_SQL ); 
     768                oValues += "'"; 
     769                oValues += pszEscapedValue; 
     770                oValues += "'"; 
     771 
     772                CPLFree( pszEscapedValue ); 
     773            } 
     774            else 
     775            { 
     776                oValues += "'"; 
     777                oValues += pszRawValue; 
     778                oValues += "'"; 
     779            } 
    758780        } 
    759              
     781 
    760782        bNeedComma = TRUE; 
    761783    } 
     
    797819} 
    798820 
     821