![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I am trying to write a simple program using BDB , similar to the programs given in the reference document. Both the key and data are integers. For some reason, the DB->put function is failing (Invalid Argument). I am not able to figure out what could fail with a simple statement as that. If I try to display the error using DB->err, I get a segmentation fault. And if I try to set the page (1K) and cache size (32K), those methods fail as well. Am I missing something important over here? Thanks very much in advance. Regards, Maitreyee |
#3
| |||
| |||
|
|
rmaitreyee (AT) gmail (DOT) com (Maitreyee) wrote in message news:<db53bce6.0409131700.72d6c963 (AT) posting (DOT) google.com>... I am trying to write a simple program using BDB , similar to the programs given in the reference document. Both the key and data are integers. For some reason, the DB->put function is failing (Invalid Argument). I am not able to figure out what could fail with a simple statement as that. If I try to display the error using DB->err, I get a segmentation fault. And if I try to set the page (1K) and cache size (32K), those methods fail as well. Am I missing something important over here? Thanks very much in advance. Regards, Maitreyee Please post your code that will demonstrate the problem. Regards, Ron Sleepycat Software |
#4
| |||||
| |||||
|
|
ron (AT) sleepycat (DOT) com (Ron Cohen) wrote in message news:<6906cc78.0409140628.c1695ec (AT) posting (DOT) google.com>... rmaitreyee (AT) gmail (DOT) com (Maitreyee) wrote in message news:<db53bce6.0409131700.72d6c963 (AT) posting (DOT) google.com>... I am trying to write a simple program using BDB , similar to the programs given in the reference document. Both the key and data are integers. For some reason, the DB->put function is failing (Invalid Argument). |
|
statement as that. Please post your code that will demonstrate the problem. Regards, Ron Sleepycat Software Here is the piece of code: #define SOMEDB "somedb.db" int main(void) { DB *dbp; DBT key,data; int i; int *pInt; int *pData; int ret; if ( db_create( &dbp,NULL,0) != 0) { printf("Error creating database\n"); exit(0); } dbp->set_errfile(dbp, stderr); if ((ret = dbp->set_pagesize(dbp, 1024)) != 0) { dbp->err(dbp, ret, "set_pagesize"); exit(0); } if ((ret = dbp->set_cachesize(dbp, 0, 32 * 1024, 0)) != 0) { dbp->err(dbp, ret, "set_cachesize"); exit(0); } if ( dbp->open ( dbp , NULL , SOMEDB , DB_RECNO ,DB_CREATE, 0664 ) != 0) I had to change this: |
|
{ printf("Error opening client database\n"); exit(0); } if ( (pInt = (int*) malloc (sizeof(int))) == NULL ) { printf("Error doing malloc for pInt\n"); exit(0); } for ( i=0 ; i<10 ; i++ ) { memset ( &key , 0 , sizeof(key) ); memset ( &data , 0 , sizeof(data) ); *pInt = i+1; key.data = pInt; key.size = sizeof(int); data.data = pInt; data.size = sizeof(int); if((ret = dbp->put(dbp,NULL,&key,&data,DB_APPEND)) != 0 ) { printf("Error putting record in the database for record :%d\n",i); exit(0); } } for (i=0;i<10;i+2) |
|
{ *pInt = i; key.data = pInt; key.size = sizeof(int); |
|
if ( dbp->get(dbp,NULL,&key,&data,0) != 0 ) { printf("Error retrieving record\n"); exit(0); } pData = data.data; printf("data is:%d",*pData); } free(pInt); } Running this as it is gives a segmentation fault which goes away with the removal of dbp->err. Thanks for your help. Regards, Maitreyee |
#5
| |||
| |||
|
|
rmaitreyee (AT) gmail (DOT) com (Maitreyee) wrote in message news:<db53bce6.0409141136.3b8c5734 (AT) posting (DOT) google.com>... ron (AT) sleepycat (DOT) com (Ron Cohen) wrote in message news:<6906cc78.0409140628.c1695ec (AT) posting (DOT) google.com>... rmaitreyee (AT) gmail (DOT) com (Maitreyee) wrote in message news:<db53bce6.0409131700.72d6c963 (AT) posting (DOT) google.com>... I am trying to write a simple program using BDB , similar to the programs given in the reference document. Both the key and data are integers. For some reason, the DB->put function is failing (Invalid Argument). The DB->put function is due to a coding error. I modified your code below. Also, this program would not compile as it was missing an argument for the get method. I am not able to figure out what could fail with a simple statement as that. Please post your code that will demonstrate the problem. Regards, Ron Sleepycat Software Here is the piece of code: #define SOMEDB "somedb.db" int main(void) { DB *dbp; DBT key,data; int i; int *pInt; int *pData; int ret; if ( db_create( &dbp,NULL,0) != 0) { printf("Error creating database\n"); exit(0); } dbp->set_errfile(dbp, stderr); if ((ret = dbp->set_pagesize(dbp, 1024)) != 0) { dbp->err(dbp, ret, "set_pagesize"); exit(0); } if ((ret = dbp->set_cachesize(dbp, 0, 32 * 1024, 0)) != 0) { dbp->err(dbp, ret, "set_cachesize"); exit(0); } if ( dbp->open ( dbp , NULL , SOMEDB , DB_RECNO ,DB_CREATE, 0664 ) != 0) I had to change this: if ( dbp->open ( dbp , NULL , SOMEDB , NULL, DB_RECNO ,DB_CREATE, 0664 ) != 0) { printf("Error opening client database\n"); exit(0); } if ( (pInt = (int*) malloc (sizeof(int))) == NULL ) { printf("Error doing malloc for pInt\n"); exit(0); } for ( i=0 ; i<10 ; i++ ) { memset ( &key , 0 , sizeof(key) ); memset ( &data , 0 , sizeof(data) ); *pInt = i+1; key.data = pInt; key.size = sizeof(int); data.data = pInt; data.size = sizeof(int); if((ret = dbp->put(dbp,NULL,&key,&data,DB_APPEND)) != 0 ) { printf("Error putting record in the database for record :%d\n",i); exit(0); } } for (i=0;i<10;i+2) I also changed the line above for (i=1;i<10;i++) { *pInt = i; key.data = pInt; key.size = sizeof(int); May want to use: key.flags = DB_DBT_USERMEM; if ( dbp->get(dbp,NULL,&key,&data,0) != 0 ) { printf("Error retrieving record\n"); exit(0); } pData = data.data; printf("data is:%d",*pData); } free(pInt); } Running this as it is gives a segmentation fault which goes away with the removal of dbp->err. Thanks for your help. Regards, Maitreyee You are welcome. Ron |
#6
| |||
| |||
|
#7
| |||
| |||
|
|
I have a database and a secondary index associated with it. Whenever I try to "put" to the primary, I get an "Unknown error". The error number is a wierd (similar to -10056378200)negative value. |
#8
| |||
| |||
|
|
rmaitreyee (AT) gmail (DOT) com (Maitreyee) writes: I have a database and a secondary index associated with it. Whenever I try to "put" to the primary, I get an "Unknown error". The error number is a wierd (similar to -10056378200)negative value. Are you sure that the callback that you passed to DB->associate() is *always* returning zero or a valid error number? DB itself doesn't use such a large negative value for its errors, so it would seem that either some C library call did so (doubtful) or your associate callback returned that value. Philip Guenther |
![]() |
| Thread Tools | |
| Display Modes | |
| |