尊敬的前辈,
大家好!
我在网上看到了关于extremedb的文章,在实际操作时碰到了一些问题,想和大家探讨一下。
1、我先安装了extremedb_3.1_win32_sql_log_eval_1B.EXE,
2、然后用安装目录(C:/McObject/eXtremeDB_SQL_LOG/win32/host/bin)下的mcocomp.exe对test.mco文件进行了编译,test.mco文件代码如下:
#define int1 signed<1>
#define int2 signed<2>
#define int4 signed<4>
#define int8 signed<8>
#define uint8 unsigned<8>
#define uint4 unsigned<4>
#define uint2 unsigned<2>
#define uint1 unsigned<1>
declare database testdb; //申明一个数据库定义名称
compact class Myclass //表名字
{
unsigned<4> id;
char<20> strnname;
string straddress;
unique tree<id> pkey; //索引
};
#define int2 signed<2>
#define int4 signed<4>
#define int8 signed<8>
#define uint8 unsigned<8>
#define uint4 unsigned<4>
#define uint2 unsigned<2>
#define uint1 unsigned<1>
declare database testdb; //申明一个数据库定义名称
compact class Myclass //表名字
{
unsigned<4> id;
char<20> strnname;
string straddress;
unique tree<id> pkey; //索引
};
3、编译成功后生成了如下两个文件:testdb.c,testdb.h
testdb.c的代码如下:
/* Generated by eXtremeDB Schema Compiler, build 468
* at Fri Jul 31 09:44:42 2009
*/
* at Fri Jul 31 09:44:42 2009
*/
#include "testdb.h"
#include "mcowrap.h"
#include "mcowrap.h"
/*---------------------------------------------------------------------*/
/* dictionary */
mco_dictionary_h testdb_get_dictionary(void)
{
static mco_dictionary_t dict;
static int dictionary_ready = 0;
{
static mco_dictionary_t dict;
static int dictionary_ready = 0;
if( ! dictionary_ready )
{
static mco_dict_field_t v_field_info[3] = {
/* Myclass */
{"id", {4, 4, 0, 4, 4, 0}, 3, 8, 0, -1, 4, -1, 0, 0, -1, 0 /* 1 */},
{"straddress", {2, 2, 4, 4, 4, 4}, 8, 0, 0, -1, 0, -1, 0, 2, -1, 0 /* 3 */},
{"strnname", {20, 1, 6, 20, 1, 8}, 7, 0, 0, -1, 20, -1, 0, 1, -1, 0 /* 2 */}
};
{
static mco_dict_field_t v_field_info[3] = {
/* Myclass */
{"id", {4, 4, 0, 4, 4, 0}, 3, 8, 0, -1, 4, -1, 0, 0, -1, 0 /* 1 */},
{"straddress", {2, 2, 4, 4, 4, 4}, 8, 0, 0, -1, 0, -1, 0, 2, -1, 0 /* 3 */},
{"strnname", {20, 1, 6, 20, 1, 8}, 7, 0, 0, -1, 20, -1, 0, 1, -1, 0 /* 2 */}
};
static mco_dict_struct_t v_struct_info[1] = {
{ "Myclass", 1, 3, (v_field_info + 0), 26, 4, 28, 4 }
};
{ "Myclass", 1, 3, (v_field_info + 0), 26, 4, 28, 4 }
};
dictionary_ready = 1;
{
static const char * v_class_names[] =
{
0,
"Myclass" , /* [1] */
0
};
static const char * v_class_names[] =
{
0,
"Myclass" , /* [1] */
0
};
dict.str_class_names = v_class_names;
}
}
{
static const char * v_index_names[] =
{
"Myclass.pkey" , /* [0] */
0
};
dict.str_index_names = v_index_names;
}
}
{
static mco_dict_class_info_t class_inf[2] = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, -1, -1, 0, 0, -1, 0, 0, -1, -2, 8, (v_struct_info + 0), 26, 0, -1, -1, -1 } /* Myclass */
};
dict.v_class_info = class_inf;
}
static mco_dict_class_info_t class_inf[2] = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, -1, -1, 0, 0, -1, 0, 0, -1, -2, 8, (v_struct_info + 0), 26, 0, -1, -1, -1 } /* Myclass */
};
dict.v_class_info = class_inf;
}
dict.v_desc_events = (mco_dict_event_t *)0;
dict.v_all_struct = v_struct_info;
{
static mco_dict_index_field_t v_all_index_fields[ 1] = {
{ 0, -1, 4, 3, 0, 1 } /* [0] id */
};
{
static mco_dict_index_field_t v_all_index_fields[ 1] = {
{ 0, -1, 4, 3, 0, 1 } /* [0] id */
};
static mco_dict_index_t v_all_indexes_info[ 1] = {
{ 1, 1, -1, 2051, & v_all_index_fields[0], 0 } /* Myclass.pkey [0] */
};
{ 1, 1, -1, 2051, & v_all_index_fields[0], 0 } /* Myclass.pkey [0] */
};
dict.v_desc_indexes = v_all_indexes_info;
}
}
dict.version_major = 3;
dict.version_minor = 1;
dict.version_build = 468;
dict.magic_number = 7;
dict.oid_is_supported = 0;
dict.auto_oid_supported = 0;
dict.flags = 0;
dict.n_class_codes = 1;
dict.n_list_indexes = 0;
dict.n_autoid_indexes = 0;
dict.n_history_indexes = 0;
dict.n_desc_indexes = 1;
dict.n_desc_events = 0;
dict.n_structs = 1;
dict.num_oid_estimation = 0;
dict.num_HA_estimation = 0;
dict.max_numof_indexes_per_obj = 1;
dict.exact_OID_sizeof = 0;
dict.layout_OID_size = 0;
}
dict.version_minor = 1;
dict.version_build = 468;
dict.magic_number = 7;
dict.oid_is_supported = 0;
dict.auto_oid_supported = 0;
dict.flags = 0;
dict.n_class_codes = 1;
dict.n_list_indexes = 0;
dict.n_autoid_indexes = 0;
dict.n_history_indexes = 0;
dict.n_desc_indexes = 1;
dict.n_desc_events = 0;
dict.n_structs = 1;
dict.num_oid_estimation = 0;
dict.num_HA_estimation = 0;
dict.max_numof_indexes_per_obj = 1;
dict.exact_OID_sizeof = 0;
dict.layout_OID_size = 0;
}
return &dict;
}
}
MCO_RET Myclass_new ( mco_trans_h t, /*OUT*/ Myclass *handle )
{ return mco_w_new_obj_noid( t, 26, 1, (mco_objhandle_h)handle);
}
{ return mco_w_new_obj_noid( t, 26, 1, (mco_objhandle_h)handle);
}
MCO_RET Myclass_delete ( Myclass *handle )
{ return mco_w_obj_delete( (mco_objhandle_h)handle);
}
{ return mco_w_obj_delete( (mco_objhandle_h)handle);
}
MCO_RET Myclass_delete_all ( mco_trans_h t )
{ return mco_w_obj_delete_all( t, 1 );
}
{ return mco_w_obj_delete_all( t, 1 );
}
MCO_RET Myclass_checkpoint ( Myclass *handle )
{ return mco_w_obj_checkpoint( (mco_objhandle_h)handle );
}
{ return mco_w_obj_checkpoint( (mco_objhandle_h)handle );
}
MCO_RET Myclass_pack ( Myclass *handle, /*OUT*/ uint4 * pages_released )
{ return mco_w_compact( (mco_objhandle_h)handle, 1, 0, pages_released);
}
{ return mco_w_compact( (mco_objhandle_h)handle, 1, 0, pages_released);
}
MCO_RET Myclass_id_get ( Myclass *handle, /*OUT*/ uint4 * result)
{ return mco_w_b4_get( (mco_objhandle_h) handle, 0, result);
}
{ return mco_w_b4_get( (mco_objhandle_h) handle, 0, result);
}
MCO_RET Myclass_id_put ( Myclass *handle, uint4 value )
{ return mco_w_b4_put( (mco_objhandle_h) handle, 0, 1, *(uint4*)& value);
}
{ return mco_w_b4_put( (mco_objhandle_h) handle, 0, 1, *(uint4*)& value);
}
MCO_RET Myclass_strnname_get ( Myclass *handle, /*OUT*/ char * dest, uint2 dest_size)
{ return mco_w_chars_get2( (mco_objhandle_h) handle, 8, 6, dest, dest_size, 20);
}
{ return mco_w_chars_get2( (mco_objhandle_h) handle, 8, 6, dest, dest_size, 20);
}
MCO_RET Myclass_strnname_put ( Myclass *handle, const char * src, uint2 len)
{ return mco_w_chars_put2( (mco_objhandle_h)handle, 8, 6, src, len, 20, 0);
}
{ return mco_w_chars_put2( (mco_objhandle_h)handle, 8, 6, src, len, 20, 0);
}
MCO_RET Myclass_straddress_get ( Myclass *handle, /*OUT*/ char * dest, uint2 dest_size, /*OUT*/ uint2 * len)
{ return mco_w_string_get2( (mco_objhandle_h) handle, 4, 4, dest, dest_size, len);
}
{ return mco_w_string_get2( (mco_objhandle_h) handle, 4, 4, dest, dest_size, len);
}
MCO_RET Myclass_straddress_size ( Myclass *handle, /*OUT*/ uint2 *result)
{ return mco_w_string_len2( (mco_objhandle_h) handle, 4, 4, result);
}
{ return mco_w_string_len2( (mco_objhandle_h) handle, 4, 4, result);
}
MCO_RET Myclass_straddress_put ( Myclass *handle, const char * src, uint2 len)
{ return mco_w_string_put2( (mco_objhandle_h) handle, 4, 4, src, len, 0);
}
{ return mco_w_string_put2( (mco_objhandle_h) handle, 4, 4, src, len, 0);
}
MCO_RET Myclass_from_cursor ( mco_trans_h t, mco_cursor_h c, /*OUT*/ Myclass *handle )
{ return mco_w_obj_from_cursor( t, c, 1, (mco_objhandle_h)handle );
}
{ return mco_w_obj_from_cursor( t, c, 1, (mco_objhandle_h)handle );
}
MCO_RET Myclass_pkey_index_cursor ( mco_trans_h t, /*OUT*/ mco_cursor_h c )
{ return mco_w_index_cursor( t, 0, c );
}
{ return mco_w_index_cursor( t, 0, c );
}
MCO_RET Myclass_pkey_search ( mco_trans_h t, /*INOUT*/ mco_cursor_h c, MCO_OPCODE op_, uint4 id )
{ mco_external_field_t a_ [1];
mco_external_field_h pa_ = a_;
pa_->field_type = 3; pa_->v.u4 = id;
{ mco_external_field_t a_ [1];
mco_external_field_h pa_ = a_;
pa_->field_type = 3; pa_->v.u4 = id;
return mco_w_tree_find(t,c,op_,a_);
}
}
MCO_RET Myclass_pkey_compare ( mco_trans_h t, mco_cursor_h c, uint4 id, /*OUT*/ int *result_ )
{ mco_external_field_t a_[1];
mco_external_field_h pa_ = a_;
pa_->field_type = 3; pa_->v.u4 = id;
return mco_w_cursor_compare( t, c, a_, result_);
}
{ mco_external_field_t a_[1];
mco_external_field_h pa_ = a_;
pa_->field_type = 3; pa_->v.u4 = id;
return mco_w_cursor_compare( t, c, a_, result_);
}
MCO_RET Myclass_pkey_pattern_size ( uint4 id, /*OUT*/ uint4 *size_)
{ mco_external_field_t a_ [2];
mco_external_field_h pa_ = a_;
pa_->field_type = 3; pa_->v.u4 = id;
(pa_+1)->field_type=0;
*size_=mco_w_pattern_size(0, a_);
return MCO_S_OK;
}
{ mco_external_field_t a_ [2];
mco_external_field_h pa_ = a_;
pa_->field_type = 3; pa_->v.u4 = id;
(pa_+1)->field_type=0;
*size_=mco_w_pattern_size(0, a_);
return MCO_S_OK;
}
MCO_RET Myclass_pkey_pattern_search ( mco_trans_h t, /*INOUT*/ void *allocated_pattern, uint4 memsize, /*OUT*/ Myclass *obj, uint4 id )
{ mco_external_field_t a_ [2];
mco_external_field_h pa_ = a_;
pa_->field_type = 3; pa_->v.u4 = id;
(pa_+1)->field_type=0;
return mco_w_pattern_search(t, 0, allocated_pattern, memsize, (mco_objhandle_h )obj, a_);
}
{ mco_external_field_t a_ [2];
mco_external_field_h pa_ = a_;
pa_->field_type = 3; pa_->v.u4 = id;
(pa_+1)->field_type=0;
return mco_w_pattern_search(t, 0, allocated_pattern, memsize, (mco_objhandle_h )obj, a_);
}
MCO_RET Myclass_pkey_pattern_next ( mco_trans_h t, /*INOUT*/ void *allocated_pattern, /*OUT*/ Myclass *obj)
{ return mco_w_pattern_next(t, 0 , allocated_pattern, (mco_objhandle_h) obj, 0);
}
{ return mco_w_pattern_next(t, 0 , allocated_pattern, (mco_objhandle_h) obj, 0);
}
MCO_RET Myclass_pkey_locate ( mco_trans_h t, /*OUT*/ mco_cursor_h c, Myclass * handle)
{ return mco_w_cursor_locate( t, 0, (mco_objhandle_h)handle, c);
}
{ return mco_w_cursor_locate( t, 0, (mco_objhandle_h)handle, c);
}
MCO_RET Myclass_pkey_find ( mco_trans_h t, uint4 id, /*OUT*/ Myclass *handle_)
{ mco_external_field_t a_[1];
mco_external_field_h pa_ = a_;
pa_->field_type = 3; pa_->v.u4 = id;
return mco_w_tree_find_scalar(t, 0, a_, (mco_objhandle_h)handle_);
}
{ mco_external_field_t a_[1];
mco_external_field_h pa_ = a_;
pa_->field_type = 3; pa_->v.u4 = id;
return mco_w_tree_find_scalar(t, 0, a_, (mco_objhandle_h)handle_);
}
testdb.h的代码如下:
/* Generated by eXtremeDB Schema Compiler, build 468
* at Fri Jul 31 09:44:42 2009
*/
* at Fri Jul 31 09:44:42 2009
*/
#ifndef __MCO__testdb__H__
#define __MCO__testdb__H__
#define __MCO__testdb__H__
#ifndef MCO_CFG_WCHAR_SUPPORT
#define MCO_CFG_WCHAR_SUPPORT
#include <wchar.h>
#endif
#define MCO_CFG_WCHAR_SUPPORT
#include <wchar.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
extern "C" {
#endif
#include "mco.h"
#define MCO_COMP_VER_MAJOR 3
#define MCO_COMP_VER_MINOR 1
#define MCO_COMP_BUILD_NUM 468
#define MCO_COMP_VER_MINOR 1
#define MCO_COMP_BUILD_NUM 468
/*---------------------------------------------------------------------*/
/* Handles and Class Codes */
/* Handles and Class Codes */
typedef struct Myclass_ { MCO_Hf h; } Myclass;
#define Myclass_code 1
#define Myclass_code 1
/*---------------------------------------------------------------------*/
/* Dictionary */
/* Dictionary */
mco_dictionary_h testdb_get_dictionary(void);
/*---------------------------------------------------------------------*/
/* class Myclass methods */
MCO_RET Myclass_new ( mco_trans_h t, /*OUT*/ Myclass *handle );
MCO_RET Myclass_delete ( Myclass *handle );
MCO_RET Myclass_delete_all ( mco_trans_h t );
MCO_RET Myclass_checkpoint ( Myclass *handle );
MCO_RET Myclass_pack ( Myclass *handle, /*OUT*/ uint4 * pages_released );
MCO_RET Myclass_delete ( Myclass *handle );
MCO_RET Myclass_delete_all ( mco_trans_h t );
MCO_RET Myclass_checkpoint ( Myclass *handle );
MCO_RET Myclass_pack ( Myclass *handle, /*OUT*/ uint4 * pages_released );
MCO_RET Myclass_id_get ( Myclass *handle, /*OUT*/ uint4 * result);
MCO_RET Myclass_id_put ( Myclass *handle, uint4 value );
MCO_RET Myclass_id_put ( Myclass *handle, uint4 value );
MCO_RET Myclass_strnname_get ( Myclass *handle, /*OUT*/ char * dest, uint2 dest_size);
MCO_RET Myclass_strnname_put ( Myclass *handle, const char * src, uint2 len) ;
MCO_RET Myclass_strnname_put ( Myclass *handle, const char * src, uint2 len) ;
MCO_RET Myclass_straddress_get ( Myclass *handle, /*OUT*/ char * dest, uint2 dest_size, /*OUT*/ uint2 * len);
MCO_RET Myclass_straddress_size ( Myclass *handle, /*OUT*/ uint2 *result);
MCO_RET Myclass_straddress_put ( Myclass *handle, const char * src, uint2 len);
MCO_RET Myclass_straddress_size ( Myclass *handle, /*OUT*/ uint2 *result);
MCO_RET Myclass_straddress_put ( Myclass *handle, const char * src, uint2 len);
MCO_RET Myclass_from_cursor ( mco_trans_h t, mco_cursor_h c, /*OUT*/ Myclass *handle );
MCO_RET Myclass_pkey_index_cursor ( mco_trans_h t, /*OUT*/ mco_cursor_h c );
MCO_RET Myclass_pkey_search ( mco_trans_h t, /*INOUT*/ mco_cursor_h c, MCO_OPCODE op_, uint4 id );
MCO_RET Myclass_pkey_compare ( mco_trans_h t, mco_cursor_h c, uint4 id, /*OUT*/ int *result_ );
MCO_RET Myclass_pkey_pattern_size ( uint4 id, /*OUT*/ uint4 *size_);
MCO_RET Myclass_pkey_pattern_search ( mco_trans_h t, /*INOUT*/ void *allocated_pattern, uint4 memsize, /*OUT*/ Myclass *obj, uint4 id );
MCO_RET Myclass_pkey_pattern_next ( mco_trans_h t, /*INOUT*/ void *allocated_pattern, /*OUT*/ Myclass *obj);
MCO_RET Myclass_pkey_locate ( mco_trans_h t, /*OUT*/ mco_cursor_h c, Myclass * handle);
MCO_RET Myclass_pkey_find ( mco_trans_h t, uint4 id, /*OUT*/ Myclass *handle_);
MCO_RET Myclass_pkey_search ( mco_trans_h t, /*INOUT*/ mco_cursor_h c, MCO_OPCODE op_, uint4 id );
MCO_RET Myclass_pkey_compare ( mco_trans_h t, mco_cursor_h c, uint4 id, /*OUT*/ int *result_ );
MCO_RET Myclass_pkey_pattern_size ( uint4 id, /*OUT*/ uint4 *size_);
MCO_RET Myclass_pkey_pattern_search ( mco_trans_h t, /*INOUT*/ void *allocated_pattern, uint4 memsize, /*OUT*/ Myclass *obj, uint4 id );
MCO_RET Myclass_pkey_pattern_next ( mco_trans_h t, /*INOUT*/ void *allocated_pattern, /*OUT*/ Myclass *obj);
MCO_RET Myclass_pkey_locate ( mco_trans_h t, /*OUT*/ mco_cursor_h c, Myclass * handle);
MCO_RET Myclass_pkey_find ( mco_trans_h t, uint4 id, /*OUT*/ Myclass *handle_);
#ifdef __cplusplus
} // extern "C"
#endif
} // extern "C"
#endif
#endif
4、然后用VC++6.0新建了一个工程Myproject,并把testdb.c,testdb.h拷到了该工程目录下,然后将testdb.c,testdb.h加入到该工程
4、然后用VC++6.0新建了一个工程Myproject,并把testdb.c,testdb.h拷到了该工程目录下,然后将testdb.c,testdb.h加入到该工程
5、接着设置了Myproject,
(1)在project/setting中选择link,将category选为general,在其后加入mcolib_shm.lib,并将mcolib_shm.lib拷到Myproject目录中
(2)在project/setting中选择C/C++,将category选为code generation,
将use run-time library选为debug multithreaded dll
6、新建一个源文件Mytest.c,代码如下:
#include<ctype.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include "testdb.h"
const char *dbname="demo ShmDb";
const int SEGSZ=1024*1024*10;
const uint2 PAGESIZE=90;
const int MAP_ADDRESS=0x200000000;
void SH(void)
{
char test[]={"嵌入式实时数据库演示/n"};
char text1[]={"Copyright(c)2001-2005 Mcobject LLC.All Right Reserved./n"};
printf("%s/n eXtremeDB runtime version %d.%d,build %d/n %s/n/n Press Enter to Start",text,MCO_COMP_VER_MAJOR,MCO_COMP_VER_MINOR,MCO_COMP_BUILD_NUM,text1);
getchar();
}
static int askNumber(const char *prompt)
{
char buf[100];
printf("/n%s",prompt);
fgets(buf,sizeof(buf),stdin);
if(isdigit(buf[0]))
return atoi(buf);
return -1;
}
static char *askString(const char *prompt)
{
char buf[300];
static char buf1[300];
printf("/n%s",prompt);
}
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include "testdb.h"
const char *dbname="demo ShmDb";
const int SEGSZ=1024*1024*10;
const uint2 PAGESIZE=90;
const int MAP_ADDRESS=0x200000000;
void SH(void)
{
char test[]={"嵌入式实时数据库演示/n"};
char text1[]={"Copyright(c)2001-2005 Mcobject LLC.All Right Reserved./n"};
printf("%s/n eXtremeDB runtime version %d.%d,build %d/n %s/n/n Press Enter to Start",text,MCO_COMP_VER_MAJOR,MCO_COMP_VER_MINOR,MCO_COMP_BUILD_NUM,text1);
getchar();
}
static int askNumber(const char *prompt)
{
char buf[100];
printf("/n%s",prompt);
fgets(buf,sizeof(buf),stdin);
if(isdigit(buf[0]))
return atoi(buf);
return -1;
}
static char *askString(const char *prompt)
{
char buf[300];
static char buf1[300];
printf("/n%s",prompt);
}
7、然后编译,提示错误:
--------------------Configuration: Myproject - Win32 Debug--------------------
Compiling...
Mytest.c
C:/123/Myproject/Mytest.c(9) : warning C4305: 'initializing' : truncation from 'const __int64 ' to 'const int '
C:/123/Myproject/Mytest.c(28) : warning C4101: 'buf' : unreferenced local variable
Linking...
LINK : warning LNK4098: defaultlib "MSVCRT" conflicts with use of other libs; use /NODEFAULTLIB:library
MSVCRTD.lib(crtexe.obj) : error LNK2001: unresolved external symbol _main
Debug/Myproject.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.
Compiling...
Mytest.c
C:/123/Myproject/Mytest.c(9) : warning C4305: 'initializing' : truncation from 'const __int64 ' to 'const int '
C:/123/Myproject/Mytest.c(28) : warning C4101: 'buf' : unreferenced local variable
Linking...
LINK : warning LNK4098: defaultlib "MSVCRT" conflicts with use of other libs; use /NODEFAULTLIB:library
MSVCRTD.lib(crtexe.obj) : error LNK2001: unresolved external symbol _main
Debug/Myproject.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.
Myproject.exe - 1 error(s), 0 warning(s)
小结:我估计是Mytest.c写得不完整,这个代码是在一个帖子里看到的,里面没有main函数。
请问大家能能写出一个完整的Mytest.c吗?然后给我发过来吗?我现在水平有限,目前只能照搬别人的代码,只是想先按照提示做出点东西。
期待着大家的回复!谢谢了!