Skip to content

Commit

Permalink
test ql framework
Browse files Browse the repository at this point in the history
  • Loading branch information
xunkai55-ood committed Jan 9, 2015
1 parent 4bb416b commit 7e1b9b4
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 2 deletions.
9 changes: 7 additions & 2 deletions include/ql/query.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

namespace sqleast {

extern sm::DBManager dbManager;

namespace ql {
enum SupportedQueryType {
Q_CREATE_DB,
Expand All @@ -18,15 +20,18 @@ namespace sqleast {

struct StructuredQuery {
SupportedQueryType type;
virtual void execute();
};

struct SingleStringQuery: public StructuredQuery {
char dbName[MAX_NAME_LEN + 1];
char name[MAX_NAME_LEN + 1];
void execute();
};

struct CreateTableQuery: public CreateTableQuery {
struct CreateTableQuery: public StructuredQuery {
char dbName[MAX_NAME_LEN + 1];
AttrInfo attrs[MAX_ATTR_NUM];
void execute();
};

}
Expand Down
5 changes: 5 additions & 0 deletions include/sm/dbmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ namespace sqleast {
void createIndex(const char *relName, const char *attrName);
void dropIndex(const char *relName, const char *attrName);

void showTables();
void descTable(const char *relName);

void getCol(char *data, int offset, int size, AttrType type, void *target);

private:
rm::FileHandle relCatalog_, attrCatalog_;
};
Expand Down
Empty file removed src/ql/executor.cpp
Empty file.
26 changes: 26 additions & 0 deletions src/ql/query.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "ql/query.h"
#include "sm/systemmanager.h"
#include "sm/dbmanager.h"

namespace sqleast {

namespace ql {

void SingleStringQuery::execute() {
if (type == Q_CREATE_DB) {
sm::SystemManager::createDB(name);
} else if (type == Q_DROP_DB) {
sm::SystemManager::destroyDB(name);
} else if (type == Q_USE_DB) {
sm::SystemManager::useDB(name);
} else if (type == Q_SHOW_TABLES) {
dbManager.showTables();
} else if (type == Q_DESC_TABLE) {
dbManager.descTable(name);
} else if (type == Q_DROP_TABLE) {
dbManager.dropTable(name);
}
}

}
}
31 changes: 31 additions & 0 deletions src/sm/dbmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,36 @@ namespace sqleast {
rids.clear();
}

void DBManager::showTables() {
char name[MAX_NAME_LENGTH];
rm::FileScan relScan(relCatalog_, STRING, MAX_NAME_LENGTH, 0, 0, 0, NO_OP, name);
while (true) {
Record &r = relScan.next();
if (r.rid.pageNum <= 0) break;
getCol(r.getData(), 0, MAX_NAME_LENGTH, STRING, name);
std::cout << name << std::endl;
}
}

void DBManager::descTable(const char *relName) {
char name[MAX_NAME_LENGTH];
strcpy(name, relName);
rm::FileScan attrScan(attrCatalog_, STRING, MAX_NAME_LENGTH, 0, 0, 0, EQ_OP, name);
while (true) {
Record &r = attrScan.next();
if (r.rid.pageNum <= 0) break;
DataAttrInfo *dai = (DataAttrInfo*) r.getData();
std::cout << dai->attrName << " ";
if (dai->attrType == INT) {
std::cout << "int ";
} else {
std::cout << "vchar(" << dai->attrLength << ") ";
}
if (dai->nullable == 0) {
std::cout << "NOT NULL ";
}
}
}

}
}

0 comments on commit 7e1b9b4

Please sign in to comment.