0

リレーショナル データベースでいくつかのクエリ操作を実行してみたいと思います。たとえば

relation cars

    brandname     type     year   
       acura        suv       2012
        bmw          sedan     2013

および/または

relation transport

transport vehicle       capacity    ticketprice
bus                          40        30
airplane                   300         500
taxi                          3        125

in this database has up to 100 relations.
each relation could has 10 attributes.
each relation could has 10000 row data.

このデータベースには 1 つのテキスト ファイルがあります。このファイル、2 台の車の輸送

最初の行は、このファイルにどのような関係がありますか? およびその他の行の関係の名前。

リレーションごとに 2 つの異なるファイルがあります。最初の 1 つのテキスト ファイル、

3
brandname  String  20
type       String  10
year       Int     4

最初の行は、このリレーション テーブル内の属性の数です。他の行の属性と型 (文字列/整数) および属性のサイズ (バイト)

2 番目のファイルはバイナリ ファイルで、各行データに関する情報があります。「acura suv 2012」ですが、バイナリです。

そう、

そんなことを考えているのですが、

まず、次のような構造体を作成する必要があります。

struct relation{
char attribute[10];
char row[10000];
}

struct row {
char type[2]; //string or integer
char title[???];   //i think i have to read from binary file how many title in this file  ??
long size;   //how many bytes size of each attribute
}

しかし、私の考えが正しいかどうかはわかりません。

4

1 に答える 1

0

ファイル構造に基づいて、C データ構造を大まかにモデル化できます。

struct attribute
{
    char title[17+1]; // or whatever the max. title string length; e. g. "year"
    char type;
    long size;
    unsigned char **data; // dynamically allocate data[0] up to data[10000-1]
};

struct relation
{
    char name[9+1];   // e. g. "cars", "transport"
    int how_many_attributes;
    struct attribute att[10]; // up to 10
};

struct database
{
    int how_many_relations;
    struct relation rel[100]; // up to 100
};
于 2014-06-10T12:10:36.163 に答える