最近在尝试使用fastdb进行开发,c++版本下测试基本ok,由于项目组采用C#开发,所以转用C#开发fastdb,结果发现C#版本各种阉割,如果定义变量自增,则会发生类型定义错误报错,一番追查下来发现是在fastdb
取值时未定义cli_autoincrement造成的。
由于fastdb对cli_autoincrement的处理方式类似于int4,所以对其进行类似int4类型的类型转换
修改代码如下:
protected unsafe virtual Object getValue(Type t) {
switch((CLI.FieldType)((CLI.UnmanagedBuffer*)buffer.ToPointer())->type) {
case CLI.FieldType.cli_bool:
case CLI.FieldType.cli_int1: return Convert.ChangeType(*(sbyte*)((CLI.UnmanagedBuffer*)buffer.ToPointer())->data.ToPointer(), t);
case CLI.FieldType.cli_int2: return Convert.ChangeType(*(short*)((CLI.UnmanagedBuffer*)buffer.ToPointer())->data.ToPointer(), t);
case CLI.FieldType.cli_oid: return Convert.ChangeType(*(uint*)((CLI.UnmanagedBuffer*)buffer.ToPointer())->data.ToPointer(), t);
case CLI.FieldType.cli_autoincrement: return Convert.ChangeType(*(int*)((CLI.UnmanagedBuffer*)buffer.ToPointer())->data.ToPointer(), t);
case CLI.FieldType.cli_int4: return Convert.ChangeType(*(int*)((CLI.UnmanagedBuffer*)buffer.ToPointer())->data.ToPointer(), t);
case CLI.FieldType.cli_int8: return Convert.ChangeType(*(Int64*)((CLI.UnmanagedBuffer*)buffer.ToPointer())->data.ToPointer(), t);
case CLI.FieldType.cli_real4: return Convert.ChangeType(*(Single*)((CLI.UnmanagedBuffer*)buffer.ToPointer())->data.ToPointer(), t);
case CLI.FieldType.cli_datetime:
case CLI.FieldType.cli_real8: return Convert.ChangeType(*(double*)((CLI.UnmanagedBuffer*)buffer.ToPointer())->data.ToPointer(), t);
case CLI.FieldType.cli_asciiz:
case CLI.FieldType.cli_pasciiz: return Convert.ChangeType(Marshal.PtrToStringAnsi(((CLI.UnmanagedBuffer*)buffer.ToPointer())->data), t);
case CLI.FieldType.cli_array_of_int1:
if (t == typeof(byte[])) {
int len = Size;
byte[] arr = new byte[len];
byte* src = (byte*)((CLI.UnmanagedBuffer*)buffer.ToPointer())->data.ToPointer();
for (int i = 0; i < len; i++) {
arr[i] = *src++;
}
return arr;
} else {
throw new CliError("getValue: Unsupported conversion type! "+Enum.GetName(typeof(CLI.FieldType), ((CLI.UnmanagedBuffer*)buffer.ToPointer())->type));
}
default: throw new CliError("getValue: Unsupported type!"+Enum.GetName(typeof(CLI.FieldType), ((CLI.UnmanagedBuffer*)buffer.ToPointer())->type));
}
}
再次运行,ok,运行通过
个人感觉
fastdb文献资料过少,社区不活跃,欢迎大家积极贡献。
fastdb的查询速度在同类数据库中处于前列。
fastdb的C#版本就是C++版本的封装,而且属于未完成版,进行商用开发请慎用。
版权声明:本文为博主原创文章,未经博主允许不得转载。