Fastdb 之定義cli_autoincrement 自增變數報錯,fastdbcli

來源:互聯網
上載者:User

Fastdb 之定義cli_autoincrement 自增變數報錯,fastdbcli

最近在嘗試使用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++版本的封裝,而且屬於未完成版,進行商用開發請慎用。

 


著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.