我想尝试对关系数据库进行一些查询操作。例如
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.
在这个数据库中有一个文本文件。这个文件, 2 汽车 传输
第一行该文件中的任何关系如何?和其他行的关系名称。
每个关系有2个不同的文件。第一个文本文件,
3
brandname String 20
type String 10
year Int 4
第一行是此关系表中的多少属性 其他行属性和类型(字符串/整数)和属性大小(字节)
第二个文件是二进制文件,有关于每个行数据的信息。 “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
}
但我不确定我的想法是否属实。
答案 0 :(得分: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
};