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

📄 treeindex.c

📁 PB 熟悉的哥们希望大家可以互相学习一下
💻 C
📖 第 1 页 / 共 2 页
字号:
    /* open a transaction */
    rc = mco_trans_start(db, MCO_READ_ONLY, MCO_TRANS_FOREGROUND, &t);
    if (rc == MCO_S_OK)
    {

        /* open the cursor */
        rc = Measurement_I_Diff_index_cursor(t, &csr);
        if (rc == MCO_S_OK)
        {

            /* Search for the first occurence */
            rc = Measurement_I_Diff_search(t, &csr, MCO_GE, RANGE_DIFF);

            for (i = 0; i < 10 && rc == MCO_S_OK; i++)
            {

                /* get item from cursor */
                rc = Measurement_from_cursor(t, &csr, &Obj);
                if (rc == MCO_S_OK)
                {

                    /* Show the measurement */
                    ShowObj(&Obj);

                    /* looking for next occurence */
                    while (rc == MCO_S_OK)
                    {
                        int cmp = 0;

                        /* if theresn't next item */
                        rc = mco_cursor_next(t, &csr);
                        if (rc != MCO_S_OK)
                        {
                            break;
                        }
                         /* then break */

                        /* if it's diff. is great or equal 0.5 then break; */
                        rc = Measurement_I_Diff_compare(t, &csr, RANGE_DIFF, &cmp);
                        if (rc == MCO_S_OK && cmp >= 0)
                        {
                            break;
                        }
                        /* else move to next item */
                    };
                };
            };
        }
        else
        {
            printf("Unable to open a cursor");
        };

        /* close the tramsaction */
        rc = mco_trans_commit(t);
    }
    else
    {
        printf("Unable to open a transaction");
    };
    printf("\n");

    /* using composite index I_DiffSum */
    printf("List of all measurements from the series #%d\n", TARGET_SERIES);

    /* open a transaction */
    rc = mco_trans_start(db, MCO_READ_ONLY, MCO_TRANS_FOREGROUND, &t);
    if (rc == MCO_S_OK)
    {
        /* open the cursor */
        rc = Measurement_I_Index_index_cursor(t, &csr);
        if (rc == MCO_S_OK)
        {

            /* Search for the first occurence */
            i = 1;
            rc = Measurement_I_Index_search(t, &csr, MCO_EQ, TARGET_SERIES, i);

            do
            {
                int cmp = 0;

                /* compare the item */
                rc = Measurement_I_Index_compare(t, &csr, TARGET_SERIES, (uint4)i, &cmp);
                if (rc == MCO_S_OK && cmp == 0)
                {

                    /* get measurement */
                    rc = Measurement_from_cursor(t, &csr, &Obj);
                    if (rc == MCO_S_OK)
                    {

                        /* Show the measurement */
                        ShowObj(&Obj);

                        /* move to next measurement */
                        rc = mco_cursor_next(t, &csr);
                        i++;
                    };
                }
                else
                {
                    /* current item is from another serie of measurments */
                    break;
                };

            }
            while (rc == MCO_S_OK);
        }
        else
        {
            printf("Unable to open cursor");
        };

        /* close the tramsaction */
        rc = mco_trans_commit(t);

    }
    else
    {
        printf("Unable to open transaction");
    };
    printf("\n");

    /* using index on element of structure I_RGB */
    printf("List of the first 10 dark gray or darker (ink <= RGB(128,128,128) ) elements\n");
    j = 0;

    /* open a transaction */
    rc = mco_trans_start(db, MCO_READ_ONLY, MCO_TRANS_FOREGROUND, &t);
    if (rc == MCO_S_OK)
    {

        /* open the cursor */
        rc = Measurement_I_RGB_index_cursor(t, &csr);
        if (rc == MCO_S_OK)
        {

            /* Search for the first occurence */
            rc = Measurement_I_RGB_search(t, &csr, MCO_LE, _RGB_(128, 128, 128));

            for (i = 0; i < 10 && rc == MCO_S_OK; i++)
            {

                int cmp = 0;

                /* get measurement */
                rc = Measurement_from_cursor(t, &csr, &Obj);
                if (rc == MCO_S_OK)
                {

                    /* Show the measurement */
                    ShowObj(&Obj);
                    j++;

                    /* move to next measurement */
                    rc = mco_cursor_next(t, &csr);

                    if (rc == MCO_S_OK)
                    {
                        /* compare the item */
                        rc = Measurement_I_RGB_compare(t, &csr, _RGB_(128, 128, 128), &cmp);

                        if (cmp > 0)
                        {
                            break;
                        }
                    };
                }
            };
        }
        else
        {
            printf("Unable to open cursor");
        };

        /* close the tramsaction */
        rc = mco_trans_commit(t);

    }
    else
    {
        printf("Unable to open a transaction");
    };
    if (j > 0)
    {
        printf("\n");
    }
    else
    {
        printf("None\n");
    }
}


