├── README ├── Debug.h ├── File.cpp ├── head.h ├── main.cpp ├── Creat.cpp ├── Debug.cpp ├── Delete.cpp ├── LiteSQL.h ├── Select.cpp ├── LinkList.cpp ├── Memory.cpp └── LiteSql.cpp /README: -------------------------------------------------------------------------------- 1 | 简单数据库模拟类 -------------------------------------------------------------------------------- /Debug.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loveyu/LiteSQL/master/Debug.h -------------------------------------------------------------------------------- /File.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loveyu/LiteSQL/master/File.cpp -------------------------------------------------------------------------------- /head.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loveyu/LiteSQL/master/head.h -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loveyu/LiteSQL/master/main.cpp -------------------------------------------------------------------------------- /Creat.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loveyu/LiteSQL/master/Creat.cpp -------------------------------------------------------------------------------- /Debug.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loveyu/LiteSQL/master/Debug.cpp -------------------------------------------------------------------------------- /Delete.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loveyu/LiteSQL/master/Delete.cpp -------------------------------------------------------------------------------- /LiteSQL.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loveyu/LiteSQL/master/LiteSQL.h -------------------------------------------------------------------------------- /Select.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loveyu/LiteSQL/master/Select.cpp -------------------------------------------------------------------------------- /LinkList.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loveyu/LiteSQL/master/LinkList.cpp -------------------------------------------------------------------------------- /Memory.cpp: -------------------------------------------------------------------------------- 1 | #include"head.h" 2 | 3 | bool LiteSQL::MemoryCopy(void *dst, const void *src, int count) { 4 | if(dst == NULL || src == NULL || dst == src)return false; 5 | 6 | void *dst2 = dst; 7 | count /= sizeof(char); 8 | 9 | while(count--) { 10 | *(char *)dst2 = *(char *)src; 11 | dst2 = (char *)dst2 + 1; 12 | src = (char *)src + 1; 13 | } 14 | 15 | return true; 16 | } 17 | 18 | void *LiteSQL::MemoryAlloc(SQLList *s) { 19 | return malloc(ListSizeCount(s)); 20 | } 21 | 22 | void *LiteSQL::MemoryCount(SQLList *s, DataNode *data, const char *name) { 23 | int size = 0; 24 | 25 | for(int i = 0; i < s->length; i++) { 26 | if(!strcmp(s->name[i], name))break; 27 | 28 | size += s->size[i]; 29 | } 30 | 31 | return data->data + size; 32 | } 33 | 34 | bool LiteSQL::FreeList(SQLList *p) { 35 | if(!p)return false; 36 | 37 | for(int i = 0; i < p->length; i++) { 38 | free(*(p->name + i)); 39 | free(*(p->type + i)); 40 | } 41 | 42 | free(p->size); 43 | free(p->name); 44 | free(p->type); 45 | free(p); 46 | return true; 47 | } 48 | bool LiteSQL::FreeDataList(DataListNode *p) { 49 | if(!p)return false; 50 | 51 | if(!FreeList(p->DataName))return false; 52 | 53 | DataNode *p2, *p3; 54 | p2 = p->List; 55 | 56 | while(p2) { 57 | p3 = p2->next; 58 | 59 | if(!FreeData(p2))return false; 60 | 61 | p2 = p3; 62 | } 63 | 64 | free(p); 65 | return true; 66 | } 67 | bool LiteSQL::FreeData(DataNode *p) { 68 | if(!p)return false; 69 | 70 | free(p->data); 71 | free(p); 72 | return true; 73 | } -------------------------------------------------------------------------------- /LiteSql.cpp: -------------------------------------------------------------------------------- 1 | #include"head.h" 2 | 3 | LiteSQL::LiteSQL() { 4 | DataList = (DataListNode *)malloc(sizeof(DataListNode)); 5 | DataList->DataName = NULL; 6 | DataList->List = NULL; 7 | DataList->next = NULL; 8 | ReadingFile = false; 9 | SelectTableStatus = DataList; 10 | } 11 | int LiteSQL::CheckType(char *type) { 12 | if(!strcmp(type, "int"))return sizeof(int); 13 | 14 | if(!strcmp(type, "long"))return sizeof(long); 15 | 16 | if(!strcmp(type, "double"))return sizeof(double); 17 | 18 | if(!strcmp(type, "folat"))return sizeof(float); 19 | 20 | if(!strcmp(type, "char"))return sizeof(char); 21 | 22 | return 0; 23 | } 24 | int LiteSQL::GetNameSize(SQLList *s, char *name) { 25 | for(int i = 0; i < s->length; i++) { 26 | if(!strcmp(s->name[i], name))return s->size[i]; 27 | } 28 | 29 | return 0; 30 | } 31 | void *LiteSQL::GetNameType(SQLList *s, char *name) { 32 | for(int i = 0; i < s->length; i++) { 33 | if(!strcmp(s->name[i], name))return s->type[i]; 34 | } 35 | 36 | return NULL; 37 | } 38 | int LiteSQL::ListSizeCount(SQLList *s) { 39 | int size = 0; 40 | 41 | for(int i = 0; i < s->length; i++) 42 | size += s->size[i]; 43 | 44 | return size; 45 | } 46 | DATATYPE LiteSQL::GetSelectDataType(const char *name) { 47 | s = SelectStatus.Datalist->DataName; 48 | 49 | for(int i = 0; i < s->length; i++) { 50 | if(!strcmp(s->name[i], name)) { 51 | if(!strcmp(s->type[i], "int"))return INT; 52 | 53 | if(!strcmp(s->type[i], "long"))return LONG; 54 | 55 | if(!strcmp(s->type[i], "double"))return DOUBLE; 56 | 57 | if(!strcmp(s->type[i], "folat"))return FLOAT; 58 | 59 | if(!strcmp(s->type[i], "char"))return CHAR; 60 | } 61 | } 62 | 63 | return OTHER; 64 | } --------------------------------------------------------------------------------