2

I have a struct to store retrieved data before i put them into a vector.

typedef struct{
    long long int uuId;
    short int gender;
    short int age;
    short int cameraNo;
    unsigned char *image; //[IMAGE_SIZE];
    size_t imageSize;
    //std::string time;
}FaceRecord;

How can i get blob data and put it to a char* or char[]? tempFR is a temporary struct to push_back into the vector. Here is a part of my function:

std::stringstream s;
        s << "SELECT * FROM Dao WHERE gender = "<< data <<"";

        prepStmt = con->prepareStatement (s.str());
        res = prepStmt->executeQuery();

        unsigned char* ptr;
        size_t blobSize=100;
        std::istream *is;
        while(res->next()){
            tempFR.uuId = res->getInt64("uuId");
            tempFR.cameraNo = res->getInt("cameraNo");
            tempFR.age = res->getInt("age");
            tempFR.gender = res->getInt("gender");
            is = res->getBlob("image");
            is->seekg (0, std::ios::end);
            blobSize = is->tellg();
            is->seekg (0, std::ios::beg);
            tempFR.image = new unsigned char[blobSize];
            is->read((char*)tempFR.image,blobSize);
            tempFR.imageSize = blobSize;
            rec->push_back(tempFR);
        }

1 Answer 1

4

Give this a try:

std::istream *blobData = set->getBlob("image");
std::istreambuf_iterator<char> isb = std::istreambuf_iterator<char>(*blobData);
std::string blobString = std::string(isb, std::istreambuf_iterator<char>());
tempFR.image = blobString.c_str();
blobData->seekg(0, ios::end);
tempFR.imageSize = blobData->tellg();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.