Hi,
I tried to update bytea field, using prepared statement, and have problem:
There are twice escaped characters stored in database. First esaping cause
"Esc = T.esc_raw(...)", second one cause "I(Esc);"

It is possible pass raw data to prepare::invocation(), to avoid this 
behavior ?

Thanks,
Lumir Vanek
KPoGre developer

----------------------------------
Here is my source - slightly modified test062 :


    T.exec("DELETE FROM pqxxbin");
    
    const int bufSize = 4;
    char buffer1[bufSize]; // some raw data - begin of PNG file
    buffer1[0] = 0x89; //  \211
    buffer1[1] = 0x50; //  P
    buffer1[2] = 0x4E; //  N
    buffer1[3] = 0x47; //  G
    
    T.exec("CREATE TEMP TABLE pqxxbin (binfield bytea)");
    
    // Make escaped string from buffer data
    const std::string Esc = T.esc_raw(reinterpret_cast <const unsigned 
char *> (&buffer1), bufSize);
    const std::string prepStmtName = "test";
    
    pqxx::prepare::declaration D = m_pConnection->prepare(prepStmtName, 
"INSERT INTO pqxxbin VALUES ($1)");
    D("bytea", pqxx::prepare::treat_binary);
    
    prepare::invocation I = T.prepared(prepStmtName);
    I(Esc); // pass escaped string as invocation parameter for $1. But 
this cause escaping twice !
                
    I.exec();
    
    result R = T.exec("SELECT binfield from pqxxbin");
    
    binarystring B( R.at(0).at(0) );

    if (B.empty())
      cout << "Binary string became empty in conversion" << endl;

    cout << "original: 211PNG" << endl << "returned: " << B.c_ptr() << endl;

    if (B.size() != bufSize)
       cout << "Binary string got changed from " + to_string(bufSize) + 
" to " + to_string(B.size()) + " bytes"  << endl;

_______________________________________________
Libpqxx-general mailing list
[email protected]
http://gborg.postgresql.org/mailman/listinfo/libpqxx-general

Reply via email to