├── .idea
├── .name
├── Pybase.iml
├── encodings.xml
├── misc.xml
├── modules.xml
├── vcs.xml
└── workspace.xml
├── bind
├── buffer
├── __init__.py
├── __init__.pyc
├── __pycache__
│ ├── __init__.cpython-35.pyc
│ ├── bufmgr.cpython-34.pyc
│ └── bufmgr.cpython-35.pyc
├── bufmgr.py
└── bufmgr.pyc
├── catalog
├── __init__.py
├── __init__.pyc
├── __pycache__
│ ├── __init__.cpython-35.pyc
│ ├── core.cpython-34.pyc
│ └── core.cpython-35.pyc
├── core.py
└── core.pyc
├── ctlstudents2.dat
├── ctltable_name.dat
├── data
├── pagemgr.dat
├── students21page.dat
├── students22page.dat
└── students23page.dat
├── main.py
├── query
├── __init__.py
├── __init__.pyc
├── __pycache__
│ ├── __init__.cpython-35.pyc
│ ├── evaluator.cpython-34.pyc
│ └── evaluator.cpython-35.pyc
├── commands
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── __pycache__
│ │ ├── __init__.cpython-35.pyc
│ │ ├── insert.cpython-34.pyc
│ │ ├── insert.cpython-35.pyc
│ │ ├── select.cpython-34.pyc
│ │ ├── select.cpython-35.pyc
│ │ └── update.cpython-35.pyc
│ ├── delete.py
│ ├── insert.py
│ ├── insert.pyc
│ ├── select.py
│ ├── select.pyc
│ ├── update.py
│ └── update.pyc
├── evaluator.py
├── evaluator.pyc
└── parser
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── __pycache__
│ ├── __init__.cpython-35.pyc
│ ├── sqlparse.cpython-35.pyc
│ └── tokens.cpython-35.pyc
│ ├── sqlparse.py
│ ├── sqlparse.pyc
│ ├── tokens.py
│ └── tokens.pyc
└── storage
├── __init__.py
├── __init__.pyc
├── __pycache__
├── __init__.cpython-35.pyc
├── io.cpython-34.pyc
├── io.cpython-35.pyc
├── pageManager.cpython-34.pyc
├── pageManager.cpython-35.pyc
├── tablemgr.cpython-34.pyc
└── tablemgr.cpython-35.pyc
├── io.py
├── io.pyc
├── pageManager.py
├── pageManager.pyc
├── tablemgr.py
└── tablemgr.pyc
/.idea/.name:
--------------------------------------------------------------------------------
1 | Pybase
--------------------------------------------------------------------------------
/.idea/Pybase.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
140 |
141 |
142 |
143 |
144 |
145 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
420 |
421 |
422 |
423 |
424 |
425 |
426 |
427 |
428 |
429 |
430 |
431 |
432 |
433 |
434 |
435 |
436 |
437 |
438 |
439 |
440 |
441 |
442 |
443 |
444 |
445 |
446 |
447 |
448 |
449 |
450 |
451 |
452 |
453 |
454 |
455 |
456 |
457 |
458 |
459 |
460 |
461 |
462 |
463 |
464 |
465 |
466 |
467 |
468 |
469 |
470 |
471 |
472 |
473 |
474 |
475 |
476 |
477 |
478 |
479 |
480 |
481 |
482 |
483 |
484 |
485 |
486 |
487 |
488 |
489 |
490 |
491 |
492 |
493 |
494 |
495 |
496 |
497 |
498 |
499 |
500 |
501 |
502 |
503 |
504 |
505 |
506 |
507 |
508 | 1448341095179
509 |
510 | 1448341095179
511 |
512 |
513 | 1449302195337
514 |
515 |
516 | 1449302195337
517 |
518 |
519 | 1449303880347
520 |
521 |
522 | 1449303880347
523 |
524 |
525 | 1449305435903
526 |
527 |
528 | 1449305435903
529 |
530 |
531 | 1449461894396
532 |
533 |
534 | 1449461894396
535 |
536 |
537 | 1449462105931
538 |
539 |
540 | 1449462105931
541 |
542 |
543 | 1449906422314
544 |
545 |
546 | 1449906422314
547 |
548 |
549 | 1449998540529
550 |
551 |
552 | 1449998540529
553 |
554 |
555 | 1450001374210
556 |
557 |
558 | 1450001374210
559 |
560 |
561 | 1450215584525
562 |
563 |
564 | 1450215584525
565 |
566 |
567 | 1450215888187
568 |
569 |
570 | 1450215888187
571 |
572 |
573 | 1450217774602
574 |
575 |
576 | 1450217774602
577 |
578 |
579 | 1450329480640
580 |
581 |
582 | 1450329480640
583 |
584 |
585 | 1450515822671
586 |
587 |
588 | 1450515822671
589 |
590 |
591 | 1450516686041
592 |
593 |
594 | 1450516686041
595 |
596 |
597 | 1450779992814
598 |
599 |
600 | 1450779992814
601 |
602 |
603 | 1450861999169
604 |
605 |
606 | 1450861999169
607 |
608 |
609 | 1450862079246
610 |
611 |
612 | 1450862079246
613 |
614 |
615 | 1451364293837
616 |
617 |
618 | 1451364293837
619 |
620 |
621 | 1451365053240
622 |
623 |
624 | 1451365053240
625 |
626 |
627 | 1451732449489
628 |
629 |
630 | 1451732449489
631 |
632 |
633 | 1451734254591
634 |
635 |
636 | 1451734254591
637 |
638 |
639 | 1451734306434
640 |
641 |
642 | 1451734306434
643 |
644 |
645 | 1451734987061
646 |
647 |
648 | 1451734987061
649 |
650 |
651 | 1453281252894
652 |
653 |
654 | 1453281252894
655 |
656 |
657 | 1453503113115
658 |
659 |
660 | 1453503113115
661 |
662 |
663 | 1453842344333
664 |
665 |
666 | 1453842344333
667 |
668 |
669 | 1453843247451
670 |
671 |
672 | 1453843247451
673 |
674 |
675 | 1453925892426
676 |
677 |
678 | 1453925892426
679 |
680 |
681 | 1453925939496
682 |
683 |
684 | 1453925939496
685 |
686 |
687 | 1454448237778
688 |
689 |
690 | 1454448237778
691 |
692 |
693 | 1454448510902
694 |
695 |
696 | 1454448510902
697 |
698 |
699 | 1454448770503
700 |
701 |
702 | 1454448770503
703 |
704 |
705 | 1454454829566
706 |
707 |
708 | 1454454829566
709 |
710 |
711 | 1454479905613
712 |
713 |
714 | 1454479905613
715 |
716 |
717 | 1454480119318
718 |
719 |
720 | 1454480119318
721 |
722 |
723 | 1454529228639
724 |
725 |
726 | 1454529228639
727 |
728 |
729 | 1454753366362
730 |
731 |
732 | 1454753366362
733 |
734 |
735 | 1454832752102
736 |
737 |
738 | 1454832752102
739 |
740 |
741 | 1454832833434
742 |
743 |
744 | 1454832833434
745 |
746 |
747 | 1454833595884
748 |
749 |
750 | 1454833595884
751 |
752 |
753 | 1455245807877
754 |
755 |
756 | 1455245807877
757 |
758 |
759 | 1455332411399
760 |
761 |
762 | 1455332411399
763 |
764 |
765 | 1455332678634
766 |
767 |
768 | 1455332678634
769 |
770 |
771 | 1455419602082
772 |
773 |
774 | 1455419602082
775 |
776 |
777 | 1456544163039
778 |
779 |
780 | 1456544163040
781 |
782 |
783 | 1457753778346
784 |
785 |
786 | 1457753778346
787 |
788 |
789 | 1457063147048
790 |
791 |
792 | 1457063147049
793 |
794 |
795 | 1457063799701
796 |
797 |
798 | 1457063799702
799 |
800 |
801 | 1457755012756
802 |
803 |
804 | 1457755012756
805 |
806 |
807 |
808 |
809 |
810 |
811 |
812 |
813 |
814 |
815 |
816 |
817 |
818 |
819 |
820 |
821 |
822 |
823 |
824 |
825 |
826 |
827 |
828 |
829 |
830 |
831 |
832 |
833 |
834 |
835 |
836 |
837 |
838 |
839 |
840 |
841 |
842 |
843 |
844 |
845 |
846 |
847 |
848 |
849 |
850 |
851 |
852 |
853 |
854 |
855 |
856 |
857 |
858 |
859 |
860 |
861 |
862 |
863 |
864 |
865 |
866 |
867 |
868 |
869 |
870 |
871 |
872 |
873 |
874 |
875 |
876 |
877 |
878 |
879 |
880 |
881 |
882 |
883 |
884 |
885 |
886 |
887 |
888 |
889 |
890 |
891 |
892 |
893 |
894 |
895 |
896 |
897 |
898 |
899 |
900 |
901 |
902 |
903 |
904 |
905 |
906 |
907 |
908 |
909 |
910 |
911 |
912 |
913 |
914 |
915 |
916 |
917 |
918 |
919 |
920 |
921 |
922 |
923 |
924 |
925 |
926 |
927 |
928 |
929 |
930 |
931 |
932 |
933 |
934 |
935 |
936 |
937 |
938 |
939 |
940 |
941 |
942 |
943 |
944 |
945 |
946 |
947 |
948 |
949 |
950 |
951 |
952 |
953 |
954 |
955 |
956 |
957 |
958 |
959 |
960 |
961 |
962 |
963 |
964 |
965 |
966 |
967 |
968 |
969 |
970 |
971 |
972 |
973 |
974 |
975 |
976 |
977 |
978 |
979 |
980 |
981 |
982 |
983 |
984 |
985 |
986 |
987 |
988 |
989 |
990 |
991 |
992 |
993 |
994 |
995 |
996 |
997 |
998 |
999 |
1000 |
1001 |
1002 |
1003 |
1004 |
1005 |
1006 |
1007 |
1008 |
1009 |
1010 |
1011 |
1012 |
1013 |
1014 |
1015 |
1016 |
1017 |
1018 |
1019 |
1020 |
1021 |
1022 |
1023 |
1024 |
1025 |
1026 |
1027 |
1028 |
1029 |
1030 |
1031 |
1032 |
1033 |
1034 |
1035 |
1036 |
1037 |
1038 |
1039 |
1040 |
1041 |
1042 |
1043 |
1044 |
1045 |
1046 |
1047 |
1048 |
1049 |
1050 |
1051 |
1052 |
1053 |
1054 |
1055 |
1056 |
1057 |
1058 |
1059 |
1060 |
1061 |
1062 |
1063 |
1064 |
1065 |
1066 |
1067 |
1068 |
1069 |
1070 |
1071 |
1072 |
1073 |
1074 |
1075 |
1076 |
1077 |
1078 |
1079 |
1080 |
1081 |
1082 |
1083 |
1084 |
1085 |
1086 |
1087 |
1088 |
1089 |
1090 |
1091 |
1092 |
1093 |
1094 |
1095 |
1096 |
1097 |
1098 |
1099 |
1100 |
1101 |
1102 |
1103 |
1104 |
1105 |
1106 |
1107 |
1108 |
1109 |
1110 |
1111 |
1112 |
1113 |
1114 |
1115 |
1116 |
1117 |
1118 |
1119 |
1120 |
1121 |
1122 |
1123 |
1124 |
1125 |
1126 |
1127 |
1128 |
1129 |
1130 |
1131 |
1132 |
1133 |
1134 |
1135 |
1136 |
1137 |
1138 |
1139 |
1140 |
1141 |
1142 |
1143 |
1144 |
1145 |
1146 |
1147 |
1148 |
1149 |
1150 |
1151 |
1152 |
1153 |
1154 |
1155 |
1156 |
1157 |
1158 |
1159 |
1160 |
1161 |
1162 |
1163 |
1164 |
1165 |
1166 |
1167 |
1168 |
1169 |
1170 |
1171 |
1172 |
1173 |
1174 |
1175 |
1176 |
1177 |
1178 |
1179 |
1180 |
1181 |
1182 |
1183 |
1184 |
1185 |
1186 |
1187 |
1188 |
1189 |
1190 |
1191 |
1192 |
1193 |
1194 |
1195 |
1196 |
1197 |
1198 |
1199 |
1200 |
1201 |
1202 |
1203 |
1204 |
1205 |
1206 |
1207 |
1208 |
1209 |
1210 |
1211 |
1212 |
1213 |
1214 |
1215 |
1216 |
1217 |
1218 |
1219 |
1220 |
1221 |
1222 |
1223 |
1224 |
1225 |
1226 |
1227 |
1228 |
1229 |
1230 |
1231 |
1232 |
1233 |
1234 |
1235 |
1236 |
1237 |
1238 |
1239 |
1240 |
1241 |
1242 |
1243 |
1244 |
1245 |
1246 |
1247 |
1248 |
1249 |
1250 |
1251 |
1252 |
1253 |
1254 |
1255 |
1256 |
1257 |
1258 |
1259 |
1260 |
1261 |
1262 |
1263 |
1264 |
1265 |
1266 |
1267 |
1268 |
1269 |
1270 |
1271 |
1272 |
1273 |
1274 |
1275 |
1276 |
1277 |
1278 |
1279 |
1280 |
1281 |
1282 |
1283 |
1284 |
1285 |
1286 |
1287 |
1288 |
1289 |
1290 |
1291 |
1292 |
1293 |
1294 |
1295 |
1296 |
1297 |
1298 |
1299 |
1300 |
1301 |
1302 |
1303 |
--------------------------------------------------------------------------------
/bind:
--------------------------------------------------------------------------------
1 | 0000:00:01.0
2 |
--------------------------------------------------------------------------------
/buffer/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/buffer/__init__.py
--------------------------------------------------------------------------------
/buffer/__init__.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/buffer/__init__.pyc
--------------------------------------------------------------------------------
/buffer/__pycache__/__init__.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/buffer/__pycache__/__init__.cpython-35.pyc
--------------------------------------------------------------------------------
/buffer/__pycache__/bufmgr.cpython-34.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/buffer/__pycache__/bufmgr.cpython-34.pyc
--------------------------------------------------------------------------------
/buffer/__pycache__/bufmgr.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/buffer/__pycache__/bufmgr.cpython-35.pyc
--------------------------------------------------------------------------------
/buffer/bufmgr.py:
--------------------------------------------------------------------------------
1 | __author__ = 'Bernardo'
2 |
3 | from catalog.core import catalogCore
4 | from storage.io import general
5 | from storage.tablemgr import manager
6 | import calendar
7 | import time
8 |
9 | __MAX_SIZE__ = 3
10 |
11 | class buffer:
12 | def __init__(self):
13 | self.pid = None
14 | self.page = None
15 | self.rids = None
16 | self.timestamp = None
17 | self.pinCount = 0
18 | self.dirty = False
19 |
20 | def forcePage(self):
21 | if self.pid is None or self.dirty is False:
22 | return
23 | ios = general()
24 |
25 | ios.writePage(self.rids, self.page, self.pid)
26 |
27 |
28 |
29 |
30 | class buffer_pool:
31 | pool = []
32 | def __init__(self):
33 | if len(buffer_pool.pool) == 0:
34 | for x in range(0, __MAX_SIZE__):
35 | self.addToPool(None)
36 |
37 |
38 | def findPage(self, pid):
39 | pos = -1
40 | for x in range(len(buffer_pool.pool)):
41 | if buffer_pool.pool[x].pid == pid:
42 | pos = x
43 | break
44 | return pos
45 |
46 | def addToPool(self, pid):
47 | ios = general()
48 | newb = buffer()
49 | newb.pid = pid
50 | newb.timestamp = calendar.timegm(time.gmtime())
51 | if pid is not None:
52 | newb.page = ios.readPage(pid)
53 | buffer_pool.pool.append(newb)
54 |
55 | def findVictimPage(self):
56 | victim = 0
57 | for x in range(len(buffer_pool.pool)):
58 | if buffer_pool.pool[x].timestamp < buffer_pool.pool[victim].timestamp:
59 | victim = x
60 | return victim
61 |
62 | def replacePage(self, pid):
63 | ios = general()
64 | newb = buffer()
65 | newb.pid = pid
66 |
67 | page = ios.readValues(pid)
68 | print(page[0])
69 |
70 | newb.page = page[0]#.split(chr(0))[0].split("$")
71 | newb.rids = page[1]
72 | victim = self.findVictimPage()
73 | buffer_pool.pool[victim].forcePage() #Forces all data to disk before replacing
74 | #time.sleep(1)
75 | newb.timestamp = time.time()
76 |
77 | print("Replacing Page: " + str(buffer_pool.pool[victim].pid) + " -> " + str(newb.pid) + " on slot " + str(victim))
78 | buffer_pool.pool[victim] = newb
79 | print(buffer_pool.pool[victim].rids)
80 | print(buffer_pool.pool[victim].page)
81 | return victim
82 |
83 | def forceBuffer(self):
84 | for x in range(len(buffer_pool.pool)):
85 | buffer_pool.pool[x].forcePage()
86 |
87 |
--------------------------------------------------------------------------------
/buffer/bufmgr.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/buffer/bufmgr.pyc
--------------------------------------------------------------------------------
/catalog/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/catalog/__init__.py
--------------------------------------------------------------------------------
/catalog/__init__.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/catalog/__init__.pyc
--------------------------------------------------------------------------------
/catalog/__pycache__/__init__.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/catalog/__pycache__/__init__.cpython-35.pyc
--------------------------------------------------------------------------------
/catalog/__pycache__/core.cpython-34.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/catalog/__pycache__/core.cpython-34.pyc
--------------------------------------------------------------------------------
/catalog/__pycache__/core.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/catalog/__pycache__/core.cpython-35.pyc
--------------------------------------------------------------------------------
/catalog/core.py:
--------------------------------------------------------------------------------
1 | __author__ = 'Bernardo'
2 |
3 | __CATALOG_FOLDER__ = "data/"
4 | __CATALOG_PREFIX__ = "ctl"
5 |
6 | import pickle
7 |
8 | class catalogCore:
9 | def __init__(self):
10 | self.catalog = []
11 | self.tableName = "tst"
12 |
13 | def insertAttr(self, attr, type):
14 | self.catalog.append([attr, type])
15 |
16 | def newCatalog(self, t_name):
17 | self.tableName = t_name
18 | self.catalog = []
19 |
20 | def commitCatalog(self):
21 | pickle.dump(self.catalog, open(__CATALOG_PREFIX__ + self.tableName + ".dat", 'wb'))
22 |
23 | def loadCatalog(self, table):
24 | self.tableName = table
25 | self.catalog = pickle.load(open(__CATALOG_PREFIX__ + self.tableName + ".dat", 'rb'))
26 |
27 | def printCtlg(self):
28 | print(self.catalog)
29 |
--------------------------------------------------------------------------------
/catalog/core.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/catalog/core.pyc
--------------------------------------------------------------------------------
/ctlstudents2.dat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/ctlstudents2.dat
--------------------------------------------------------------------------------
/ctltable_name.dat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/ctltable_name.dat
--------------------------------------------------------------------------------
/data/pagemgr.dat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/data/pagemgr.dat
--------------------------------------------------------------------------------
/data/students21page.dat:
--------------------------------------------------------------------------------
1 | 26$terceiro2221seesss 26$terceiro2221seesss 26$terceiro2221seesss 26$terceiro2221seesss 26$terceiro2221seesss 26$terceiro2221seesss 26$terceiro2221seesss 26$terceiro2221seesss 26$terceiro2221seesss 26$terceiro2221seesss 26$terceiro2221seesss 26$terceiro2221seesss 26$terceiro2221seesss 26$terceiro2221seesss 26$terceiro2221seesss 26$terceiro2221seesss
2 |
--------------------------------------------------------------------------------
/data/students22page.dat:
--------------------------------------------------------------------------------
1 | 26$terceiro2221seesss 26$terceiro2221seesss 26$terceiro2221seesss 26$terceiro2221seesss 26$terceiro2221seesss 26$terceiro2221seesss 26$terceiro2221seesss 26$terceiro2221seesss 26$terceiro2221seesss 26$terceiro2221seesss 26$terceiro2221seesss 26$terceiro2221seesss 26$terceiro2221seesss 26$terceiro2221seesss 26$terceiro2221seesss 26$terceiro2221seesss !
--------------------------------------------------------------------------------
/data/students23page.dat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/data/students23page.dat
--------------------------------------------------------------------------------
/main.py:
--------------------------------------------------------------------------------
1 | __author__ = 'Bernardo Godinho - @bernardogo'
2 |
3 | from query.evaluator import evaluator
4 | from storage.io import general
5 | from catalog.core import catalogCore
6 | from storage.tablemgr import manager
7 | from buffer.bufmgr import buffer_pool
8 | from query.commands.insert import *
9 | from query.commands.select import *
10 | from query.commands.update import *
11 |
12 | main_pool = buffer_pool()
13 |
14 | def main():
15 | print ("dsad")
16 |
17 | io = general()
18 | #io.initPage(2)
19 | io.write()
20 |
21 |
22 |
23 | eval = evaluator()
24 | eval.execute(
25 | """
26 | create table table_name
27 | (
28 | column_name1 data_type(size),
29 | column_name2 data_type(size),
30 | column_name3 data_type(size),
31 | );
32 | """
33 |
34 | )
35 |
36 |
37 |
38 | tblm = manager()
39 | tblm.createTable("students2", [["id", "integer"], ["phone", "string"]])
40 |
41 |
42 | ctlg2 = catalogCore()
43 | ctlg2.loadCatalog("students2")
44 | ctlg2.printCtlg()
45 |
46 |
47 | ins = insert()
48 |
49 | #ins.insertRecord("students2", ["26", "terce32441iro"])
50 | #for x in range(25, 82):
51 | # ins.insertRecord("students3", [str(x), "terce3PG32323o" + str(x)])
52 |
53 | sel = select()
54 | upd = update()
55 | #sel.selection("students2", [])
56 | upd.update("students2", [['phone', 'terceiro2221see']], [['phone', 'terceiro2221seesss']])
57 | sel.selection("students2", [['phone', 'terce32441iro']])
58 | print("321-----")
59 | #sel.selection("students2", [])
60 | #sel.selection("students3", [])
61 | #sel.join("students2", "students3", sel.selection("students2", []), sel.selection("students3", []), "id")
62 | main_pool.forceBuffer()
63 | print(main_pool.pool)
64 |
65 | from query.parser.sqlparse import parser
66 | pt = parser()
67 | #print(pt.parse("select * from x where x = 3 and y = 9"))
68 | #eval.execQuery("insert into students2 values (\"83\", \"gravado\")")
69 | print("select")
70 | eval.execQuery("select * from students2 where id = '26'") #where phone = terce32441iro
71 |
72 | main()
73 |
--------------------------------------------------------------------------------
/query/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/query/__init__.py
--------------------------------------------------------------------------------
/query/__init__.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/query/__init__.pyc
--------------------------------------------------------------------------------
/query/__pycache__/__init__.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/query/__pycache__/__init__.cpython-35.pyc
--------------------------------------------------------------------------------
/query/__pycache__/evaluator.cpython-34.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/query/__pycache__/evaluator.cpython-34.pyc
--------------------------------------------------------------------------------
/query/__pycache__/evaluator.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/query/__pycache__/evaluator.cpython-35.pyc
--------------------------------------------------------------------------------
/query/commands/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/query/commands/__init__.py
--------------------------------------------------------------------------------
/query/commands/__init__.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/query/commands/__init__.pyc
--------------------------------------------------------------------------------
/query/commands/__pycache__/__init__.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/query/commands/__pycache__/__init__.cpython-35.pyc
--------------------------------------------------------------------------------
/query/commands/__pycache__/insert.cpython-34.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/query/commands/__pycache__/insert.cpython-34.pyc
--------------------------------------------------------------------------------
/query/commands/__pycache__/insert.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/query/commands/__pycache__/insert.cpython-35.pyc
--------------------------------------------------------------------------------
/query/commands/__pycache__/select.cpython-34.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/query/commands/__pycache__/select.cpython-34.pyc
--------------------------------------------------------------------------------
/query/commands/__pycache__/select.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/query/commands/__pycache__/select.cpython-35.pyc
--------------------------------------------------------------------------------
/query/commands/__pycache__/update.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/query/commands/__pycache__/update.cpython-35.pyc
--------------------------------------------------------------------------------
/query/commands/delete.py:
--------------------------------------------------------------------------------
1 | __author__ = 'Bernardogo'
2 |
3 | from catalog.core import catalogCore
4 | from storage.io import general
5 | from storage.tablemgr import manager
6 | from storage.pageManager import pageManager
7 | from query.commands.select import select
8 |
9 | class delete:
10 | def __init__(self):
11 | pass
12 |
13 |
14 | def delete(self, table, values, newvalues):
15 | sel = select()
16 | pgmg = pageManager()
17 | sel.selection(table, values, pgmg.deleteValues, newvalues)
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/query/commands/insert.py:
--------------------------------------------------------------------------------
1 | __author__ = 'BernardoGO'
2 |
3 | from catalog.core import catalogCore
4 | from storage.io import general
5 | from storage.tablemgr import manager
6 | from storage.pageManager import pageManager
7 |
8 | class insert:
9 | def __init__(self):
10 | pass
11 |
12 | def insertRecord(self, table, values):
13 | ctlg = catalogCore()
14 | ctlg.loadCatalog(table)
15 | io_s = general()
16 | print("Values not verified.")
17 | if len(ctlg.catalog) == len(values):
18 | pgmg = pageManager()
19 | pgmg.writeValue(table, values)
20 | else:
21 | print("Number of values does not match table columns")
22 |
23 |
--------------------------------------------------------------------------------
/query/commands/insert.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/query/commands/insert.pyc
--------------------------------------------------------------------------------
/query/commands/select.py:
--------------------------------------------------------------------------------
1 | __author__ = 'BernardoGO'
2 |
3 | from catalog.core import catalogCore
4 | from storage.io import general
5 | from storage.tablemgr import manager
6 | from storage.pageManager import pageManager
7 |
8 | class select:
9 | def __init__(self):
10 | pass
11 |
12 | def buildValues(self, ctlg):
13 | builtVal = []
14 | for x in ctlg.catalog:
15 | builtVal.append(None)
16 | return builtVal
17 |
18 | def join(self, table1, table2, selection1, selection2, cond):
19 | ctlg1 = catalogCore()
20 | ctlg1.loadCatalog(table1)
21 | ctlg2 = catalogCore()
22 | ctlg2.loadCatalog(table2)
23 | pgmg = pageManager()
24 | io_s = general()
25 | cond1pos = -1
26 | cond2pos = -1
27 |
28 | for x in range(len(ctlg1.catalog)):
29 | if ctlg1.catalog[x][0] == cond:
30 | cond1pos = x
31 |
32 | for x in range(len(ctlg2.catalog)):
33 | if ctlg2.catalog[x][0] == cond:
34 | cond2pos = x
35 |
36 | joinedVals = []
37 | for x in selection1:
38 | for y in selection2:
39 | if x[1][cond1pos] == y[1][cond2pos]:
40 | newv = []
41 | newv.extend(x[1])
42 | newv.extend(y[1])
43 | joinedVals.append(newv)
44 | print(newv)
45 | return joinedVals
46 |
47 | def selection(self, table, values, function = None, newValues = None):
48 | ctlg = catalogCore()
49 | ctlg.loadCatalog(table)
50 |
51 | pgmg = pageManager()
52 | io_s = general()
53 | print("Values not verified.")
54 |
55 | vals = self.buildValues(ctlg)
56 | newVals = None
57 | if newValues is not None:
58 | newVals = self.buildValues(ctlg)
59 | for x in range(len(newValues)):
60 | for y in range(len(ctlg.catalog)):
61 | val1 = newValues[x][0]
62 | val2 = ctlg.catalog[y][0]
63 | if val1 == val2:
64 | newVals[y] = newValues[x][1]
65 |
66 | for x in range(len(values)):
67 | for y in range(len(ctlg.catalog)):
68 | print("VER: " + str(ctlg.catalog[y][0]))
69 | val1 = str(values[x][0]).replace("'", "")
70 | val2 = str(ctlg.catalog[y][0]).replace("'", "")
71 | if values[x][1] == '=':
72 | if val1 == val2:
73 | vals[y] = values[x][2].replace("'", "")
74 | else:
75 | print ("NO OPERATOR #322")
76 |
77 | print("VALS: " + str(vals))
78 | x = pgmg.readValues(table, vals, function, newVals)
79 | return x
80 | print(len(x))
81 | #print(len(pgmg.readValues(table, vals)))
82 |
--------------------------------------------------------------------------------
/query/commands/select.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/query/commands/select.pyc
--------------------------------------------------------------------------------
/query/commands/update.py:
--------------------------------------------------------------------------------
1 | __author__ = 'Bernardo'
2 |
3 | from catalog.core import catalogCore
4 | from storage.io import general
5 | from storage.tablemgr import manager
6 | from storage.pageManager import pageManager
7 | from query.commands.select import select
8 |
9 | class update:
10 | def __init__(self):
11 | pass
12 |
13 |
14 | def update(self, table, values, newvalues):
15 | sel = select()
16 | pgmg = pageManager()
17 | sel.selection(table, values, pgmg.updateValues, newvalues)
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/query/commands/update.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/query/commands/update.pyc
--------------------------------------------------------------------------------
/query/evaluator.py:
--------------------------------------------------------------------------------
1 | __author__ = 'Bernardo'
2 |
3 | ##### THIS IS A PLACEHOLDER EVALUATOR #####
4 |
5 | from query.commands.insert import *
6 | from query.commands.select import *
7 | from query.commands.update import *
8 |
9 | """
10 | CREATE TABLE table_name
11 | (
12 | column_name1 data_type(size),
13 | column_name2 data_type(size),
14 | column_name3 data_type(size),
15 | ....
16 | );
17 | """
18 |
19 | """
20 | sel.selection("students2", [['phone', 'terce32441iro']])
21 | """
22 | from catalog.core import catalogCore
23 | import re
24 | class evaluator:
25 | def execQuery(self, query):
26 | from query.parser.sqlparse import parser
27 | pt = parser()
28 | gentokens = pt.parse(query)
29 | print("tokens = ", gentokens)
30 | print("tokens.command =", gentokens.command)
31 | print("tokens.columns =", gentokens.columns)
32 | print("tokens.tables =", gentokens.tables)
33 | print("tokens.join =", gentokens.join)
34 | print("tokens.where =", gentokens.where)
35 | print("tokens.values =", gentokens.insValues)
36 |
37 | if gentokens.command == "select":
38 |
39 | sel = select()
40 |
41 | print ( "select detected")
42 | conditions = []
43 | if gentokens.where[0] == "where":
44 | print("where detected")
45 |
46 | for cond in gentokens.where:
47 | print ( cond)
48 | if isinstance(cond, list):
49 | print( "list detected in where")
50 | #working for equals only
51 |
52 | sel.selection(gentokens.tables[0], [gentokens.where[0][0]])
53 | #sel.selection("students2", [['phone', 'terce32441iro']])
54 |
55 | elif gentokens.command == "insert":
56 | ins = insert()
57 | iid = gentokens.insValues
58 | print(type(iid))
59 | print(iid)
60 | print(len(iid))
61 | print(iid)
62 | ins.insertRecord(gentokens.tables[0], iid)
63 |
64 |
65 | def execute(self, query):
66 | if ("create table") in query:
67 | createTbl = r"(?:\s*)create table(?:\s*)(.*?)(?:\s*)\((?:\s*)(.*?)\);"
68 | groups = re.findall(createTbl, query, re.S)
69 | print ("----->" + str(groups))
70 | attribsre = r"((?:.*?) (?:.*?),(?:\s*))"
71 | attribs = re.findall(attribsre, groups[0][1], re.S)
72 | print ("----->" + str(attribs))
73 | ctrl = catalogCore()
74 | ctrl.newCatalog(groups[0][0])
75 | for x in attribs:
76 | attr = x.split(" ")
77 | ctrl.insertAttr(attr[0], attr[1].replace(",", "").replace("\n", ""))
78 |
79 | ctrl.commitCatalog()
80 |
81 |
82 | #select = r"select (.*?) from (.*?);"
83 | #groups = re.findall(select, query, re.S)
84 |
--------------------------------------------------------------------------------
/query/evaluator.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/query/evaluator.pyc
--------------------------------------------------------------------------------
/query/parser/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/query/parser/__init__.py
--------------------------------------------------------------------------------
/query/parser/__init__.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/query/parser/__init__.pyc
--------------------------------------------------------------------------------
/query/parser/__pycache__/__init__.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/query/parser/__pycache__/__init__.cpython-35.pyc
--------------------------------------------------------------------------------
/query/parser/__pycache__/sqlparse.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/query/parser/__pycache__/sqlparse.cpython-35.pyc
--------------------------------------------------------------------------------
/query/parser/__pycache__/tokens.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/query/parser/__pycache__/tokens.cpython-35.pyc
--------------------------------------------------------------------------------
/query/parser/sqlparse.py:
--------------------------------------------------------------------------------
1 | from pyparsing import Literal, CaselessLiteral, Word, delimitedList, Optional, \
2 | Combine, Group, alphas, nums, alphanums, ParseException, Forward, oneOf, quotedString, \
3 | ZeroOrMore, restOfLine, Keyword, Suppress
4 |
5 | from query.parser import tokens
6 |
7 |
8 | class parser:
9 | def __init__(self):
10 | self.realNum = Combine( Optional(tokens.arithSign) + ( Word( nums ) + "." + Optional( Word(nums) ) |
11 | ( "." + Word(nums) ) ) +
12 | Optional( tokens.E + Optional(tokens.arithSign) + Word(nums) ) )
13 | self.intNum = Combine( Optional(tokens.arithSign) + Word( nums ) +
14 | Optional( tokens.E + Optional("+") + Word(nums) ) )
15 |
16 | self.columnRval = self.realNum | self.intNum | quotedString | tokens.columnName # need to add support for alg expressions
17 | self.whereCondition = Group(
18 | ( tokens.columnName + tokens.binop + self.columnRval ) |
19 | ( tokens.columnName + tokens.in_ + tokens.LPAREN + delimitedList( self.columnRval ) + tokens.RPAREN ) |
20 | ( tokens.columnName + tokens.in_ + tokens.LPAREN + tokens.selectStmt + tokens.RPAREN ) |
21 | ( tokens.LPAREN + tokens.whereExpression + tokens.RPAREN )
22 | )
23 | tokens.whereExpression << (self.whereCondition + Optional( ZeroOrMore( tokens.and_ | tokens.or_ ) + tokens.whereExpression ))
24 |
25 |
26 | self.joinCondition = Group(
27 | ( tokens.tableName + tokens.on_ + tokens.whereExpression )
28 | )
29 | tokens.joinExpression << (self.joinCondition )
30 |
31 |
32 | # define the grammar
33 | tokens.selectStmt << ( tokens.selectToken.setResultsName("command") +
34 | ( '*' | tokens.columnNameList ).setResultsName( "columns" ) +
35 |
36 | tokens.fromToken +
37 | tokens.tableNameList.setResultsName( "tables" ) +
38 | Optional( Group( CaselessLiteral("join") + tokens.joinExpression ), "" ).setResultsName("join") +
39 | Optional( Group( Suppress(CaselessLiteral("where")) + tokens.whereExpression ), "" ).setResultsName("where") )
40 |
41 | #self.valuesIter = ( self.columnRval | "," + self.columnRval)
42 |
43 | tokens.insertStmt << (tokens.insertToken.setResultsName("command") +
44 | tokens.intoToken.setResultsName("middle") +
45 | tokens.columnNameList.setResultsName( "tables" ) +
46 | tokens.valuesToken.setResultsName("val") +
47 | tokens.LPAREN + Group(delimitedList(self.columnRval, delim=r', ')).setResultsName("insValues") + tokens.RPAREN
48 |
49 |
50 |
51 | )
52 |
53 | self.simpleSQL = tokens.selectStmt | tokens.insertStmt
54 |
55 | # define Oracle comment format, and ignore them
56 | self.oracleSqlComment = "--" + restOfLine
57 | self.simpleSQL.ignore( self.oracleSqlComment )
58 |
59 | def parse(self, str):
60 | gentokens = None
61 | try:
62 | gentokens = self.simpleSQL.parseString( str )
63 | except ParseException as err:
64 | print(" "*err.loc + "^\n" + err.msg)
65 | print(err)
66 | return gentokens
67 |
68 | def test(self, str ):
69 | print(str,"->")
70 | try:
71 | gentokens = self.simpleSQL.parseString( str )
72 | print("tokens = ", gentokens)
73 | print("tokens.command =", gentokens.command)
74 | print("tokens.columns =", gentokens.columns)
75 | print("tokens.tables =", gentokens.tables)
76 | print("tokens.join =", gentokens.join)
77 | print("tokens.where =", gentokens.where)
78 | except ParseException as err:
79 | print(" "*err.loc + "^\n" + err.msg)
80 | print(err)
81 | print()
82 |
--------------------------------------------------------------------------------
/query/parser/sqlparse.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/query/parser/sqlparse.pyc
--------------------------------------------------------------------------------
/query/parser/tokens.py:
--------------------------------------------------------------------------------
1 | from pyparsing import Literal, CaselessLiteral, Word, delimitedList, Optional, \
2 | Combine, Group, alphas, nums, alphanums, ParseException, Forward, oneOf, quotedString, \
3 | ZeroOrMore, restOfLine, Keyword
4 |
5 |
6 | # define SQL tokens
7 | command = Forward()
8 | selectStmt = Forward()
9 | insertStmt = Forward()
10 | selectToken = Keyword("select", caseless=True)
11 | insertToken = Keyword("insert", caseless=True)
12 | fromToken = Keyword("from", caseless=True)
13 | intoToken = Keyword("into", caseless=True)
14 | valuesToken = Keyword("values", caseless=True)
15 | ident = Word( alphas, alphanums + "_$" ).setName("identifier")
16 | columnName = ( delimitedList( ident, ".", combine=True ) )
17 | columnNameList = Group( delimitedList( columnName ) )
18 | tableName = ( delimitedList( ident, ".", combine=True ) )
19 | tableNameList = Group( delimitedList( tableName ) )
20 | whereExpression = Forward()
21 | joinExpression = Forward()
22 | and_ = Keyword("and", caseless=True)
23 | or_ = Keyword("or", caseless=True)
24 | in_ = Keyword("in", caseless=True)
25 | on_ = Keyword("on", caseless=True)
26 | E = CaselessLiteral("E")
27 | binop = oneOf("= != < > >= <= eq ne lt le gt ge", caseless=True)
28 | arithSign = Word("+-",exact=1)
29 | LPAREN = "("
30 | RPAREN = ")"
31 |
--------------------------------------------------------------------------------
/query/parser/tokens.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/query/parser/tokens.pyc
--------------------------------------------------------------------------------
/storage/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/storage/__init__.py
--------------------------------------------------------------------------------
/storage/__init__.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/storage/__init__.pyc
--------------------------------------------------------------------------------
/storage/__pycache__/__init__.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/storage/__pycache__/__init__.cpython-35.pyc
--------------------------------------------------------------------------------
/storage/__pycache__/io.cpython-34.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/storage/__pycache__/io.cpython-34.pyc
--------------------------------------------------------------------------------
/storage/__pycache__/io.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/storage/__pycache__/io.cpython-35.pyc
--------------------------------------------------------------------------------
/storage/__pycache__/pageManager.cpython-34.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/storage/__pycache__/pageManager.cpython-34.pyc
--------------------------------------------------------------------------------
/storage/__pycache__/pageManager.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/storage/__pycache__/pageManager.cpython-35.pyc
--------------------------------------------------------------------------------
/storage/__pycache__/tablemgr.cpython-34.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/storage/__pycache__/tablemgr.cpython-34.pyc
--------------------------------------------------------------------------------
/storage/__pycache__/tablemgr.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/storage/__pycache__/tablemgr.cpython-35.pyc
--------------------------------------------------------------------------------
/storage/io.py:
--------------------------------------------------------------------------------
1 | __author__ = 'Bernardo Augusto Godinho de Oliveira - @bernardogo'
2 |
3 | __PAGE_SIZE__ = 1024
4 | __MAX_SIZE_SEQ__ = 64
5 | __CATALOG_FOLDER__ = "data/"
6 | __PAGE_SUFFIX__ = 'page.dat'
7 |
8 | __PAGE_SIZE__ += int(__PAGE_SIZE__/__MAX_SIZE_SEQ__)
9 |
10 |
11 | #### CONSTANTS
12 | __CONS_EMPTY_SLOT__ = 255
13 |
14 | class general:
15 | def func(self):
16 | print ("here")
17 |
18 | def readPage(self, pageId):
19 | file_ = open(__CATALOG_FOLDER__ + str(pageId) + __PAGE_SUFFIX__, 'rb')
20 | byt = bytearray(file_.read())
21 | file_.close()
22 | return byt
23 |
24 | def initPage(self, pageId):
25 | file_ = open(__CATALOG_FOLDER__ + str(pageId) + __PAGE_SUFFIX__, 'wb')
26 |
27 | toBeWritten = bytearray([]) #'\0' *__PAGE_SIZE__
28 | for i in range(__PAGE_SIZE__):
29 | toBeWritten.append(0)
30 |
31 | for x in range(int(__PAGE_SIZE__/ __MAX_SIZE_SEQ__)):
32 | toBeWritten[x*-1 -1] = __CONS_EMPTY_SLOT__
33 |
34 | file_.write(toBeWritten )
35 | file_.close()
36 | print("all written")
37 | print(self.readPage(pageId))
38 |
39 | def writePage(self, rids, records, pageId):
40 | file_ = open( __CATALOG_FOLDER__+str(pageId) + __PAGE_SUFFIX__, 'wb')
41 |
42 | toBeWritten = bytearray([]) #'\0' *__PAGE_SIZE__
43 | for i in range(__PAGE_SIZE__):
44 | toBeWritten.append(0)
45 |
46 | for x in range(int(__PAGE_SIZE__/ __MAX_SIZE_SEQ__)):
47 | toBeWritten[x*-1 -1] = __CONS_EMPTY_SLOT__
48 |
49 | file_ = open(__CATALOG_FOLDER__ + str(pageId) + __PAGE_SUFFIX__, 'wb')
50 | print(self.readPage(pageId))
51 |
52 | print(toBeWritten)
53 | for ridN in range(len(rids)):
54 | position = 255
55 | for x in range(int(__PAGE_SIZE__/ __MAX_SIZE_SEQ__)):
56 |
57 | if toBeWritten[x*-1 -1] == __CONS_EMPTY_SLOT__:
58 | toBeWritten[x*-1-1] = rids[ridN]
59 | position = x
60 | break
61 |
62 | for x in range(len(records[ridN])):
63 | toBeWritten[x+(position*__MAX_SIZE_SEQ__)] = ord(records[ridN][x])
64 |
65 | file_.write(toBeWritten )
66 | file_.close()
67 | print("all written")
68 | print(self.readPage(pageId))
69 |
70 | def writeValue(self, rid, bytes, pageId):
71 | toBeWritten = self.readPage(pageId) #'\0' *__PAGE_SIZE__
72 | file_ = open(__CATALOG_FOLDER__ + str(pageId) + __PAGE_SUFFIX__, 'wb')
73 | print(self.readPage(pageId))
74 |
75 | print(toBeWritten)
76 | position = 255
77 | for x in range(int(__PAGE_SIZE__/ __MAX_SIZE_SEQ__)):
78 |
79 | if toBeWritten[x*-1-1] == __CONS_EMPTY_SLOT__:
80 | toBeWritten[x*-1-1] = rid
81 | position = x
82 | break
83 |
84 | for x in range(len(bytes)):
85 | toBeWritten[x+(position*__MAX_SIZE_SEQ__)] = ord(bytes[x])
86 |
87 | file_.write(toBeWritten )
88 | file_.close()
89 | print("all written")
90 | print(self.readPage(pageId))
91 |
92 |
93 |
94 | def readValue(self, rid, pageid):
95 | page = self.readPage(pageid)
96 | position = 255
97 | for x in range(int(__PAGE_SIZE__/ __MAX_SIZE_SEQ__)):
98 | if page[x*-1 -1] == rid:
99 | position = x
100 | break
101 | print(position)
102 | value = bytearray([])
103 | for x in range(__MAX_SIZE_SEQ__):
104 | value.append(page[x+(position*__MAX_SIZE_SEQ__)])
105 | print(value.decode("utf-8") )
106 |
107 | def hasEmptySpace(self, pageid):
108 | page = self.readPage(pageid)
109 | position = 255
110 | for x in range(int(__PAGE_SIZE__/ __MAX_SIZE_SEQ__)):
111 | if page[x*-1 -1] == __CONS_EMPTY_SLOT__:
112 | return True
113 | return False
114 |
115 | def readValues(self, pageid):
116 | page = self.readPage(pageid)
117 | values = []
118 | rids = []
119 | positions = []
120 | for x in range(int(__PAGE_SIZE__/ __MAX_SIZE_SEQ__)):
121 | positions.append(x)
122 |
123 | for y in positions:
124 |
125 | value = bytearray([])
126 | for x in range(__MAX_SIZE_SEQ__):
127 | value.append(page[x+(y*__MAX_SIZE_SEQ__)])
128 | values.append(value.decode("utf-8"))
129 |
130 | for x in range(int(__PAGE_SIZE__/ __MAX_SIZE_SEQ__)):
131 | rids.append(page[x*-1 -1])
132 | print(page)
133 | print(rids)
134 | return [values, rids]
135 |
136 |
137 |
138 | def write(self):
139 | print("write function called while it was not necessary")
140 | return
141 | self.initPage(2)
142 | print(self.readPage(2))
143 | self.writeValue(40, "test1running", 2)
144 | self.writeValue(41, "test2running", 2)
145 | self.writeValue(43, "test23running", 2)
146 | self.readValue(43,2)
147 |
--------------------------------------------------------------------------------
/storage/io.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/storage/io.pyc
--------------------------------------------------------------------------------
/storage/pageManager.py:
--------------------------------------------------------------------------------
1 | __author__ = 'Bernardo'
2 |
3 | import pickle
4 | from storage.io import general
5 | from buffer.bufmgr import buffer_pool
6 | import storage.io
7 |
8 | __CATALOG_FOLDER__ = "data/"
9 | __CATALOG_PREFIX__ = __CATALOG_FOLDER__+ "pagemgr"
10 |
11 | __numberOfPages_IDX__ = 0
12 |
13 | class pageManager:
14 | def __init__(self):
15 | self.catalog = {}
16 | if(len(self.catalog) == 0):
17 | self.load()
18 |
19 | def updateInfo(self, table, value):
20 | #numberOfPages|AutoIncrNumber
21 | self.catalog[table] = value
22 | self.commit()
23 |
24 | def buildRow(self, row):
25 | newPg = ""
26 | for i in range(len(row)): ########################### THIS IS NOT THE BEST WAY TO DO THIS, CHANGE THE BUFFER FILE
27 | newPg += row[i] + "$"
28 | return newPg[0:len(newPg)-1]
29 |
30 |
31 | def writeValue(self, table, values):
32 | io_s = general()
33 | bfm = buffer_pool()
34 | if(table not in self.catalog):
35 | print("not in")
36 | self.catalog[table] = [0,0]
37 |
38 | self.catalog[table] = [self.catalog[table][0],self.catalog[table][1]+1]
39 | pageid = table + str(self.catalog[table][__numberOfPages_IDX__])
40 |
41 | if(self.catalog[table][__numberOfPages_IDX__] == 0):
42 | self.catalog[table][__numberOfPages_IDX__] += 1
43 | pageid = table + str(self.catalog[table][__numberOfPages_IDX__])
44 | io_s.initPage(pageid)
45 |
46 |
47 |
48 | self.commit()
49 | strToSVX = ""
50 | for x in values:
51 | strToSVX += x.replace('""', '') + "$"
52 | strToSVX = strToSVX[0:len(strToSVX)-1]
53 |
54 | while(True):
55 | if(io_s.hasEmptySpace(pageid)):
56 |
57 | #io_s.writeValue(self.catalog[table][1], strToSVX, pageid)
58 | #victim = bfm.replacePage(pageid)
59 |
60 | readvals = bfm.findPage(pageid)
61 | if readvals == -1:
62 | readvals = bfm.replacePage(pageid)
63 |
64 | for rec in range(len(bfm.pool[readvals].rids)):
65 | if bfm.pool[readvals].rids[rec] == storage.io.__CONS_EMPTY_SLOT__:
66 | bfm.pool[readvals].rids[rec] = self.catalog[table][1]
67 | bfm.pool[readvals].page[rec] =strToSVX
68 | bfm.pool[readvals].dirty = True
69 | break
70 |
71 | print("Values written")
72 | break
73 | else:
74 | self.catalog[table][__numberOfPages_IDX__] += 1
75 | self.commit()
76 | pageid = table + str(self.catalog[table][__numberOfPages_IDX__])
77 | io_s.initPage(pageid)
78 | print("Another page created")
79 |
80 |
81 | def updateValues(self, row, xx, yy, newValues):
82 | bfm = buffer_pool()
83 | for xxs in range(len(newValues)):
84 | if newValues[xxs] is None:
85 | continue
86 | else:
87 | row[xxs] = newValues[xxs]
88 | bfm.pool[xx].page[yy] = self.buildRow(row)
89 | bfm.pool[xx].dirty = True
90 |
91 | def deleteValues(self, row, xx, yy, newValues):
92 | bfm = buffer_pool()
93 | for xxs in range(len(newValues)):
94 | if newValues[xxs] is None:
95 | continue
96 | else:
97 | bfm.pool[xx].page[yy] = self.buildRow(row)
98 | bfm.pool[xx].dirty = True
99 | bfm.pool[xx].rids[yy] = storage.io.__CONS_EMPTY_SLOT__
100 |
101 | def replaceControl(self, page):
102 | bfm = buffer_pool()
103 | readvals = bfm.findPage(page)
104 | if readvals == -1:
105 | bfm.replacePage(page)
106 | return bfm.findPage(page)
107 |
108 | def readValues(self, table, cond = None, function = None, newValues = None):
109 | bfm = buffer_pool()
110 | print("match")
111 | io_s = general()
112 | if(len(self.catalog) == 0):
113 | print("WARNING: IT SHOULD BE LOADED HERE")
114 | self.load()
115 |
116 | if(table not in self.catalog):
117 | print("Table does not exists -- attention")
118 |
119 |
120 | print(self.catalog)
121 | print (self.catalog[table][__numberOfPages_IDX__])
122 | values = []
123 | for x in range(1, self.catalog[table][__numberOfPages_IDX__]+1):
124 | #readvals = io_s.readValues(table + str(x))
125 | page = table + str(x)
126 | victimPage = self.replaceControl(page)
127 |
128 | for victimRecord in range(len(bfm.pool[victimPage].page)):
129 | y = bfm.pool[victimPage].page[victimRecord]
130 |
131 | row = y.split(chr(0))[0].split("$")
132 |
133 | if len(row) == 1 and len(row[0]) == 0: continue#empty row
134 | elif len(row) > 0:
135 |
136 | if cond is None: #not a filtered selection
137 | values.append([bfm.pool[victimPage].rids[victimRecord], row])
138 | else:
139 | if len(cond) != len(row):
140 | print("Length of values does not match table")
141 | else:
142 | valid = True
143 | for x in range(len(cond)):
144 | if cond[x] is None:
145 | continue
146 | else:
147 | if str(cond[x]) != str(row[x]):
148 | #print ( str(cond[x]) +"-VER-"+ str(row[x]))
149 | valid = False
150 | break
151 |
152 | if valid and bfm.pool[victimPage].rids[victimRecord] != storage.io.__CONS_EMPTY_SLOT__:
153 | if newValues is not None:
154 | function(row, victimPage, victimRecord, newValues)
155 | values.append([bfm.pool[victimPage].rids[victimRecord], row])
156 | print (values)
157 | return values
158 |
159 |
160 | def commit(self):
161 | pickle.dump(self.catalog, open(__CATALOG_PREFIX__ + ".dat", 'wb'), protocol=2)
162 |
163 | def load(self):
164 | try:
165 | self.catalog = pickle.load(open(__CATALOG_PREFIX__ + ".dat", 'rb'))
166 | except Exception as e:
167 | print("FAILED TO LOAD CATALOG" + str(e))
168 | pass
169 |
--------------------------------------------------------------------------------
/storage/pageManager.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/storage/pageManager.pyc
--------------------------------------------------------------------------------
/storage/tablemgr.py:
--------------------------------------------------------------------------------
1 | __author__ = 'Bernardo'
2 |
3 | import re
4 |
5 | from catalog.core import catalogCore
6 |
7 |
8 | class manager:
9 | def createTable(self, name, attrs):
10 | ctlg = catalogCore()
11 | ctlg.tableName = name
12 | for x in attrs:
13 | ctlg.insertAttr(x[0], x[1])
14 | ctlg.commitCatalog()
15 |
16 |
--------------------------------------------------------------------------------
/storage/tablemgr.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/PyDB/5427995aa8a3829eba872b66e7ce4c51aa91013d/storage/tablemgr.pyc
--------------------------------------------------------------------------------