Skip to content

Commit 3f6f862

Browse files
author
dynmi
committed
fix bug
1 parent 8a8a2d2 commit 3f6f862

File tree

10 files changed

+997
-424
lines changed

10 files changed

+997
-424
lines changed

doc/internal.md

Lines changed: 18 additions & 0 deletions
Large diffs are not rendered by default.

doc/structure.png

24.4 KB
Loading

doc/user.md

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
# WSQL Toturial
2+
3+
## Supported Comparision Operations
4+
5+
<table>
6+
<tr>
7+
<th>= </th>
8+
<th> != </th>
9+
<th> < </th>
10+
<th> > </th>
11+
<th> <= </th>
12+
<th> >= </th>
13+
</tr >
14+
</table>
15+
16+
## Supported Data Type
17+
18+
<table>
19+
<tr>
20+
<th> TYPE </th>
21+
<th> LENGTH(Byte) </th>
22+
</tr >
23+
<tr>
24+
<th> int整型 </th>
25+
<th> 4 </th>
26+
</tr >
27+
<tr>
28+
<th> string字符串型 </th>
29+
<th> 1~MAXLEN </th>
30+
</tr >
31+
<tr>
32+
<th> float浮点型 </th>
33+
<th> 4 </th>
34+
</tr >
35+
</table>
36+
37+
## Installation (Only support Linux)
38+
39+
```
40+
git clone git@github.com:Dynmi/WSQL.git
41+
cd WSQL
42+
sudo make clean && sudo make all
43+
```
44+
45+
## Usage
46+
47+
Use ```./wsql``` to start WSQL.
48+
49+
Each sentence should be ended with ";".
50+
51+
### DML
52+
53+
#### `list databases`
54+
55+
This will list all databases.
56+
57+
#### `create database <database name>`
58+
59+
A new database will be created.
60+
Example:
61+
```
62+
WSQL > create database dbtest;
63+
dbtest
64+
PATH: ./
65+
------------SUCCESS-------------
66+
WSQL >
67+
```
68+
69+
#### `drop database <database name>`
70+
71+
Given database will be deleted.
72+
Example:
73+
```
74+
WSQL > drop database dbtest;
75+
------------SUCCESS-------------
76+
WSQL >
77+
```
78+
79+
#### `use database <database name>`
80+
81+
This will enter an existing database.
82+
Example:
83+
```
84+
WSQL > use db2;
85+
WSQL@db2 >
86+
```
87+
88+
#### `list tables`
89+
90+
This will list all tables in a database.
91+
Example:
92+
```
93+
WSQL@db2 > list tables;
94+
#==================================#
95+
| Table |
96+
+----------------------------------+
97+
| tb1 |
98+
#==================================#
99+
------------SUCCESS-------------
100+
WSQL@db2 >
101+
```
102+
103+
#### `detail table <table name>`
104+
105+
This will show the details of given table.
106+
Example:
107+
```
108+
WSQL@db2 > detail table tb1;
109+
110+
tb1
111+
--------------------------------------
112+
NAME TYPE LENGTH(Byte)
113+
--------------------------------------
114+
age INT 4
115+
name STRING 10
116+
--------------------------------------
117+
118+
------------SUCCESS-------------
119+
120+
```
121+
122+
#### `create table <table name> ...`
123+
124+
A new empty table will be created in database.
125+
Example:
126+
```
127+
WSQL@db2 > create table tbtest (id INT, height FLOAT, name STRING[12]);
128+
129+
------------------------------------------
130+
CREATING TABLE tbtest
131+
------------------------------------------
132+
./db2/tbtest.scm
133+
./db2/tbtest.id.data
134+
./db2/tbtest.id.index
135+
./db2/tbtest.height.data
136+
./db2/tbtest.height.index
137+
./db2/tbtest.name.data
138+
./db2/tbtest.name.index
139+
------------SUCCESS-------------
140+
WSQL@db2 >
141+
```
142+
143+
#### `drop table <table name>`
144+
145+
Given table will be deleted.
146+
Example:
147+
```
148+
WSQL@db2 > drop table tbtest;
149+
150+
------------------------------------------
151+
DROPING TABLE tbtest
152+
------------------------------------------
153+
------------SUCCESS-------------
154+
WSQL@db2 >
155+
156+
```
157+
158+
#### `rename table <table name> <table name>`
159+
160+
Example:
161+
```
162+
WSQL@db2 > list tables;
163+
#==================================#
164+
| Table |
165+
+----------------------------------+
166+
| tb1 |
167+
#==================================#
168+
------------SUCCESS-------------
169+
WSQL@db2 > rename table tb1 tbxxx;
170+
------------SUCCESS-------------
171+
WSQL@db2 > list tables;
172+
#==================================#
173+
| Table |
174+
+----------------------------------+
175+
| tbxxx |
176+
#==================================#
177+
------------SUCCESS-------------
178+
WSQL@db2 >
179+
```
180+
181+
#### `clear table <table name>`
182+
183+
#### `alter table <table name> rename column <old column name> <new column name>`
184+
185+
#### `alter table <table name> drop column <column name>`
186+
187+
#### `alter table <table name> add column (<column name> <column type>)`
188+
189+
### DDL
190+
191+
#### `update <table name> (<column name 1>,<column name 2>,...>):(<new value 1>, <new value 2>,...) where <where-condition>`
192+
193+
194+
#### `insert into <table name> (<column name 1>,<column name 2>,...):(<new value 1>,<new value 2>,...)`
195+
196+
#### ~~`insert into <table name> select ...`~~
197+
198+
#### `delete from <table name> where <where-condition>`
199+
200+
#### `select * from <table name>`
201+
#### `select * from <table name> where <where-condition>`
202+
#### `select <column name 1>,<column name 2>,... from <table name>`
203+
#### `select <column name 1>,<column name 2>,... from <table name> where <where-condition>`
204+
205+
206+
## Remarks
207+
- Lastest updated on 5th,March,2021

