[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

02/16/2003 at 11:41PM PST, ID: 20516728
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.8

I have a question..!!

Asked by lian_kh_kr in Berkeley DB

Tags: berkeley, _cpbase64encoding, base64encode

I wonder that it is possible to store severl data under one key. for example:
(key) : (data)
fruit = apple,orange,banada
vegetalbe = carot,onion,
...
....
and above source is just for storing data.Therefore if I want to make a program for just reading berkeley db data, how can I make it ? I made following these sources but it doesn't work. That is,i want to make two program Data is stored by input.c and data is read by reading.c

== input.c ===
#include <stdio.h>
#include <sys/types.h>
#include <stdio.h>
#include <db.h>
#define DATABASE "access.db"
#define SSIZE 256
typedef struct _content{
   char RE[SSIZE];
   char REURL[SSIZE];
   char ACCEL[SSIZE];
} CONTENT;
CONTENT content;
static char* _cpBase64Encoding =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
void Base64Encode( char* cpInput, char* cpOutput )
{
int nIdx[ 4 ];  
while ( '\0' != *cpInput )
{
  nIdx[0] = ((*cpInput) & 0xFC)>>2;
  nIdx[1] = ((*cpInput) & 0x03)<<4;
  cpInput++;
  if ( '\0' != *cpInput )
  {
    nIdx[1] |= ((*cpInput) & 0xF0)>>4;
    nIdx[2]  = ((*cpInput) & 0x0F)<<2;
    cpInput++;
    if ( '\0' != (*cpInput) )
    {
      nIdx[2] |= ((*cpInput) & 0xC0) >> 6;
      nIdx[3]  = (*cpInput) & 0x3F;
      cpInput++;
    }
    else
      nIdx[3] = 64;
  }
  else
  {
    nIdx[2] = 64;
    nIdx[3] = 64;
  }

  *(cpOutput+0) = *(_cpBase64Encoding + nIdx[0]);
  *(cpOutput+1) = *(_cpBase64Encoding + nIdx[1]);
  *(cpOutput+2) = *(_cpBase64Encoding + nIdx[2]);
  *(cpOutput+3) = *(_cpBase64Encoding + nIdx[3]);
  cpOutput += 4;
}

*cpOutput = '\0';

return;
}
int main (){
     FILE *fp;
     DB *dbp;
     DBT key,data;
     int ret,t_ret;
     int size=600;
     char buf[size];
     char sNonCoded[256];
     char ssNonCoded[256];
     char sssNonCoded[256];
     char ssssNonCoded[256];
     char sEncoded[256];
     char ssEncoded[256];
     char sssEncoded[256];
     char ssssEncoded[256];
     char regex[6];
     char redirect[512];
     char redirect_url[512];
     char accel[512];
     //Read data
     if((fp=fopen("2.txt","rt")) ==  NULL){
          printf("Error: Cannot open data file\n");
          return(1);
     }
       // Create Berkeley DB
     if ((ret = db_create(&dbp, NULL, 0)) != 0) {
          fprintf(stderr, "db_create: %s\n", db_strerror(ret));
          exit (1);
     }
     if ((ret = dbp->open(
         dbp, DATABASE, NULL, DB_BTREE, DB_CREATE, 0664)) != 0) {
          dbp->err(dbp, ret, "%s", DATABASE);
          goto err;
     }

 while(fgets(buf,size-1,fp)){
     sscanf(buf,"%6s %512s %512s %512s",regex,redirect,redirect_url,accel);
     strcpy(sNonCoded,regex);
     strcpy(ssNonCoded,redirect);
     strcpy(sssNonCoded,redirect_url);
     strcpy(ssssNonCoded,accel);
     Base64Encode( sNonCoded, sEncoded );
     Base64Encode( ssNonCoded, ssEncoded );
     Base64Encode( sssNonCoded, sssEncoded );
     Base64Encode( ssssNonCoded, ssssEncoded);
     memset(&key,0,sizeof(key));
     memset(&data,0,sizeof(data));
     key.data = sEncoded;
     key.size = sizeof(sEncoded);
     strncpy(content.RE,ssEncoded,SSIZE);
     strncpy(content.REURL,sssEncoded,SSIZE);
     strncpy(content.ACCEL,ssssEncoded,SSIZE);
     data.data = (char *)&content;
     data.size = sizeof(CONTENT);
     if ((ret = dbp->put(dbp,NULL,&key,&data,0))==0){
          printf("db: %s: field 1 stored.\n",(char *)key.data);
          printf("db: %s: field 2 stored.\n",content.RE);
          printf("db: %s: field 3  stored.\n",content.REURL);
          printf("db: %s: field 4  stored.\n",content.ACCEL);
     }else{
          printf("Error");
          dbp->err(dbp,ret,"DB->put");
          goto err;
     }


 }
 err: if ((t_ret = dbp->close(dbp, 0)) != 0 && ret == 0)
             ret = t_ret;
             exit(ret);
}




== reading.c =====
#include <stdio.h>
#include <sys/types.h>
#include <stdio.h>
#include <db.h>
#define DATABASE "access.db"
#define SSIZE 256
typedef struct _content{
   char RE[SSIZE];
   char REURL[SSIZE];
   char ACCEL[SSIZE];
} CONTENT;
CONTENT content;

int main (){
     FILE *fp;
     DB *dbp;
     DBT key,data;
     int ret,t_ret,i=0;
     char sNonCoded[256];
     char rkey[1000 + 1], *retaddr;
   // Create Berkeley DB
     if ((ret = db_create(&dbp, NULL, 0)) != 0) {
          fprintf(stderr, "db_create: %s\n", db_strerror(ret));
          exit (1);
     }
     if ((ret = dbp->open(
         dbp, DATABASE, NULL, DB_BTREE, DB_CREATE, 0664)) != 0) {
          dbp->err(dbp, ret, "%s", DATABASE);
          goto err;
     }

 while((ret = dbp->get(dbp, NULL, &key, &data, 0)) != 0){
     printf("%d\n",i);
     memset(&key,0,sizeof(key));
     memset(&data,0,sizeof(data));
     key.data = rkey;
     key.size = sizeof(rkey);
     data.data = (char *)&content;
     data.size = sizeof(CONTENT);
     printf( "Decoded(field 1): %s\n", (char *)key.data );
     printf( "Decoded(field 2): %s\n",((CONTENT *)(data.data))->RE);
     printf( "Decoded(field 2): %s\n", ((CONTENT *)(data.data))->REURL);          
     printf( "Decoded(field 2): %s\n\n", ((CONTENT *)(data.data))->ACCEL);
     i++;
     if ( i == 20) {
          exit(1);
     }
 }
 err: if ((t_ret = dbp->close(dbp, 0)) != 0 && ret == 0)
             ret = t_ret;
 exit(ret);
}

data are :
AAAA    http://www.zzz.zzz   http://myhome http://www.zzz.*aaa
AAAi    http://www.bbb.zzz   http://myhome http://www.zzz.*aaa
AAAA    http://www.zzz.zzz   http://myhome http://www.zzz.*aaa
AAAA    http://www.ccc.zzz   http://myhome http://www.zzz.*aaa
AAAi    http://www.zzz.zzz   http://myhome http://www.zzz.*aaa
AAAA    http://www.ddd.zzz   http://myhome http://www.zzz.*aaa


I apprecate of your help..!!
 
Keywords: I have a question..!!
 
Loading Advertisement...
 
[+][-]03/07/03 11:39 PM, ID: 8093156

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Berkeley DB
Tags: berkeley, _cpbase64encoding, base64encode
Sign Up Now!
Solution Provided By: nrohan
Participating Experts: 1
Solution Grade: A
 
 
[+][-]03/26/04 02:48 AM, ID: 10685869

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]03/30/04 12:04 PM, ID: 10717104

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-91