Retreving the dynamically allocated values from bdb using C


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Retreving the dynamically allocated values from bdb using C
# 1  
Old 04-11-2012
Retreving the dynamically allocated values from bdb using C

In one of the assignment which i am working on, i am am trying to insert keys and values into BDB by reading the input records from a input file as below.
Here keys i am inserting as character buffer and for values i am dynamically allocating the memory using malloc and then inserting into bdb.
But when i try to retireve the inserted values from BDB i am geting only the latest record for Value.

//KEY
char key[512];

//VALUE
typedef struct
{
char *remValues[10];
}valuestr;

static valuestr vstr;
Dbc *dbcObj;
Dbt dbtKey,dbtValue;

// I am dynamically allocating memory for Value str using malloc example as below.
vstr.remValues[0] = (char *)malloc(50);

while(!feof(inFile))
{
//getting key from input file
strcpy(buf, <value1>); //value1 comes from input file

//getting Value from input file
memset(vstr.remValues[0],0,50);
sprintf(vstr.remValues[0],"%d",<value2>); //value2 comes from input file

...........
...........

//Putting values into BDB

dbtKey.set_data((char*) buf);
dbtKey.set_size(strlen(buf));

dbtValue.set_data((valuestr*)&vstr);
dbtValue.set_size(sizeof(valuestr));

int ret = dbObj.put(0,&dbtKey,&dbtValue,DB_NOOVERWRITE);
}

But when i try to retrive the values from BDB its giving proper values for Key but for Value i am getting only the latest value from input file.
Below is the Key value retreival code.

dbObj.cursor(NULL,&dbcObj,0);
char keys[100];
valuestr *values;
while(dbcObj->get(&dbtKey,&dbtValue,DB_NEXT)==0)
{
memset(keys,0,sizeof(keys));
strncpy(keys,(char *)dbtKey.get_data(),strlen(buf));
values = (valuestr *)dbtValue.get_data();
//printing values and keys on to console
}

Can you please suggest how to resolve this ?
# 2  
Old 04-11-2012
Bumping up posts or double posting is not permitted in these forums.

Please read the rules, which you agreed to when you registered, if you have not already done so.

You may receive an infraction for this. If so, don't worry, just try to follow the rules more carefully. The infraction will expire in the near future

Thank You.

The UNIX and Linux Forums.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Dynamically merging 2 files on header values

Hi All, I have 2 files which i need to merge together based on the column names provided in the file. The first line in both files are header records. The first file has fixed columns but second file can have subset of the columns from file 1 File 1: ... (6 Replies)
Discussion started by: kushagra
6 Replies

2. Shell Programming and Scripting

Modifying the values of dynamically named arrays

Hi all, In ksh, I'm trying to loop through all of my arrays, named array1, array2, array3..., and update the indices. But I'm getting errors and I'm not sure how to fix them. The errors are ./parse.sh: 6+1: not found The code is: eval \${array$c}=$(eval \${array$c}+1 ) Any help... (12 Replies)
Discussion started by: nicksantos1
12 Replies

3. Programming

Retreving the dynamically allocated values from bdb using C

In one of the assignment which i am working on, i am am trying to insert keys and values into BDB by reading the input records from a input file as below. Here keys i am inserting as character buffer and for values i am dynamically allocating the memory using malloc and then inserting into bdb.... (1 Reply)
Discussion started by: AmbikaValagonda
1 Replies

4. Shell Programming and Scripting

dynamically adding values in c-shell

I am needing to create a variable(changing) and assign it a value(changing) ... I am using C-Shell.. Example: foreach account in ($Accountlist) set account_connect = "$account/$account_pass" end I want to make set account_connect to store various values ? $account_connect did not... (3 Replies)
Discussion started by: shafi2all
3 Replies

5. Programming

Why memory allocated through malloc should be freed ?

Actually for a process to run it needs text, stack , heap and data segments. All these find a place in the physical memory. Out of these 4 only heap does exist after the termination of the process that created it. I want to know the exact reason why this happens. Also why the other process need to... (20 Replies)
Discussion started by: karthiktceit
20 Replies

6. Programming

Dynamically allocated structures in C

I have a pointer to a structure containing an integer pointer: struct members { int id; int *neigh; }; The number of members N and its neighbors M change as the code runs, so I allocate the memory dynamically: members *grid = malloc(sizeof(members)*N); for(i=0;i<N;i++)... (2 Replies)
Discussion started by: brinch
2 Replies

7. Shell Programming and Scripting

Help with variables for filesystems allocated

Hi all, I am interning in a unix department and am very new to programming. I am supposed to write a script that counts the amount of filesystems a server has allocated, and the amount free. This is what I was given to start with: #!/bin/ksh df -m | grep -v ":"|grep -v Free|grep -v "/proc"|... (6 Replies)
Discussion started by: compan023
6 Replies

8. Solaris

Can be changeed the allocated space

i am working with solaris 9 and my disk usages are # df -k Filesystem kbytes used avail capacity Mounted on /dev/dsk/c0t0d0s0 2148263 1902721 202577 91% / /proc 0 0 0 0% /proc mnttab 0 0 0 ... (3 Replies)
Discussion started by: smartgupta
3 Replies

9. Solaris

xntpd[28781]: too many recvbufs allocated

Hi, I have a server that is getting the following alarm a couple times a day: Mar 25 10:56:54 hostname xntpd: too many recvbufs allocated (30) Mar 25 10:56:54 hostname xntpd: too many recvbufs allocated (30) I know this is some sort of NTP related issue but I need to gauge the severity of... (0 Replies)
Discussion started by: BrewDudeBob
0 Replies

10. Solaris

Memory allocated

Hi, How to find out what is the maximum memory allocated to TOMCAT server in SunOS 5.8? The Tomcat server crashes down during peak times.... Regards (1 Reply)
Discussion started by: baanprog
1 Replies
Login or Register to Ask a Question