Help me on my SQL emulation project!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help me on my SQL emulation project!!
# 1  
Old 02-17-2010
Help me on my SQL emulation project!!

hello all!!

I am a newbie to shell scripting and to learn it I took a project in which I m facing a tremendous amount
problems....I Need Your HELP!! the Details of project are as follows:

while learning shell scripting, i came up with an idea to make a 'Database/Record management system' as
my major project in this semester
with a specific query language to interact with it. what i wanted was...
as when you type like
Code:
SELECT */EMPNO,ENAME,JOB,SAL FROM EMP

in Oracle , you get the result of
desired fields..i wanted the same thing to happen when i invoke a command in terminal with
column names as arguments... it should get the output as we get in SQL Prompt.

the whole thing i wanted to create a package/utility for unix/linux that could emulate SQL.. i.e, to create
CREATE,SELECT,INSERT, etc all DML, DDL,TCL commands. I named this 'GQL'...
now the whole process should go as follows:

when you type gql in terminal you should get a restricted environment with GQL prompt,

Code:
$ gql           //for entering in the package where other commands & Databases(Directories) stored
//after a while GQL prompt Should appear as
GQL>

Now use the existing database as:
GQL>use <Database_name>    //choosing one of the database(Directory)
//OR
Create a Database as:   // we should not be able to Create table(file) before 'use' command.

GQL>Create database <Database_name>

//Now you can execute DDL  Statments as:


GQL>create table <table_name>
                Fields     Type      Constraint(if any)                    
Field1:
Field2:                                                           #press ctrl+c when done


*******************************************************************************
in simple meaning ..a Database means collection of tables...so creating a database would simply mean creating
a directory and creating a table means creating file in particular directory...
all the record is in the form of text delimited by colon !!

the problem i m facing is how to implement the 'Datatype' & 'Constraints' over the fields..as they are mere the text of a file!!

i have written the 'gql' script which is mere a prompt changing $ path setting script but i wanted that when GQL prompt appears no other shell commands like 'cd', 'mkdir' etc could run it should be a separate environment. plz tell me how can i achieve this.


I have also written the 'project' script which resembles the SQL , SELECT Statement without WHERE Clause....now i want to add the Where clause functionality to it but i cudn't find any approach for it ...plz help!!




********************
i know u'd say that this is of no worth as we already have Oracle, PostgreSQl, MySql....the openoffice Databases..and hundreds of utility of this kind.... which are a thousands times better than this. but its my college project and by the end of semester i have to submit it...and I've already started!! so plz guide me!!!

I want ur reviews , comments, suggestions over the project...its feasibility that what i m thinking of is possible or not....its enhancement and scope.. other alternatives how can i make it better and significance...


I m attaching the screen sccreenschots of my work along with the scripts....
plz Do hav look over it...GUIDE me to optimize the scripts..

NOTE: plz dont Smilie over my scripts .. as i m a newbie!!

Help me on my SQL emulation project!!-createpng

Help me on my SQL emulation project!!-projectpng

emp.doc

create.sh

project.sh




regards,
prayush

Last edited by pludi; 02-17-2010 at 04:03 PM.. Reason: code tags, please...
# 2  
Old 02-18-2010
You should be able to write a script that validates each field before it is added to the database, and at anytime that it is modified.
Some field types would have generic solutions (date/time), others might be specific to the table/field (dept number, salary), others might have to belong to a list.
Either use exit values from the validation script, or test the output from the validation against the input, to decide how to proceed.
Are you planning on having one record per file, and using the directory structure as the indexes?
# 3  
Old 02-18-2010
thanx Jgt for your suggestions!!

what i have planned... consider directory named 'employee'.. now directory contains files related to employee information...just as the the default 'employee' databse of oracle contains tables like emp, dept,location salgrade etc...the directory 'employee' would contain files - emp, dept,location, salgrade etc.

so the a directory is analogous to a database and files are analogous to the tables of any database..

and the information within file is organized as below;
the content of the file 'emp' is:
Code:
empno:ename:job:mgr:sal:comm:deptno
7839:king:president:7839:5000::10
7698:blake:manager:7839:2850::30
7782:clark:manager:7839:2450::10
7654:martin:salesman:7698:1250:1400:20
7788:scott:analyst:7566:3000::20
7900:james:clerk:7698:950::30
7521:ward:salesman:7698:1250:500:30




I have written a script named 'project'..if U see the attached screenshot,, to project the specified columns in arguments to STDOUT. now i want to add up a filtering functionality based on conditions ..as WHERE clause of SQL..please suggest me any approach to accomplish this!!

now i m planning to write a script to insert the values in the file in the form as:

Code:
$insert emp:7788 ward salesman 7689 3000 140 10

