Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6648267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:38:08+00:00 2026-05-26T00:38:08+00:00

I need to code a small/simple database application using C, for my CS degree

  • 0

I need to code a small/simple database application using C, for my CS degree (so using SQLite or any other available application is not an option. In other words, I do need to re-invent the wheel here).

My idea is to use a B-Tree to store the items of each table. The problem I am facing is that tables need to be flexible to hold an unknown number of columns, and each column can be either a STRING or an INT. For example, with this command:

CREATE TABLE student (STRING name, INT age)

I would need to create a table that holds a string and an integer. With this command instead:

CREATE TABLE grade (INT grade1, INT grade2, INT grade3)

I would need to create a table that holds three integers.

How can achieve such flexibility?

My only idea so far is to create a struct with several unions inside it, where each union can be either a STRING or an INT. I would also need to put a lot of unions inside, to be sure to accommodate all the columns requested by the table. For example:

struct table{
    union{
        int number;
        char *text;
    }column1;

    union{
        int number;
        char *text;
    }column2;

    union{
        int number;
        char *text;
    }column3;

    ....

};

Is there a better way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:38:08+00:00Added an answer on May 26, 2026 at 12:38 am

    i can only think of two very different approaches:

    1. make a ‘schema compiler’ that gets the table definition, writes the structs and compiles the database engine.
    2. from the schema definition calculate the byte offset and length of each column. save and restore the records as a byte array and pick the fields using that offset/length list.

    most common is #2, but #1 has the advantage that the C compiler ‘knows’ the table structure, and will type-check your columns.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to code a small record-keeping application for a small business in Windows
With JPA I do not need to code the SQL for every new attribute
I have a console application that require to use some code that need administrator
I am here to write a small database application that will be running in
I've been using JPA on a small application I've been working on. I now
I wrote some code to connect the application to it's database, then I created
I need code in Perl for requesting and parsing ATOM and RSS feeds. Is
how to send rich text message in system.net.mail need code for send a mail
I need to write code that picks up PGP-encrypted files from an FTP location
I need a short code snippet to get a directory listing from an HTTP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.