void _SH_(void)
{

    char text[] = 
    {
        "\nThis samples demonstartes various tree index operations\n"
    };

    char text1[] = 
    {
        "Copyright (c) 2001-2007 McObject LLC. All Right Reserved.\n\n"
    };

    printf("%s\neXtremeDB runtime version %d.%d, build %d\n%s\n\nPress Enter to start", text, MCO_COMP_VER_MAJOR,
           MCO_COMP_VER_MINOR, MCO_COMP_BUILD_NUM, text1);

    getchar();
}


static void errhandler(int n)
{
    printf("\neXtremeDB fatal error: %d", n);
    getchar();
    exit( - 1);
}


int main(void)
{

    MCO_RET rc;
    mco_db_h db = 0;
    char* start_mem = 0;
    const char* dbName = "randdb";
    mco_runtime_info_t info;

    _SH_();
    mco_get_runtime_info(&info);
    if (info.mco_shm_supported)
    {
        start_mem = (char*)MAP_ADDRESS;
    }
    else
    {
        start_mem = (char*)malloc(DB_MEMORY_SIZE);
        if (!start_mem)
        {
            printf("Couldn't allocated memory\n");
            exit(1);
        }
    };

    /* set fatal error handler */
    mco_error_set_handler(&errhandler);

    /* start db engine */
    if (mco_runtime_start() != MCO_S_OK)
    {
        printf("\nUnable to start database engine\n");
        if (!info.mco_shm_supported)
        {
            free(start_mem);
        }
        exit( - 1);
    };

    /* Create a database, using first memory segment */
    rc = mco_db_open(dbName, randdb_get_dictionary(), start_mem, DB_MEMORY_SIZE, (uint2)PAGESIZE);

    if (rc == MCO_S_OK)
    {
        /* connect to the database, obtain a database handle */
        if (mco_db_connect(dbName, &db) == MCO_S_OK)
        {
            /* if LoadData is OK than ShowData */
            if (LoadData(db))
            {
                ShowData(db);
            }
            else
            {
                printf("Unable to load data\n");
            };
        }
        else
        {
            printf("Unable to connect database\n");
        };

        /* disconnect from the database, db is no longer valid */
        if (mco_db_disconnect(db) != MCO_S_OK)
        {
            printf("mco_db_disconnect(...) failed\n");
        };

        /* destroys the memory manager */
        if (mco_db_close(dbName) != MCO_S_OK)
        {
            printf("mco_db_close(...) failed\n");
        };

    }
    else
    {
        printf("\nerror creating database");
    };

    /* free the memory */
    if (!info.mco_shm_supported)
    {
        free(start_mem);
    }

    /* shutdown database engine */
    mco_runtime_stop();

    printf("\nPress Enter key to exit");
    getchar();
    PROG_EXIT(0);
}

⌨️ 快捷键说明

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