Dali in the university project on the lab. You need to make an application that will implement simple database capabilities, with maintenance in the console.

Requirements:

  1. Data stored in a text file (read and write).
  2. View the contents of the database.
  3. Adding an entry to the end.
  4. Edit selected entry, more or less folded view. But I decided for my own skills to try to implement something more complicated: the ability to work CRUD sql commands, in their most primitive form, and so that it works accordingly through the console. The application was launched, the database was selected, the "sql command" was entered. But here are the problems, I don’t really understand how.
  5. Delete the selected entry.
  6. Record search based on specified conditions.
  7. Sort entries by selected conditions.

In principle, how to implement this? Therefore, I would be grateful for the general idea of ​​the work or the push in the form of links.

Thank.

  • @TheOwl, If you are given an exhaustive answer, mark it as correct (click on the check mark next to the selected answer). - Vitalina

2 answers 2

Changing records can be done as follows (in principle, this is done in most modern databases):

  • find the old record;
  • check whether there is enough space to write there a new one. If yes, write;
  • if not, then mark the record as deleted (yes, for this you have to allocate one byte / bit) and add the record to the end.

Search records. Again, we look, as done in the "big bases". If there is no index for the field, simply look through the records sequentially and display / memorize the necessary ones. If there is an index, then we look at it. What an index for a numeric field might look like is just the value and line number where it appears. If the field is unique, then just an ordinary binary tree. How to search is understandable. They asked to find records by the required number - they just took ready-made line numbers in the index and that's it.

Sorting. There are no problems here either. They pulled out all the records that fit the condition and applied the usual sort function to them (or as it is called there in Sharp). If there is an index, then, formally, it may be that the records are already sorted.

If you want to do "sub-sql", then you have to write a parser. And this may be a more difficult task. But you can simply limit yourself to minimal syntax, then it will be much easier. For example, select gets only a list of fields and, possibly, one condition for one field.

If you want to see the source code, then look at the sqlite. It is, however, not in C #, but in C, but well documented with tests.

    So as not to bathe much, but for the "complexity" to store all the data in the usual MS Access file (.acdb). With such a thing, the SQL server does not need to be installed, but to access the database using SQL. Here is a look.

    • one
      >> Requirements: 1. Data stored in a text file (read and write) - Zufir