Changeset 492

Show
Ignore:
Timestamp:
04/08/06 19:31:25 (3 years ago)
Author:
common
Message:

sqlhandler-postgres
- unescape escaped binary data received, added escapeBinary() and unescapeBinary()

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • library/trunk/modules/sqlhandler-postgres/sqlhandler-postgres.cpp

    r489 r492  
    156156} 
    157157 
     158string SQLHandlerPostgres::escapeBinary(string *str) 
     159{ 
     160         
     161        unsigned char *res; 
     162        size_t size; 
     163        res = PQescapeBytea((const unsigned char *)str->c_str(),str->size(),&size); 
     164        string result((char *)res,(int)size); 
     165        PQfreemem(res); 
     166        return result; 
     167} 
     168 
     169string SQLHandlerPostgres::unescapeBinary(string *str) 
     170{ 
     171         
     172        unsigned char *res; 
     173        size_t size; 
     174        res = PQunescapeBytea((unsigned char *)str->c_str(),&size); 
     175        string result((char *)res,(int)size); 
     176        PQfreemem(res); 
     177        return result; 
     178} 
    158179 
    159180 
     
    209230                                        for ( i=0;i<PQnfields(res);i++ ) 
    210231                                        { 
    211                                                 foo[PQfname(res,i)] = PQgetvalue(res, j, i); 
     232                                                if ( PQfformat(res,i) == 0 ) 
     233                                                { 
     234                                                        foo[PQfname(res,i)] = PQgetvalue(res, j, i); 
     235                                                } else 
     236                                                { 
     237                                                        string bar = PQgetvalue(res, j, i); 
     238                                                        foo[PQfname(res,i)] = unescapeBinary(&bar); 
     239                                                } 
    212240                                        } 
    213241                                        result.push_back(foo); 
    214  
    215242                                } 
    216243                        } 
     
    271298    } 
    272299} 
     300 
  • library/trunk/modules/sqlhandler-postgres/sqlhandler-postgres.hpp

    r489 r492  
    5757                ~SQLHandlerPostgres(); 
    5858                bool runQuery(SQLQuery *query); 
     59                string escapeBinary(string *str); 
     60                string unescapeBinary(string *str); 
     61 
    5962                bool Init(); 
    6063                bool Exit();