MySQL Forums
Forum List  »  Connector/C++

getBlob VC++ compile error
Posted by: Michael Leitch
Date: July 08, 2011 12:55PM

Hi:

I have had success with the C++ connector in writing and reading data to a database, but I am unable to put together code to get a blob. My current attempt does not compile, and I've been unable to find a C++ example from the internet though there are many for Java. I am currently trying to figure out the complexities of the stream objects, but can anyone help me implement the routine below to load a blob? I have code that writes blob data that complies but I have not yet tried to run it. Thanks in advance.

I am using MS VC++ Express 2008

Error:
======

1>c:\users\mike\documents\testengineer\coding\dev\modules_c++_express_2008\simple_mysqlcon\simple_mysqlconn\simple_mysqlcon.cpp(91) : error C2664: 'std::basic_istream<_Elem,_Traits>::basic_istream(std::basic_streambuf<_Elem,_Traits> *,bool)' : cannot convert parameter 1 from 'std::istream *' to 'std::basic_streambuf<_Elem,_Traits> *'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Code:
=====

Just the snippet of where the problem is. I can provide the complete code.

int loadBlob (DB_key key)
{
if(!pDB_Conn) return -1;

int iRet = 0;
char szBuf[256] = {'\0'}; // 512

sql::Statement *stmt=NULL;
sql::ResultSet *res=NULL;

try
{

stmt = pDB_Conn->createStatement();
sprintf(szBuf,"SELECT MY_TABLE_BLOB FROM MY_TABLE WHERE ID = %u;",key);

res = stmt->executeQuery(szBuf);

if (res->rowsCount()!=0)
{
res->next();

std::istream blobIn(res->getBlob("MY_TABLE_BLOB"));

string s;

int count=0;
while (getline(blobIn, s))
{
strcpy(gszArray[count],s.c_str());

if(++count == 256) break;
}
}
else
iRet = -1;

} catch (sql::SQLException &e) {

iRet = -1;
}

if(stmt) delete stmt;
if(res) delete res;

return iRet;

}



Edited 1 time(s). Last edit at 07/10/2011 07:11PM by Michael Leitch.

Options: ReplyQuote


Subject
Views
Written By
Posted
getBlob VC++ compile error
5111
July 08, 2011 12:55PM
1797
July 10, 2011 11:55PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.