now the problem is to validate that while entering the values for 'empno' it shud be integer and for 'ename' it must be characters..so on...please guide me to accomplish this ......
can you please elaborate how can do this using exit values...should i have to make a separate validation script or it shud be a function in the script!!

thanx..
regards.
# 4  
Old 02-18-2010
If you increase the number of directories, you can reduce the number of records per physical file.
For instance
$EMPLMASTER/$DEPT/$EMPLNUMBER/
then in this directory have multiple files but only one record per file
For instance file1 contains employee#, name, address, hire date, date of birth,etc
A second file, file2 contains work history, one field of indeterminate length.
A third file, file3, contains salary information

To SELECT * FROM EMPLMASTER
cat $EMPLMASTER/*/*/file1 >>result

TO SELECT DEPT=1 from EMPLMASTER
cat $EMPLMASTER/1/*/file1 >>result


When you want to validate a field, can we assume for expedience that any invalid value will be replaced by the default value.

So to insert the hire month we will write a simple script that accepts one parameter (month, Jan thru Dec) and checks to see if it is in a table, if not, the current month is used.

Code:
#!/bin/ksh
#validatemonth.ksh
grep $1 monthtable.en
if [ $? -eq 0 ]   #if found 
   echo -e "$1\c"
else
   mon=`date +"%b"`
   echo -e "$mon\c"
fi

monthtable.en is a file containing

Jan
Feb
Mar
Apr
May
...
Dec

And to insert a new record

Code:
echo -e $EMPLNUMBER:$NAME:$TITLE:`validatemonth.ksh $month`:........>$EMPLMASTER/$DEPT/$EMPLNUMBER/file1

Jack

Last edited by jgt; 02-18-2010 at 09:49 PM.. Reason: typos
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

FINDING DUPLICATE PROJECT ( directory project )

I have a project tree like that. after running find command with the -no -empty option, i am able to have a list of non empty directory DO_MY_SEARCH="find . -type d -not -empty -print0" MY_EXCLUDE_DIR1=" -e NOT_IN_USE -e RTMAP -e NOT_USEFULL " echo " " > $MY_TEMP_RESULT_1 while... (2 Replies)
Discussion started by: jcdole
2 Replies

2. News, Links, Events and Announcements

A new project was posted on The UNIX and Linux Forums project board.

A new project was posted on your project board. Project title: Bash Shell Tutoring Estimated Budget: $50/hr Start date: Immediately Required skills: Linux, Bash, Shell, UNIX I work as a datawarehouse designer and developer. Although I usually stick to the role of an analyst,... (0 Replies)
Discussion started by: Neo
0 Replies

3. Solaris

what is the use of /etc/project file and project administration commands?

i have two doubts.. 1. what is the use /etc/project file. i renamed this file and when i tried to switch user or login with some user account the login was happening slowly. but when i renamed it to original name it was working fine... why so? 2. unix already has useradd and grouadd for... (4 Replies)
Discussion started by: chidori
4 Replies

4. UNIX for Dummies Questions & Answers

dc (desk calculator) emulation project

Hey guys, I'm working on a project where we have to duplicate the 'dc' command. I'm having trouble figuring out how to queue the different commands available (such as printing stack contents or saving/executing macros and registers). I'm also having a great deal of trouble finding any literature... (1 Reply)
Discussion started by: wolfe.zach
1 Replies

5. UNIX for Advanced & Expert Users

Bad emulation

I am using mpc8xx processor with linux-2.4.20 kernel. These prints are getting flooded to my console almost consistenly. 14 06:29:17 MC4L-TP01 syslog.warn klogd: pte @ 0x10113d88: (0xc51cc100)->(0xc4bd144c)->0x01eec889 Oct 14 06:29:17 MC4L-TP01 syslog.warn klogd: RPN: 01eec PP: 2 SPS: 1 SH:... (1 Reply)
Discussion started by: subratasaharia
1 Replies

6. Solaris

SSH doesn't pick up user's project from /etc/project

We have a system running ssh. When a user logs in, they do not get the project they are assigned to (they run under "system"). I verify the project using the command "ps -e -o user,pid,ppid,args,project". If you do a "su - username", the user does get the project they are assigned to (and all... (2 Replies)
Discussion started by: kurgan
2 Replies

7. UNIX for Dummies Questions & Answers

Terminal Emulation

Hello all, Am new to the forum and hope this post meets the requirements. This post will be rather lengtly but needs to be to explain the problem. I have two computers running Windows 2000 Pro. I travel for a living and use a terminal emulation program called STEP to connect to our Unix... (2 Replies)
Discussion started by: skids
2 Replies

8. Filesystems, Disks and Memory

about emulation in workstations

i would like about the emulation in workstations. thanks. (2 Replies)
Discussion started by: rmilano
2 Replies
Login or Register to Ask a Question