13 Replies Latest reply on Apr 3, 2007 9:03 AM by 569973

    I create a database, but I can't find it on my harddisk. Why?

    569973
      The following codes are running correctly, so I think that I have normally created a database, and opened it, and put a record in it, and normally close it.
      But why can not I find the data file on my hard disk? Should I save it to a file somewhere?

      #include <stdio.h>
      #include <stdlib.h>
      #include <sys/types.h>
      #include <db.h>

      #define DATABASE "LesslieData.db"

      int main()
      {
           DB * dbp;
           int ret;
           DBT key, data;
           int Age = 20;
           char * name = "Lesslielee";
           
           ret = db_create(&dbp, NULL, 0); //Create a database
           if (ret != 0)
                {
                     printf("Error in creating a database!");
                     exit (1);
                }
           ret = dbp->open(dbp, NULL, DATABASE, NULL, DB_BTREE, DB_CREATE, 0664); //open the database
           if (ret != 0)
                {
                     printf("Error in opening %s", DATABASE);
                     exit(2);
                }
                
           memset(&key, 0, sizeof(DBT));
           memset(&data, 0 ,sizeof(DBT));
           
           key.data = name;
           key.size = strlen(name) + 1;
           
           data.data = &Age;
           data.size = sizeof(int);
           
           ret = dbp->put(dbp, NULL, &key, &data, DB_NOOVERWRITE);
           if (ret == DB_KEYEXIST)
                {
                     printf("The key %s already exists.", name);
                     exit(3);
                }
           if (dbp != NULL)
                {
                     dbp->close(dbp, 0);
                }     
           return 0; //Success.
      }

      Message was edited by:
      Lesslielee