
Clarisse U.
asked 01/15/21Database management System
Write a menu driven program to create and operate on a relational database that, prospectively, can be used by a library using Java or C++
One relation is stored in one data file. Because these files can have different structure, each file includes a heading that stores information about this structure. This information may include 1. the number of columns in the table, 2. the length of one record, 3. a list of all column names with their lengths.
Write functions/methods createTable(), insert(), remove(), printFile(), and purge() that operate on these files.
The createTable() function creates a file whose name is entered by the user. Here is an example (the underlined entries are typed by the user):
enter table name: books
enter column name and its length: author 20
enter column name and its length: title 20
enter column name and its length: callNo 5
enter column name and its length:
After this, the file books.dbf is created with number 45 for the length of one record and with column names author, title, and callNo in its heading. Also, the newly created file is added to the system catalog dbFiles which is a file created and maintained by your program (if you run your program next time, do not recreate this file!).
insert() allows you to add new entries (records) to a file. For example, you may have the following sequence of entries after choosing the insert option:
enter file name: books
author: Burnett Frances
title: The Secret Garden
callNo: MN432
More entries (Y/n):
author: Wesley John
title: Journal
callNo: PQ945
More entries (Y/n): n
remove() allows you to remove any record from any file. The prompts may be similar to those for inserting records. When deleting a record, put only a tombstone in the data file and continue running your program. A tombstone can be some special character – e.g., the sharp sign # – which is written over the first character in the record.
After exit is chosen from the menu, call the function purge() for all the data files to be found in dbFiles. Purging consists in permanently removing all the removed records from each file.
1 Expert Answer

Patrick B. answered 01/16/21
Math and computer tutor/teacher
OK
I have uploaded some java code that Inserts, Deletes, and Shows the records using sqlite3 database
It is in the RESOURCES section under this link.
You will also need to download the 3rd party tool sqlite3
I am using version 3.7.2
there is a *.dll and the jar file required
OR you can shoot me an email and I'll pass you the link to the folder with all the stuff on my google drive
===============================================================================
As Anthony Hopkins once said..."Hello Clarrise"
Thank you for the challenging project!
The source code I have completed has been uploaded to the RESROUCES section
under this link... unfortunately, there are issues, and I admittedly have taken some liberties
It is a text file called db_proj.txt
it contains the following source code files:
dbTable.h,.cpp
book.h,.cpp
Go.h,.cpp <--- the driver
main.cpp
data files
ISSUES and QUESTIONS
(1) The book call number is defined as 5 bytes, and the input requires
5 bytes, so there is no room for the null terminator. This is a problem.
All of these column lengths should allow for null terminators. So if the
book call # is really 5 bytes, then the column length should be 6.
The same holds for the other columns, bringing the record size to 48, instead
of 45. That is also the problem with allowing the user to input these manually.
Finally, the author is only 20 bytes long. A book with multiple authors will not fit.
I ran across this very problem with record #3 in the data. I was separating the first
and last names with %, and if there is more than one author, I was separating them
with the semi-colon; That makes the names fields more easily parsed!
So for example on record #3: "Numerical Analysis" the authors are J.Douglas Faires
and Richard Burden...
The CSV record is then:
AR753,Numerical Analysis,Faires%J.Douglas;Burden%Richard
So Question #1: Are we allowed to change the sizes and/or the format of the input data????
(2) marking records for deletion is a BAD idea. the record can still be accessed
even while it's marked for deletion. In the real world, there are race conditions
that make this a disastrous nightmare.
I would approach the record deletion in the dbTable structure as follows:
step 1: locate the record to be deleted and store its index position in
the array
step 2: copy the records before it into the temporary array
step 3: move past the target record to be deleted
step 4: copy the rest of the records into the temporary array
step 5: point the array pointer at the temporary and set the temp to NULL;
DECREMENT the record count
step 6: call DBTable_Write();
So Question #2: Are we allowed to delete the records while we got them buffered
or do we really have to mark them for deletion and purge on exit?
(3) not sure what OS you got, so the byte order may read these records backwards..
endion/indian mismatch; I'm running Bloodshed Dev C++ on win10
(4) the design of the *.dbf file is arguably unclear. It says the file "MAY include...";
I am using only the record size and the # of records currently in the data file;
The names and # of columns do not matter with binary files.
As you can see, I am reading the entire file into the array with fread();
Question #3: DO we really have to store the column names and sizes?
Keep Issues #1-2 in mind...
(5) Are you allowed to use an actual RDBMS driver for this project?
I've got sqlite for Java and it will make this whole project MUCH easier
because you will not have to "RE-INVENT the WHEEL";
You can actually do REAL SQL Queries with it...
Question #4: Are you allowed to use a REAL database drive, so that
this can be done in java, instead of having to re-invent the wheel?
(6) The sorting and searching can be down with qsort and bsearch in stdlib.h;
I have already implemented the callbacks for comparing the book records by
author,title, and call #;
In an attempt to make this db more generic, I am using callbacks to input,
parse, and serialize
(7) Rather than having to input the data every time, I prefer to store the
input data in a file and read from it; hence TEXT to Binary...
The input records are stored in books.csv
(8) I was going to use a SECOND table called MEMBERS, but scrapped the idea
once these issues happened.
member.idCard#, memberName, memberBalance, expirationDate, etc.
---------------------
I cannot go any further until you answer and respond to
AT LEAST issues #1,2 and #5. That is, specifically, we must pin
down the sizes of these field columns EXACTLY (including null terminators)
if you want to continue with the C++ solution...OR we can scrap it at use a REAL
database driver that is STABLE and do it in java, which is MUCH easier.
I would recommend the latter, so we do not have to re-invent the wheel
My email, in ENGLISH so wyzant does not flag it, is:
patrick dot baldwin dot 1 at wyzant dot com
Please let me know what you want to do and I look forward to
hearing from you.
Clarisse U.
First of all thank you so much for the work you have done so far. I was not able to see the source code but i read through your command. This project is a beginning for a database class, and we should except some errors and we should not use complicated concepts. With that being said, I think we can use JAVA to make it more easy and faster. Question #1.We have to keep the size and the format of the input regardless that some inputs won't be able to fit in. Question #2. We are not allowed to delete the data just have to mark them for deletion and purge on exit. I hope this is helpful and please don't hesitate to reach out in case you need more clarity. Lastly if you can help me see the source code that would be appreciated.01/16/21
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Patrick B.
Also, a bit unclear from the beginning... "create and operate on a relational database that, prospectively, can be used by a library using Java or C++"; Relational database consists of 2 or more tables, which I attempted to do.. but then you got primary keys, foreign keys, composite keys, etc. ,,,, Can prospectively be used by a library... do we need to compile it to a *.lib or *.dll? Is this a windows app or a console app?01/16/21