Re: storing "small binary objects"

From: "Eric G(dot) Miller" <egm2(at)jps(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: storing "small binary objects"
Date: 2001-03-31 02:08:13
Message-ID: 20010330180813.B29151@calico.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Mar 28, 2001 at 07:41:36PM -0500, Swaminathan Natarajan wrote:
> 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.

Map your public instance data to the fields of one or more tables, then
when you reread the tuple(s) map them back to a "new" instance of the
class using its "set" methods. Look at the libpq++ methods rather than
embedded C. It may not be the simplest/dirtiest method, but then for
what you're doing, why not just use the filesystem? Or DBM embedded
database file?

>
> 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.

--
Eric G. Miller <egm2(at)jps(dot)net>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Eric G. Miller 2001-03-31 02:34:45 Re: function to operate on same fields, different records?
Previous Message Soma Interesting 2001-03-31 02:02:27 Re: plperl -- postgresql married to perl