readme.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
# WSQL
22

3-
## Introduction
3+
## Introduction
44

55
WSQL is a complete single-user relational database management system.
66

7-
## Usage
7+
## Features
8+
9+
- Superior performance for storage
10+
- Superior performance for query
11+
12+
## Documentation
13+
14+
- [WSQL Internal Manual Documentation](doc/internal.md)
15+
- [WSQL User Toturial Documentation](doc/user.md)
16+
17+
## Try it
818

919
### Install
1020
```
@@ -14,4 +24,9 @@ sudo make clean && sudo make all
1424
### Run
1525
```
1626
./wsql
17-
```
27+
```
28+
29+
## Next version
30+
- Visualization of database / table / column with ML algorithm
31+
- **Brand new** query optimization strategy
32+
- Transactions and locking

src/rm.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class RM_FileHandle {
189189
RC GetPageHeader(PF_PageHandle &ph, RM_PageHdr &pHdr) const;
190190
RC SetPageHeader(PF_PageHandle &ph, RM_PageHdr &pHdr);
191191
// Given a RID, return the record
192-
RC GetRec (const RID &rid, RM_Record &rec) const;
192+
RC GetRec (RID rid, RM_Record &rec) const;
193193

194194
RC InsertRec (const void *pData, RID &rid); // Insert a new record
195195
RC DeleteRec (const RID &rid); // Delete a record
@@ -205,7 +205,7 @@ class RM_FileHandle {
205205
PageNum GetNumPages() const;
206206
SlotNum GetNumSlots() const;
207207
long long GetNumRecs() const;
208-
RC WriteRidList(FILE *&fp) const;
208+
RC WriteAllRids(const char *OutFile) const;
209209
RC WriteValue(FILE *&fp, RID rid) const;
210210
RC IsValid() const;
211211
void print(PageNum p, AttrType type);

src/rm_filehandle.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,16 @@ long long RM_FileHandle::GetNumRecs() const
202202

203203

204204
//
205-
// write RID of all records to given file
205+
// write RID of all records to 'OutFile'
206206
//
207-
RC RM_FileHandle::WriteRidList(FILE *&fp) const
207+
RC RM_FileHandle::WriteAllRids(const char *OutFile) const
208208
{
209209
RC rc = 0;
210210
auto numSlots = this->GetNumSlots();
211211
PF_PageHandle ph;
212212
RM_PageHdr pHdr(numSlots);
213213
PageNum p = (PageNum)-1;
214+
FILE *fpx = fopen(OutFile, "w");
214215
while (1)
215216
{
216217
rc = pfh->GetNextPage(p, ph);
@@ -227,12 +228,13 @@ RC RM_FileHandle::WriteRidList(FILE *&fp) const
227228
for (int s = 0; s < b.getSize(); s++)
228229
{
229230
if (b.test(s))
230-
fprintf(fp, "%d %d\n", p, s);
231+
fprintf(fpx, "%d %d\n", p, s);
231232
}
232233
}
233234
rc = pfh->UnpinPage(p);
234235
if (rc != 0) return rc;
235236
}
237+
fclose(fpx);
236238

237239
return rc;
238240
}
@@ -252,10 +254,10 @@ RC RM_FileHandle::WriteValue(FILE *&fp, RID rid) const
252254
fprintf(fp, "%s ", ptr);
253255
}break;
254256
case FLOAT:{
255-
fprintf(fp, "%f ", (float *)ptr);
257+
fprintf(fp, "%f ", *(float *)ptr);
256258
}break;
257259
case INT:{
258-
fprintf(fp, "%d ", (int *)ptr);
260+
fprintf(fp, "%d ", *(int *)ptr);
259261
}break;
260262
}
261263
return rc;
@@ -440,7 +442,7 @@ RC RM_FileHandle::SetPageHeader(PF_PageHandle &ph, RM_PageHdr &pHdr)
440442
// Out: rec
441443
// Ret: RM return code
442444
//
443-
RC RM_FileHandle::GetRec(const RID &rid, RM_Record &rec) const
445+
RC RM_FileHandle::GetRec(RID rid, RM_Record &rec) const
444446
{
445447
if(IsValid())
446448
return IsValid();

src/sm.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class SM_TableHandle {
7373

7474
RC CreateTable(string &tableName, vector<attrInfo> *attrList = NULL);
7575
RC DropTable(string &tableName);
76+
RC ClearTable(string &tableName);
7677
RC RenameTable(string &oldName, string &newName);
7778

7879
RC AddColumn(string &tableName, attrInfo &colinfo);
@@ -81,18 +82,22 @@ class SM_TableHandle {
8182

8283
RC InsertEntry(string &tableName, map<string,string> &entry, RID &_rid);
8384
RC DeleteEntry(string &tableName, vector<RID> &rids);
85+
RC DeleteEntry(string &tableName, string &RidFile);
8486
RC UpdateEntry(string &tableName, RID rid, map<string,string> &entry);
8587
RC SelectEntry(string &tableName, string &retFile, string &column, CompOp &op, void *&cmpKey);
8688
RC SelectEntry(string &tableName, string &retFile, string &column, CompOp &op, string &value);
8789
RC SelectEntry_from_file(string &tableName, string &retFile, string &column, CompOp &op, void *&cmpKey);
8890

8991
RC DetailTable(string &tableName);
90-
RC SelectTable(string &tableName, string &retFile);
9192
RC WriteValue(string &tableName, vector<string> &colList, string &outFile, string &RidFile);
93+
RC WriteValue(string &tableName, vector<string> &colList, string &outFile);
9294

9395
void GetScmFile(string &retFile, string &tableName) const;
9496
void GetRMFile(string &retFile, string &tableName, string &columnName) const;
9597
void GetIXFile(string &retFile, string &tableName, string &columnName) const;
98+
99+
bool isValidTable(string &tableName);
100+
bool isValidColumn(string &tableName, string &columnName);
96101
};
97102

98103
/* class SM_DatabaseHandle {

0 commit comments

Comments
 (0)