📄 wtest.c
字号:
printf("List of all records from the department = R&D\n");
/* open a transaction */
rc = mco_trans_start(db, MCO_READ_ONLY, MCO_TRANS_FOREGROUND, &t);
if (rc == MCO_S_OK)
{
/* open the cursor */
rc = Record_I_Department_index_cursor(t, &csr);
if (rc == MCO_S_OK)
{
wchar_t* wbuf = L"R&D";
uint2 len = 3;
/* Search for the first occurence */
i = 1;
rc = Record_I_Department_search(t, &csr, MCO_EQ, wbuf, len);
do
{
int cmp = 0;
/* compare the item */
rc = Record_I_Department_compare(t, &csr, wbuf, len, &cmp);
if (rc == MCO_S_OK && cmp == 0)
{
/* get the record */
rc = Record_from_cursor(t, &csr, &Obj);
if (rc == MCO_S_OK)
{
/* Show the record */
ShowObj(&Obj);
/* move to the next record */
rc = mco_cursor_next(t, &csr);
i++;
};
}
else
{
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");
printf("Alphabetical list\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 = Record_I_Name_index_cursor(t, &csr);
if (rc == MCO_S_OK)
{
/* jump to first record */
rc = mco_cursor_first(t, &csr);
/* take 10 first items */
while (rc == MCO_S_OK)
{
/* get a record from cursor */
rc = Record_from_cursor(t, &csr, &Obj);
if (rc == MCO_S_OK)
{
/* show it */
ShowObj(&Obj);
/* move to the next item */
rc = mco_cursor_next(t, &csr);
};
}
}
else
{
printf("Unable to open cursor");
};
/* close the tramsaction */
rc = mco_trans_commit(t);
}
else
{
printf("Unable to open a transaction");
};
printf("\n");
printf("List of all records where previouse job was = MontaVista\n");
/* open a transaction */
rc = mco_trans_start(db, MCO_READ_ONLY, MCO_TRANS_FOREGROUND, &t);
if (rc == MCO_S_OK)
{
/* open the cursor */
rc = Record_I_PrevJob_index_cursor(t, &csr);
if (rc == MCO_S_OK)
{
wchar_t* wbuf = L"MontaVista";
uint2 len = (uint2)wcslen(wbuf);
/* Search for the first occurence */
i = 1;
rc = Record_I_PrevJob_search(t, &csr, MCO_EQ, wbuf, len);
do
{
int cmp = 0;
/* compare the item */
rc = Record_I_PrevJob_compare(t, &csr, wbuf, len, &cmp);
if (rc == MCO_S_OK && cmp == 0)
{
/* get the record */
rc = Record_from_cursor(t, &csr, &Obj);
if (rc == MCO_S_OK)
{
/* Show the record */
ShowObj(&Obj);
/* move to the next record */
rc = mco_cursor_next(t, &csr);
i++;
};
}
else
{
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");
}
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 = "wddb";
mco_runtime_info_t info;
int rs = 1;
_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, wddb_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);
rs = 0;
}
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)
{
rs = 2;
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(rs);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -