Unix Technical Forum

Newbee to databases (ODBC)

This is a discussion on Newbee to databases (ODBC) within the Pgsql General forums, part of the PostgreSQL category; --> Hi all, I'm sorry to bother you with this question, I know it is a C++ ODBC question. But ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-10-2008, 12:19 AM
Malm Paul
 
Posts: n/a
Default Newbee to databases (ODBC)

Hi all,
I'm sorry to bother you with this question, I know it is a C++ ODBC
question. But I'm a bit desperate.
Perhaps I'll be lucky.

I have a table with 2 columns no_char and blobdata were no_char is
number of characters in blobdata. I would like to handle each row from
the result set.


I have got this far:

//Setup selectstatement
strcpy((char*) SQLStmt, "Select no_char, blobdata from tab1");

//Execute the statement
rc = SQLExecDirect(dbConnection.StmtHandle, SQLStmt, SQL_NTS);

//Define what to read out from the selection set
rc =SQLBindCol(StmtHandle, 1 SQL_C_LONG, (SQLPOINTER) &no, sizeOf(no),
NULL);
rc =SQLBindCol(StmtHandle, 2 SQL_C_BINARY, (SQLPOINTER) blob, no, NULL);

// get the values
while(SQLFetch(StmtHandle) != SQL_NO_DATA)
{
....
....
}

But this will not work since I'm using "no" in the second statement to
define the blob size, and no is not set yet.
I could solve it by using 2 different select statemen (once for the size
and one for the blob) but that seems to be a bad solution.

Sorry again!
/Paul


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-10-2008, 12:19 AM
Andrei Kovalevski
 
Posts: n/a
Default Re: Newbee to databases (ODBC)

Hello,

You can use SQLGetData(...) function:

//Setup selectstatement
strcpy((char*) SQLStmt, "Select no_char, blobdata from tab1");

//Execute the statement
rc = SQLExecDirect(dbConnection.StmtHandle, SQLStmt, SQL_NTS);

//Define what to read out from the selection set
rc =SQLBindCol(StmtHandle, 1, SQL_C_LONG, (SQLPOINTER) &no, sizeOf(no),
NULL);
rc =SQLBindCol(StmtHandle, 2 SQL_C_BINARY, (SQLPOINTER) blob, no, NULL);

// get the values
while(SQLFetch(StmtHandle) != SQL_NO_DATA)
{
void* blob = malloc(no);
if (blob)
{
rc = SQLGetData(StmtHandle, 2, SQL_V_BINARY, blob, no, &no);
...
...
free (blob);
}
}


Malm Paul wrote:
>
> Hi all,
> I'm sorry to bother you with this question, I know it is a C++ ODBC
> question. But I'm a bit desperate.
> Perhaps I'll be lucky.
>
> I have a table with 2 columns no_char and blobdata were no_char is
> number of characters in blobdata. I would like to handle each row from
> the result set.
>
>
> I have got this far:
>
> //Setup selectstatement
> strcpy((char*) SQLStmt, "Select no_char, blobdata from tab1");
>
> //Execute the statement
> rc = SQLExecDirect(dbConnection.StmtHandle, SQLStmt, SQL_NTS);
>
> //Define what to read out from the selection set
> rc =SQLBindCol(StmtHandle, 1 SQL_C_LONG, (SQLPOINTER) &no, sizeOf(no),
> NULL);
> rc =SQLBindCol(StmtHandle, 2 SQL_C_BINARY, (SQLPOINTER) blob, no, NULL);
>
> // get the values
> while(SQLFetch(StmtHandle) != SQL_NO_DATA)
> {
> ...
> ...
> }
>
> But this will not work since I'm using "no" in the second statement to
> define the blob size, and no is not set yet.
> I could solve it by using 2 different select statemen (once for the
> size and one for the blob) but that seems to be a bad solution.
>
> Sorry again!
> /Paul
>



--
Andrei Kovalevski
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
Managed Services, Shared and Dedicated Hosting
Co-Authors: plPHP, ODBCng - http://www.commandprompt.com/


---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 10:51 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com