Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id EC9F6174E987 for ; Fri, 24 Feb 2012 05:06:27 -0400 (AST) Received: from sd.tpf.co.jp ([210.161.239.34]) by makus.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1S0r6f-0007kD-3M for pgsql-odbc@postgresql.org; Fri, 24 Feb 2012 09:06:27 +0000 Received: (qmail 7956 invoked by uid 512); 24 Feb 2012 09:06:09 -0000 Received: from unknown (HELO ?100.0.32.108?) (100.0.32.108) by sd2.tpf-fw-c.co.jp with SMTP; 24 Feb 2012 09:06:09 -0000 Message-ID: <4F4752F9.6010302@tpf.co.jp> Date: Fri, 24 Feb 2012 18:06:01 +0900 From: Hiroshi Inoue User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:9.0) Gecko/20111222 Thunderbird/9.0.1 MIME-Version: 1.0 To: Ganesh Borse CC: pgsql-odbc@postgresql.org Subject: Re: Request for help on retrieving binary data from bytea column using ODBC calls References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201202/11 X-Sequence-Number: 10774 Hi Ganesh, (2012/02/24 14:06), Ganesh Borse wrote: > Dear All, > > I've a VC++ application which displays the various binary files (like > jpgs, xls, zips) stored in PostgrelSQL DB in bytea column. > Files are inserted into bytea column using hex encoding. How did you insert the data concretely? regards, Hiroshi Inoue > But, when I try to access this column by executing the query "select * > from tablename;" from ODBC on Windows in this application, the buffer > contains the same hex encoded data, but not the binary data. > > Application does the following steps to retrieve this binary data. This > same code works well with other DBS, like Oracle, Sybase, DB2, MSSQL & > so on. > //--------------------------------------------------------------------------------------------------- > // prepare query: > wchar_t *query = _T("select * from mytable;"); > SQLRETURN ret = SQLPrepare(stmt, query, SQL_NTS); > if (!SQL_SUCCEEDED(ret)) > { > TRACE("SybAse:SQLprepare failed."); > DbException::sqlErrorInfo(SQL_HANDLE_STMT, stmt); > throw DbException(std::string("")); > } > // bind to column: > SQLBindCol(stmtHdl, columnNumber, SQL_C_BINARY, > m_colValue[0], m_len, &m_LenInd[0]); > // Execute query: > ret = SQLExecute(stmt); > // fetch rows > if (SQL_SUCCESS == ret || SQL_SUCCESS_WITH_INFO == ret) > { > do { > ret = SQLFetchScroll(m_stmt, SQL_FETCH_NEXT, 0); > // handle data per row here... > } while(SQL_SUCCEEDED(ret)); > } > //--------------------------------------------------------------------------------------------------- > > Can you please help me know, how can I retrieve the data stored in bytea > columns in binary format, so that those file can be handled appropriately? > > Thanks in advance for your help and guidance. > > Best Regards, > Ganesh