⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mdb.c

📁 嵌入式数据Berkeley DB 4.5.20的应用例程.该例是在at91rm9200下运行,实现对数据库表的创建,数据的存取
💻 C
📖 第 1 页 / 共 3 页
字号:
        strcat(str1,"boxcode");
             strtmp =(char)((boxcode/10)+48);
        strcat(str1,&strtmp);
             strtmp =(char)((boxcode%10)+48);
        strcat(str1,&strtmp);

        memset(&key, 0, sizeof(key));
        memset(&data, 0, sizeof(data));
        key.data = str1;
        key.size = sizeof("boxcodeii");
        data.data = eqcard.BoxCode;
        data.size = sizeof(BYTE);
        if ((db_ret = dbp->put(dbp, NULL, &key, &data, 0)) == 0)
                printf("db: %s: key stored.\n", (char *)key.data);
        else    dbp->err(dbp, db_ret, "DB->put");

        strcat(str1,"slotcode");
             strtmp =(char)((slotcode/10)+48);
        strcat(str1,&strtmp);
             strtmp =(char)((slotcode%10)+48);
        strcat(str1,&strtmp);

        memset(&key, 0, sizeof(key));
        memset(&data, 0, sizeof(data));
        key.data = str1;
        key.size = sizeof("slotcodeii");
        data.data = eqcard.SlotCode;
        data.size = sizeof(BYTE);
        if ((db_ret = dbp->put(dbp, NULL, &key, &data, 0)) == 0)
                printf("db: %s: key stored.\n", (char *)key.data);
        else    dbp->err(dbp, db_ret, "DB->put");

        strcat(str1,"cardtype");
             strtmp =(char)((cardtype/10)+48);
        strcat(str1,&strtmp);
             strtmp =(char)((cardtype%10)+48);
        strcat(str1,&strtmp);

        memset(&key, 0, sizeof(key));
        memset(&data, 0, sizeof(data));
        key.data = str1;
        key.size = sizeof("cardtypeii");
        data.data = eqcard.CardTypeID;
        data.size = sizeof(WORD);
        if ((db_ret = dbp->put(dbp, NULL, &key, &data, 0)) == 0)
                printf("db: %s: key stored.\n", (char *)key.data);
        else    dbp->err(dbp, db_ret, "DB->put");

        strcat(str1,"cardsoft");
             strtmp =(char)((cardsoft/10)+48);
        strcat(str1,&strtmp);
             strtmp =(char)((cardsoft%10)+48);
        strcat(str1,&strtmp);

        memset(&key, 0, sizeof(key));
        memset(&data, 0, sizeof(data));
        key.data = str1;
        key.size = sizeof("cardsoftii");
        data.data = eqcard.CardSoftVer;
        data.size = sizeof(BYTE);
        if ((db_ret = dbp->put(dbp, NULL, &key, &data, 0)) == 0)
                printf("db: %s: key stored.\n", (char *)key.data);
        else    dbp->err(dbp, db_ret, "DB->put");
}
/*********************************************************************************
  Function:     equpPort_tableCreate(int, DB *  )
  Descripton:   create table port infomation ,set default datas to MDB
  Calls:
  Called By:    EqupInfo_tableCreate()
  Table Accessed:
  Table Updated:
  Input:        port i
  Output:
  Return:
  Others:
**********************************************************************************/
void equpPort_tableCreate(int i,DB *dbp)
{
        DB *dbp;
        DBT  key,data;

        int db_ret;
        int t_ret;
        int cardcode,portno,porttype;
        char str1[10];
        char strtmp;
        struct Equ_PORT eqport;

        /*check box infomations from equip through 485 bus*/
        //check_eqbox(i,&eqbox);

        /*open matrix database file which located at /mnt/equp.info*/
        if ((db_ret = db_create(&dbp, NULL, 0)) != 0)
        {
        fprintf(stderr, "db_create: %s\n", db_strerror(db_ret));
        exit (1);
        }
        if ((db_ret = dbp->open(dbp,NULL,"EQUPDB", NULL, DB_BTREE, DB_CREATE, 0664)) != 0)
        {
        dbp->err(dbp, db_ret, "%s", "EQUPDB");
        exit (1);
        }

        cardcode = (int) (eqport.CardCode); 
        portno   = (int) (eqport.PortNO);
        porttype = (int) (eqport.PortTypeID);


        /*card code ASCII encode: eg. 1box,2card,15channel ->keyword as b01c02ch15cc*/
        strcat(str1," cardcode");
             strtmp =(char)(( cardcode/10)+48);
        strcat(str1,&strtmp);
             strtmp =(char)(( cardcode%10)+48);
        strcat(str1,&strtmp);

        memset(&key, 0, sizeof(key));
        memset(&data, 0, sizeof(data));
        key.data = str1;
        key.size = sizeof(" cardcodeii");
        data.data = eqport.CardCode;
        data.size = sizeof(DWORD);
        if ((db_ret = dbp->put(dbp, NULL, &key, &data, 0)) == 0)
                printf("db: %s: key stored.\n", (char *)key.data);
        else    dbp->err(dbp, db_ret, "DB->put");

        strcat(str1,"portno");
             strtmp =(char)((portno/10)+48);
        strcat(str1,&strtmp);
             strtmp =(char)((portno%10)+48);
        strcat(str1,&strtmp);

        memset(&key, 0, sizeof(key));
        memset(&data, 0, sizeof(data));
        key.data = str1;
        key.size = sizeof("portnoii");
        data.data = eqport.PortNO;
        data.size = sizeof(BYTE);
        if ((db_ret = dbp->put(dbp, NULL, &key, &data, 0)) == 0)
                printf("db: %s: key stored.\n", (char *)key.data);
        else    dbp->err(dbp, db_ret, "DB->put");

        strcat(str1,"porttype");
             strtmp =(char)((porttype/10)+48);
        strcat(str1,&strtmp);
             strtmp =(char)((porttype%10)+48);
        strcat(str1,&strtmp);

        memset(&key, 0, sizeof(key));
        memset(&data, 0, sizeof(data));
        key.data = str1;
        key.size = sizeof("porttypeii");
        data.data = eqport.PortTypeID;
        data.size = sizeof(BYTE);
        if ((db_ret = dbp->put(dbp, NULL, &key, &data, 0)) == 0)
                printf("db: %s: key stored.\n", (char *)key.data);
        else    dbp->err(dbp, db_ret, "DB->put");

}
/*********************************************************************************
  Function:     equpChannel_tableCreate(int, DB *  )
  Descripton:   create table Channel infomation ,set default datas to MDB
  Calls:
  Called By:   EqupInfo_tableCreate()
  Table Accessed:
  Table Updated:
  Input:        channel i
  Output:
  Return:
  Others:
**********************************************************************************/
void equpChannel_tableCreate(int i,DB *dbp)
{
        DB *dbp;
        DBT  key,data;

        int db_ret;
        int t_ret;
        int chancode,cardcode,portno,channo,chantype,chanprot,chancoty,chancoid;
        char str1[10];
        char strtmp;
        struct Equ_CHANNEL eqchannel;

        /*check box infomations from equip through 485 bus*/
        //check_eqbox(i,&eqbox);

        /*open matrix database file which located at /mnt/equp.info*/
        if ((db_ret = db_create(&dbp, NULL, 0)) != 0)
        {
        fprintf(stderr, "db_create: %s\n", db_strerror(db_ret));
        exit (1);
        }
        if ((db_ret = dbp->open(dbp,NULL,"EQUPDB", NULL, DB_BTREE, DB_CREATE, 0664)) != 0)
        {
        dbp->err(dbp, db_ret, "%s", "EQUPDB");
        exit (1);
        }

        chancode = (int) (eqchannel.ChannelCode); 
        cardcode = (int) (eqchannel.CardCode);
        portno   = (int) (eqchannel.PortNO);
        channo   = (int) (eqchannel.ChannelNO);
        chantype = (int) (eqchannel.ChannelTypeID); 
        chanprot = (int) (eqchannel.ChannelProtocol);
        chancoty = (int) (eqchannel.ChannelConnType);
        chancoid = (int) (eqchannel.ChannelConnID); 

        /*card code ASCII encode: eg. 1box,2card,15channel ->keyword as b01c02ch15cc*/
        strcat(str1," chancode");
             strtmp =(char)((chancode/10)+48);
        strcat(str1,&strtmp);
             strtmp =(char)((chancode%10)+48);
        strcat(str1,&strtmp);

        memset(&key, 0, sizeof(key));
        memset(&data, 0, sizeof(data));
        key.data = str1;
        key.size = sizeof(" chancodeii");
        data.data = eqchannel.ChannelCode;
        data.size = sizeof(WORD);
        if ((db_ret = dbp->put(dbp, NULL, &key, &data, 0)) == 0)
                printf("db: %s: key stored.\n", (char *)key.data);
        else    dbp->err(dbp, db_ret, "DB->put");

        strcat(str1,"cardcode");
             strtmp =(char)((cardcode/10)+48);
        strcat(str1,&strtmp);
             strtmp =(char)((cardcode%10)+48);
        strcat(str1,&strtmp);

        memset(&key, 0, sizeof(key));
        memset(&data, 0, sizeof(data));
        key.data = str1;
        key.size = sizeof("cardcodeii");
        data.data = eqchannel.CardCode;
        data.size = sizeof(DWORD);
        if ((db_ret = dbp->put(dbp, NULL, &key, &data, 0)) == 0)
                printf("db: %s: key stored.\n", (char *)key.data);
        else    dbp->err(dbp, db_ret, "DB->put");

        strcat(str1,"portno");
             strtmp =(char)((portno/10)+48);
        strcat(str1,&strtmp);
             strtmp =(char)((portno%10)+48);
        strcat(str1,&strtmp);

        memset(&key, 0, sizeof(key));
        memset(&data, 0, sizeof(data));
        key.data = str1;
        key.size = sizeof("portnoii");
        data.data = eqchannel.PortNO;
        data.size = sizeof(BYTE);
        if ((db_ret = dbp->put(dbp, NULL, &key, &data, 0)) == 0)
                printf("db: %s: key stored.\n", (char *)key.data);
        else    dbp->err(dbp, db_ret, "DB->put");

       
        strcat(str1,"channo");
             strtmp =(char)((channo/10)+48);
        strcat(str1,&strtmp);
             strtmp =(char)((channo%10)+48);
        strcat(str1,&strtmp);

        memset(&key, 0, sizeof(key));
        memset(&data, 0, sizeof(data));
        key.data = str1;
        key.size = sizeof("channoii");
        data.data = eqchannel.ChannelNO;
        data.size = sizeof(BYTE);
        if ((db_ret = dbp->put(dbp, NULL, &key, &data, 0)) == 0)
                printf("db: %s: key stored.\n", (char *)key.data);
        else    dbp->err(dbp, db_ret, "DB->put");

        strcat(str1,"chantype");
             strtmp =(char)((chantype/10)+48);
        strcat(str1,&strtmp);
             strtmp =(char)((chantype%10)+48);
        strcat(str1,&strtmp);

        memset(&key, 0, sizeof(key));
        memset(&data, 0, sizeof(data));
        key.data = str1;
        key.size = sizeof("chantypeii");
        data.data = eqchannel.ChannelTypeID;
        data.size = sizeof(WORD);
        if ((db_ret = dbp->put(dbp, NULL, &key, &data, 0)) == 0)
                printf("db: %s: key stored.\n", (char *)key.data);
        else    dbp->err(dbp, db_ret, "DB->put");

        
        strcat(str1,"chanprot");
             strtmp =(char)((chanprot/10)+48);
        strcat(str1,&strtmp);
             strtmp =(char)((chanprot%10)+48);
        strcat(str1,&strtmp);

        memset(&key, 0, sizeof(key));
        memset(&data, 0, sizeof(data));
        key.data = str1;
        key.size = sizeof("chanprotii");
        data.data = eqchannel.ChannelProtocol;
        data.size = sizeof(BYTE);
        if ((db_ret = dbp->put(dbp, NULL, &key, &data, 0)) == 0)
                printf("db: %s: key stored.\n", (char *)key.data);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -