【问题标题】:Realtional Databases and Query关系数据库和查询
【发布时间】:2013-03-14 04:04:09
【问题描述】:

我想尝试对关系数据库进行一些查询操作。例如

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

第一行是这个关系表中有多少个属性 其他行属性和类型(字符串/整数)和属性大小(字节)

第二个文件是二进制文件,每行数据都有一个信息。 “讴歌 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
}

但我不确定我的想法是否正确。

【问题讨论】:

  • 您在一篇文章中提出了太多问题。请阅读FAQHow to Ask,了解如何写出好问题。
  • @JimGarrison 我的问题实际上是我无法解读他的实际问题是什么。 ccc,您已经解释了您的问题,但没有明确提出您的问题。请更清楚地重新表述您的问题
  • 抱歉,我只想问一下我的结构定义是真的吗?

标签: c database struct


【解决方案1】:

您可以根据文件结构松散地为您的 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
};

【讨论】:

    猜你喜欢
    • 2016-06-10
    • 2016-05-25
    • 1970-01-01
    • 1970-01-01
    • 2022-11-17
    • 1970-01-01
    • 1970-01-01
    • 2016-05-03
    • 2021-09-01
    相关资源
    最近更新 更多