pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Hiroshi Inoue <inoue@tpf.co.jp>
To: Ganesh Borse <bganesh05@gmail.com>
Cc: pgsql-odbc@postgresql.org
Subject: Re: Request for help on retrieving binary data from bytea column using ODBC calls
Date: Fri, 24 Feb 2012 18:06:01 +0900
Message-ID: <4F4752F9.6010302@tpf.co.jp> (raw)
In-Reply-To: <CAEhYC0HOec=cZQG6C3HWAWNGR8R-dhrdtQwH2xBhdW8AuHG1XA@mail.gmail.com>
References: <CAEhYC0HOec=cZQG6C3HWAWNGR8R-dhrdtQwH2xBhdW8AuHG1XA@mail.gmail.com>

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



view thread (9+ messages)  latest in thread

Message-ID: <4F4752F9.6010302@tpf.co.jp>
Permalink:  ../4F4752F9.6010302@tpf.co.jp/
Also on:    postgresql.org/message-id/4F4752F9.6010302@tpf.co.jp

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-odbc@postgresql.org
  Cc: inoue@tpf.co.jp, bganesh05@gmail.com
  Subject: Re: Request for help on retrieving binary data from bytea column using ODBC calls
  In-Reply-To: <4F4752F9.6010302@tpf.co.jp>
  References: <CAEhYC0HOec=cZQG6C3HWAWNGR8R-dhrdtQwH2xBhdW8AuHG1XA@mail.gmail.com> <4F4752F9.6010302@tpf.co.jp>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox