Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
dynmi committed Mar 5, 2021
1 parent 8a8a2d2 commit 3f6f862
Show file tree
Hide file tree
Showing 10 changed files with 997 additions and 424 deletions.
18 changes: 18 additions & 0 deletions doc/internal.md

Large diffs are not rendered by default.

Binary file added doc/structure.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
207 changes: 207 additions & 0 deletions doc/user.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
# WSQL Toturial

## Supported Comparision Operations

<table>
<tr>
<th>= </th>
<th> != </th>
<th> < </th>
<th> > </th>
<th> <= </th>
<th> >= </th>
</tr >
</table>

## Supported Data Type

<table>
<tr>
<th> TYPE </th>
<th> LENGTH(Byte) </th>
</tr >
<tr>
<th> int整型 </th>
<th> 4 </th>
</tr >
<tr>
<th> string字符串型 </th>
<th> 1~MAXLEN </th>
</tr >
<tr>
<th> float浮点型 </th>
<th> 4 </th>
</tr >
</table>

## Installation (Only support Linux)

```
git clone [email protected]:Dynmi/WSQL.git
cd WSQL
sudo make clean && sudo make all
```

## Usage

Use ```./wsql``` to start WSQL.

Each sentence should be ended with ";".

### DML

#### `list databases`

This will list all databases.

#### `create database <database name>`

A new database will be created.
Example:
```
WSQL > create database dbtest;
dbtest
PATH: ./
------------SUCCESS-------------
WSQL >
```

#### `drop database <database name>`

Given database will be deleted.
Example:
```
WSQL > drop database dbtest;
------------SUCCESS-------------
WSQL >
```

#### `use database <database name>`

This will enter an existing database.
Example:
```
WSQL > use db2;
WSQL@db2 >
```

#### `list tables`

This will list all tables in a database.
Example:
```
WSQL@db2 > list tables;
#==================================#
| Table |
+----------------------------------+
| tb1 |
#==================================#
------------SUCCESS-------------
WSQL@db2 >
```

#### `detail table <table name>`

This will show the details of given table.
Example:
```
WSQL@db2 > detail table tb1;
tb1
--------------------------------------
NAME TYPE LENGTH(Byte)
--------------------------------------
age INT 4
name STRING 10
--------------------------------------
------------SUCCESS-------------
```

#### `create table <table name> ...`

A new empty table will be created in database.
Example:
```
WSQL@db2 > create table tbtest (id INT, height FLOAT, name STRING[12]);
------------------------------------------
CREATING TABLE tbtest
------------------------------------------
./db2/tbtest.scm
./db2/tbtest.id.data
./db2/tbtest.id.index
./db2/tbtest.height.data
./db2/tbtest.height.index
./db2/tbtest.name.data
./db2/tbtest.name.index
------------SUCCESS-------------
WSQL@db2 >
```

#### `drop table <table name>`

Given table will be deleted.
Example:
```
WSQL@db2 > drop table tbtest;
------------------------------------------
DROPING TABLE tbtest
------------------------------------------
------------SUCCESS-------------
WSQL@db2 >
```

#### `rename table <table name> <table name>`

Example:
```
WSQL@db2 > list tables;
#==================================#
| Table |
+----------------------------------+
| tb1 |
#==================================#
------------SUCCESS-------------
WSQL@db2 > rename table tb1 tbxxx;
------------SUCCESS-------------
WSQL@db2 > list tables;
#==================================#
| Table |
+----------------------------------+
| tbxxx |
#==================================#
------------SUCCESS-------------
WSQL@db2 >
```

#### `clear table <table name>`

#### `alter table <table name> rename column <old column name> <new column name>`

#### `alter table <table name> drop column <column name>`

#### `alter table <table name> add column (<column name> <column type>)`

### DDL

#### `update <table name> (<column name 1>,<column name 2>,...>):(<new value 1>, <new value 2>,...) where <where-condition>`


#### `insert into <table name> (<column name 1>,<column name 2>,...):(<new value 1>,<new value 2>,...)`

#### ~~`insert into <table name> select ...`~~

#### `delete from <table name> where <where-condition>`

#### `select * from <table name>`
#### `select * from <table name> where <where-condition>`
#### `select <column name 1>,<column name 2>,... from <table name>`
#### `select <column name 1>,<column name 2>,... from <table name> where <where-condition>`


## Remarks
- Lastest updated on 5th,March,2021
21 changes: 18 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
# WSQL

## Introduction
## Introduction

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

## Usage
## Features

- Superior performance for storage
- Superior performance for query

## Documentation

- [WSQL Internal Manual Documentation](doc/internal.md)
- [WSQL User Toturial Documentation](doc/user.md)

## Try it

### Install
```
Expand All @@ -14,4 +24,9 @@ sudo make clean && sudo make all
### Run
```
./wsql
```
```

## Next version
- Visualization of database / table / column with ML algorithm
- **Brand new** query optimization strategy
- Transactions and locking
4 changes: 2 additions & 2 deletions src/rm.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class RM_FileHandle {
RC GetPageHeader(PF_PageHandle &ph, RM_PageHdr &pHdr) const;
RC SetPageHeader(PF_PageHandle &ph, RM_PageHdr &pHdr);
// Given a RID, return the record
RC GetRec (const RID &rid, RM_Record &rec) const;
RC GetRec (RID rid, RM_Record &rec) const;

RC InsertRec (const void *pData, RID &rid); // Insert a new record
RC DeleteRec (const RID &rid); // Delete a record
Expand All @@ -205,7 +205,7 @@ class RM_FileHandle {
PageNum GetNumPages() const;
SlotNum GetNumSlots() const;
long long GetNumRecs() const;
RC WriteRidList(FILE *&fp) const;
RC WriteAllRids(const char *OutFile) const;
RC WriteValue(FILE *&fp, RID rid) const;
RC IsValid() const;
void print(PageNum p, AttrType type);
Expand Down
14 changes: 8 additions & 6 deletions src/rm_filehandle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,16 @@ long long RM_FileHandle::GetNumRecs() const


//
// write RID of all records to given file
// write RID of all records to 'OutFile'
//
RC RM_FileHandle::WriteRidList(FILE *&fp) const
RC RM_FileHandle::WriteAllRids(const char *OutFile) const
{
RC rc = 0;
auto numSlots = this->GetNumSlots();
PF_PageHandle ph;
RM_PageHdr pHdr(numSlots);
PageNum p = (PageNum)-1;
FILE *fpx = fopen(OutFile, "w");
while (1)
{
rc = pfh->GetNextPage(p, ph);
Expand All @@ -227,12 +228,13 @@ RC RM_FileHandle::WriteRidList(FILE *&fp) const
for (int s = 0; s < b.getSize(); s++)
{
if (b.test(s))
fprintf(fp, "%d %d\n", p, s);
fprintf(fpx, "%d %d\n", p, s);
}
}
rc = pfh->UnpinPage(p);
if (rc != 0) return rc;
}
fclose(fpx);

return rc;
}
Expand All @@ -252,10 +254,10 @@ RC RM_FileHandle::WriteValue(FILE *&fp, RID rid) const
fprintf(fp, "%s ", ptr);
}break;
case FLOAT:{
fprintf(fp, "%f ", (float *)ptr);
fprintf(fp, "%f ", *(float *)ptr);
}break;
case INT:{
fprintf(fp, "%d ", (int *)ptr);
fprintf(fp, "%d ", *(int *)ptr);
}break;
}
return rc;
Expand Down Expand Up @@ -440,7 +442,7 @@ RC RM_FileHandle::SetPageHeader(PF_PageHandle &ph, RM_PageHdr &pHdr)
// Out: rec
// Ret: RM return code
//
RC RM_FileHandle::GetRec(const RID &rid, RM_Record &rec) const
RC RM_FileHandle::GetRec(RID rid, RM_Record &rec) const
{
if(IsValid())
return IsValid();
Expand Down
7 changes: 6 additions & 1 deletion src/sm.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class SM_TableHandle {

RC CreateTable(string &tableName, vector<attrInfo> *attrList = NULL);
RC DropTable(string &tableName);
RC ClearTable(string &tableName);
RC RenameTable(string &oldName, string &newName);

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

RC InsertEntry(string &tableName, map<string,string> &entry, RID &_rid);
RC DeleteEntry(string &tableName, vector<RID> &rids);
RC DeleteEntry(string &tableName, string &RidFile);
RC UpdateEntry(string &tableName, RID rid, map<string,string> &entry);
RC SelectEntry(string &tableName, string &retFile, string &column, CompOp &op, void *&cmpKey);
RC SelectEntry(string &tableName, string &retFile, string &column, CompOp &op, string &value);
RC SelectEntry_from_file(string &tableName, string &retFile, string &column, CompOp &op, void *&cmpKey);

RC DetailTable(string &tableName);
RC SelectTable(string &tableName, string &retFile);
RC WriteValue(string &tableName, vector<string> &colList, string &outFile, string &RidFile);
RC WriteValue(string &tableName, vector<string> &colList, string &outFile);

void GetScmFile(string &retFile, string &tableName) const;
void GetRMFile(string &retFile, string &tableName, string &columnName) const;
void GetIXFile(string &retFile, string &tableName, string &columnName) const;

bool isValidTable(string &tableName);
bool isValidColumn(string &tableName, string &columnName);
};

/* class SM_DatabaseHandle {
Expand Down
Loading

0 comments on commit 3f6f862

Please sign in to comment.