storing "small binary objects"

From: Swaminathan Natarajan <swami(at)dcs(dot)uky(dot)edu>
To: pgsql-general(at)postgresql(dot)org
Subject: storing "small binary objects"
Date: 2001-03-29 00:41:36
Message-ID: Pine.LNX.4.10.10103281906130.21837-100000@mickey.dcs.uky.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

hi,

I am relatively new to postgresql. Sorry if this is a rather naive
question.

I am trying to store a fixed sized c++ class into the database and
retreive it. What is the simplest (dirtiest?!) way to do it? I couldnt
find any example on the web or in the pgsql/src directories that I could
get to work.

Here is what i did.

I tried defining a column as char(sizeof class) using...
create table firstTable(id integer,className char(sizeofclass));

Then in my c++ program, I used....

char* someVariable=(char*)(&classInstance)
//character handle to the class

exec sql insert into firstTable(id,className)
values(:temp,:someVariable);
//save "someVariable" 'asis' into the column

Then I tried reading the value back in...

someVariable=(char*)malloc(sizeof(class));
memset(someVariable,0,sizeof(class));
exec sql select id, className
into :id,:someVariable
from firstTable
where id = 5;
//read "someVariable" back in

While I got the value of id (and there is definitely a valid record), the
"someVariable" memory location is blank. What am I doing wrong?

In addition to examples available with the distribution, pointers to some
more sample code would help.

Thanks,
Swami.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2001-03-29 01:07:02 Re: composite data types
Previous Message Joseph Shraibman 2001-03-29 00:40:21 Re: explain shows lots-o-preliminary sorting