예제 #1
0
파일: select.py 프로젝트: jango2015/PyDB
    def join(self, table1, table2, selection1, selection2, cond):
        ctlg1 = catalogCore()
        ctlg1.loadCatalog(table1)
        ctlg2 = catalogCore()
        ctlg2.loadCatalog(table2)
        pgmg = pageManager()
        io_s = general()
        cond1pos = -1
        cond2pos = -1

        for x in range(len(ctlg1.catalog)):
            if ctlg1.catalog[x][0] == cond:
                cond1pos = x

        for x in range(len(ctlg2.catalog)):
            if ctlg2.catalog[x][0] == cond:
                cond2pos = x

        joinedVals = []
        for x in selection1:
            for y in selection2:
                if x[1][cond1pos] == y[1][cond2pos]:
                    newv = []
                    newv.extend(x[1])
                    newv.extend(y[1])
                    joinedVals.append(newv)
                    print(newv)
        return joinedVals
예제 #2
0
파일: select.py 프로젝트: jango2015/PyDB
    def selection(self, table, values, function=None, newValues=None):
        ctlg = catalogCore()
        ctlg.loadCatalog(table)

        pgmg = pageManager()
        io_s = general()
        print("Values not verified.")

        vals = self.buildValues(ctlg)
        newVals = None
        if newValues is not None:
            newVals = self.buildValues(ctlg)
            for x in range(len(newValues)):
                for y in range(len(ctlg.catalog)):
                    val1 = newValues[x][0]
                    val2 = ctlg.catalog[y][0]
                    if val1 == val2:
                        newVals[y] = newValues[x][1]

        for x in range(len(values)):
            for y in range(len(ctlg.catalog)):
                val1 = values[x][0]
                val2 = ctlg.catalog[y][0]
                if val1 == val2:
                    vals[y] = values[x][1]

        x = pgmg.readValues(table, vals, function, newVals)
        return x
        print(len(x))
예제 #3
0
    def join(self, table1, table2, selection1, selection2, cond):
        ctlg1 = catalogCore()
        ctlg1.loadCatalog(table1)
        ctlg2 = catalogCore()
        ctlg2.loadCatalog(table2)
        pgmg = pageManager()
        io_s = general()
        cond1pos = -1
        cond2pos = -1

        for x in range(len(ctlg1.catalog)):
            if ctlg1.catalog[x][0] == cond:
                cond1pos = x

        for x in range(len(ctlg2.catalog)):
            if ctlg2.catalog[x][0] == cond:
                cond2pos = x

        joinedVals = []
        for x in selection1:
            for y in selection2:
                if x[1][cond1pos] == y[1][cond2pos]:
                    newv = []
                    newv.extend(x[1])
                    newv.extend(y[1])
                    joinedVals.append(newv)
                    print(newv)
        return joinedVals
예제 #4
0
    def selection(self, table, values, function = None, newValues = None):
        ctlg = catalogCore()
        ctlg.loadCatalog(table)

        pgmg = pageManager()
        io_s = general()
        print("Values not verified.")

        vals = self.buildValues(ctlg)
        newVals = None
        if newValues is not None:
            newVals = self.buildValues(ctlg)
            for x in range(len(newValues)):
                for y in range(len(ctlg.catalog)):
                    val1 = newValues[x][0]
                    val2 = ctlg.catalog[y][0]
                    if val1 == val2:
                        newVals[y] = newValues[x][1]

        for x in range(len(values)):
            for y in range(len(ctlg.catalog)):
                print("VER: " + str(ctlg.catalog[y][0]))
                val1 = str(values[x][0]).replace("'", "")
                val2 = str(ctlg.catalog[y][0]).replace("'", "")
                if values[x][1] == '=':
                    if val1 == val2:
                        vals[y] = values[x][2].replace("'", "")
                else:
                    print ("NO OPERATOR #322")

        print("VALS: " + str(vals))
        x = pgmg.readValues(table, vals, function, newVals)
        return x
        print(len(x))
예제 #5
0
    def writeValue(self, table, values):
        io_s = general()

        if(table not in self.catalog):
            print("not in")
            self.catalog[table] = [0,0]

        self.catalog[table] = [self.catalog[table][0],self.catalog[table][1]+1]
        pageid = table + str(self.catalog[table][__numberOfPages_IDX__])

        if(self.catalog[table][__numberOfPages_IDX__] == 0):
            self.catalog[table][__numberOfPages_IDX__] += 1
            pageid = table + str(self.catalog[table][__numberOfPages_IDX__])
            io_s.initPage(pageid)



        self.commit()
        strToSVX = ""
        for x in values:
            strToSVX += x + "$"
        strToSVX = strToSVX[0:len(strToSVX)-1]

        while(True):
            if(io_s.hasEmptySpace(pageid)):
                io_s.writeValue(self.catalog[table][1], strToSVX, pageid)
                break
            else:
                self.catalog[table][__numberOfPages_IDX__] += 1
                self.commit()
                pageid = table + str(self.catalog[table][__numberOfPages_IDX__])
                io_s.initPage(pageid)
                print("Another page created")
예제 #6
0
    def selection(self, table, values, function = None, newValues = None):
        ctlg = catalogCore()
        ctlg.loadCatalog(table)

        pgmg = pageManager()
        io_s = general()
        print("Values not verified.")

        vals = self.buildValues(ctlg)
        newVals = None
        if newValues is not None:
            newVals = self.buildValues(ctlg)
            for x in range(len(newValues)):
                for y in range(len(ctlg.catalog)):
                    val1 = newValues[x][0]
                    val2 = ctlg.catalog[y][0]
                    if val1 == val2:
                        newVals[y] = newValues[x][1]

        for x in range(len(values)):
            for y in range(len(ctlg.catalog)):
                val1 = values[x][0]
                val2 = ctlg.catalog[y][0]
                if val1 == val2:
                    vals[y] = values[x][1]


        x = pgmg.readValues(table, vals, function, newVals)
        return x
        print(len(x))
예제 #7
0
 def addToPool(self, pid):
     ios = general()
     newb = buffer()
     newb.pid = pid
     newb.timestamp = calendar.timegm(time.gmtime())
     if pid is not None:
         newb.page = ios.readPage(pid)
     buffer_pool.pool.append(newb)
예제 #8
0
    def selection(self, table, values):
        ctlg = catalogCore()
        ctlg.loadCatalog(table)
        pgmg = pageManager()
        io_s = general()
        print("Values not verified.")

        pgmg.readValues(table)
예제 #9
0
 def addToPool(self, pid):
     ios = general()
     newb = buffer()
     newb.pid = pid
     newb.timestamp = calendar.timegm(time.gmtime())
     if pid is not None:
         newb.page = ios.readPage(pid)
     buffer_pool.pool.append(newb)
예제 #10
0
def main():
    print ("dsad")

    io = general()
    #io.initPage(2)
    io.write()



    eval = evaluator()
    eval.execute(
        """
        create table table_name
        (
        column_name1 data_type(size),
        column_name2 data_type(size),
        column_name3 data_type(size),
        );
        """

    )



    tblm = manager()
    tblm.createTable("students2", [["id", "integer"], ["phone", "string"]])


    ctlg2 = catalogCore()
    ctlg2.loadCatalog("students2")
    ctlg2.printCtlg()


    ins = insert()

    #ins.insertRecord("students2", ["26", "terce32441iro"])
    #for x in range(25, 82):
    #    ins.insertRecord("students3", [str(x), "terce3PG32323o" + str(x)])

    sel = select()
    upd = update()
    #sel.selection("students2", [])
    upd.update("students2", [['phone', 'terceiro2221see']], [['phone', 'terceiro2221seesss']])
    sel.selection("students2", [['phone', 'terce32441iro']])
    print("321-----")
    #sel.selection("students2", [])
    #sel.selection("students3", [])
    #sel.join("students2", "students3", sel.selection("students2", []), sel.selection("students3", []), "id")
    main_pool.forceBuffer()
    print(main_pool.pool)

    from query.parser.sqlparse import parser
    pt = parser()
    #print(pt.parse("select * from x where x = 3 and y = 9"))
    #eval.execQuery("insert into students2 values (\"83\", \"gravado\")")
    print("select")
    eval.execQuery("select * from students2 where phone = 'gravado'") #where phone = terce32441iro
예제 #11
0
파일: main.py 프로젝트: MauricioTorre/PyDB
def main():
    print ("dsad")

    io = general()
    #io.initPage(2)
    io.write()



    eval = evaluator()
    eval.execute(
        """
        create table table_name
        (
        column_name1 data_type(size),
        column_name2 data_type(size),
        column_name3 data_type(size),
        );
        """

    )



    tblm = manager()
    tblm.createTable("students2", [["id", "integer"], ["phone", "string"]])


    ctlg2 = catalogCore()
    ctlg2.loadCatalog("students2")
    ctlg2.printCtlg()


    ins = insert()

    #ins.insertRecord("students2", ["26", "terce32441iro"])
    #for x in range(25, 82):
    #    ins.insertRecord("students3", [str(x), "terce3PG32323o" + str(x)])

    sel = select()
    upd = update()
    #sel.selection("students2", [])
    upd.update("students2", [['phone', 'terceiro2221see']], [['phone', 'terceiro2221seesss']])
    sel.selection("students2", [['phone', 'terce32441iro']])
    print("321-----")
    #sel.selection("students2", [])
    #sel.selection("students3", [])
    #sel.join("students2", "students3", sel.selection("students2", []), sel.selection("students3", []), "id")
    main_pool.forceBuffer()
    print(main_pool.pool)

    from query.parser.sqlparse import parser
    pt = parser()
    #print(pt.parse("select * from x where x = 3 and y = 9"))
    #eval.execQuery("insert into students2 values (\"83\", \"gravado\")")
    print("select")
    eval.execQuery("select * from students2 where id = '26'") #where phone = terce32441iro
예제 #12
0
 def insertRecord(self, table, values):
     ctlg = catalogCore()
     ctlg.loadCatalog(table)
     io_s = general()
     print("Values not verified.")
     if len(ctlg.catalog) == len(values):
         pgmg = pageManager()
         pgmg.writeValue(table, values)
     else:
         print("Number of values does not match table columns")
예제 #13
0
 def insertRecord(self, table, values):
     ctlg = catalogCore()
     ctlg.loadCatalog(table)
     io_s = general()
     print("Values not verified.")
     if len(ctlg.catalog) == len(values):
         pgmg = pageManager()
         pgmg.writeValue(table, values)
     else:
         print("Number of values does not match table columns")
예제 #14
0
    def readValues(self, table, cond=None, function=None, newValues=None):
        bfm = buffer_pool()
        print("match")
        io_s = general()
        if (len(self.catalog) == 0):
            print("WARNING: IT SHOULD BE LOADED HERE")
            self.load()

        if (table not in self.catalog):
            print("Table does not exists -- attention")

        print(self.catalog)
        print(self.catalog[table][__numberOfPages_IDX__])
        values = []
        for x in range(1, self.catalog[table][__numberOfPages_IDX__] + 1):
            #readvals = io_s.readValues(table + str(x))
            page = table + str(x)
            victimPage = self.replaceControl(page)

            for victimRecord in range(len(bfm.pool[victimPage].page)):
                y = bfm.pool[victimPage].page[victimRecord]

                row = y.split(chr(0))[0].split("$")

                if len(row) == 1 and len(row[0]) == 0: continue  #empty row
                elif len(row) > 0:

                    if cond is None:  #not a filtered selection
                        values.append(
                            [bfm.pool[victimPage].rids[victimRecord], row])
                    else:
                        if len(cond) != len(row):
                            print("Length of values does not match table")
                        else:
                            valid = True
                            for x in range(len(cond)):
                                if cond[x] is None:
                                    continue
                                else:
                                    if cond[x] != row[x]:
                                        valid = False
                                        break

                            if valid and bfm.pool[victimPage].rids[
                                    victimRecord] != storage.io.__CONS_EMPTY_SLOT__:
                                if newValues is not None:
                                    function(row, victimPage, victimRecord,
                                             newValues)
                                values.append([
                                    bfm.pool[victimPage].rids[victimRecord],
                                    row
                                ])
        print(values)
        return values
예제 #15
0
    def writeValue(self, table, values):
        io_s = general()
        bfm = buffer_pool()
        if (table not in self.catalog):
            print("not in")
            self.catalog[table] = [0, 0]

        self.catalog[table] = [
            self.catalog[table][0], self.catalog[table][1] + 1
        ]
        pageid = table + str(self.catalog[table][__numberOfPages_IDX__])

        if (self.catalog[table][__numberOfPages_IDX__] == 0):
            self.catalog[table][__numberOfPages_IDX__] += 1
            pageid = table + str(self.catalog[table][__numberOfPages_IDX__])
            io_s.initPage(pageid)

        self.commit()
        strToSVX = ""
        for x in values:
            strToSVX += x.replace('""', '') + "$"
        strToSVX = strToSVX[0:len(strToSVX) - 1]

        while (True):
            if (io_s.hasEmptySpace(pageid)):

                #io_s.writeValue(self.catalog[table][1], strToSVX, pageid)
                #victim = bfm.replacePage(pageid)

                readvals = bfm.findPage(pageid)
                if readvals == -1:
                    readvals = bfm.replacePage(pageid)

                for rec in range(len(bfm.pool[readvals].rids)):
                    if bfm.pool[readvals].rids[
                            rec] == storage.io.__CONS_EMPTY_SLOT__:
                        bfm.pool[readvals].rids[rec] = self.catalog[table][1]
                        bfm.pool[readvals].page[rec] = strToSVX
                        bfm.pool[readvals].dirty = True
                        break

                print("Values written")
                break
            else:
                self.catalog[table][__numberOfPages_IDX__] += 1
                self.commit()
                pageid = table + str(
                    self.catalog[table][__numberOfPages_IDX__])
                io_s.initPage(pageid)
                print("Another page created")
예제 #16
0
    def readValues(self, table, cond = None, function = None, newValues = None):
        bfm = buffer_pool()
        print("match")
        io_s = general()
        if(len(self.catalog) == 0):
            print("WARNING: IT SHOULD BE LOADED HERE")
            self.load()

        if(table not in self.catalog):
            print("Table does not exists -- attention")


        print(self.catalog)
        print (self.catalog[table][__numberOfPages_IDX__])
        values = []
        for x in range(1, self.catalog[table][__numberOfPages_IDX__]+1):
            #readvals = io_s.readValues(table + str(x))
            page = table + str(x)
            victimPage = self.replaceControl(page)

            for victimRecord in range(len(bfm.pool[victimPage].page)):
                y = bfm.pool[victimPage].page[victimRecord]

                row = y.split(chr(0))[0].split("$")

                if len(row) == 1 and len(row[0]) == 0: continue#empty row
                elif len(row) > 0:

                    if cond is None: #not a filtered selection
                        values.append([bfm.pool[victimPage].rids[victimRecord], row])
                    else:
                        if len(cond) != len(row):
                            print("Length of values does not match table")
                        else:
                            valid = True
                            for x in range(len(cond)):
                                if cond[x] is None:
                                    continue
                                else:
                                    if str(cond[x]) != str(row[x]):
                                        #print ( str(cond[x]) +"-VER-"+ str(row[x]))
                                        valid = False
                                        break

                            if valid and bfm.pool[victimPage].rids[victimRecord] != storage.io.__CONS_EMPTY_SLOT__:
                                if newValues is not None:
                                    function(row, victimPage, victimRecord, newValues)
                                values.append([bfm.pool[victimPage].rids[victimRecord], row])
        print (values)
        return values
예제 #17
0
    def writeValue(self, table, values):
        io_s = general()
        bfm = buffer_pool()
        if(table not in self.catalog):
            print("not in")
            self.catalog[table] = [0,0]

        self.catalog[table] = [self.catalog[table][0],self.catalog[table][1]+1]
        pageid = table + str(self.catalog[table][__numberOfPages_IDX__])

        if(self.catalog[table][__numberOfPages_IDX__] == 0):
            self.catalog[table][__numberOfPages_IDX__] += 1
            pageid = table + str(self.catalog[table][__numberOfPages_IDX__])
            io_s.initPage(pageid)



        self.commit()
        strToSVX = ""
        for x in values:
            strToSVX += x + "$"
        strToSVX = strToSVX[0:len(strToSVX)-1]

        while(True):
            if(io_s.hasEmptySpace(pageid)):

                #io_s.writeValue(self.catalog[table][1], strToSVX, pageid)
                #victim = bfm.replacePage(pageid)

                readvals = bfm.findPage(pageid)
                if readvals == -1:
                    readvals = bfm.replacePage(pageid)

                for rec in range(len(bfm.pool[readvals].rids)):
                    if bfm.pool[readvals].rids[rec] == storage.io.__CONS_EMPTY_SLOT__:
                        bfm.pool[readvals].rids[rec] = self.catalog[table][1]
                        bfm.pool[readvals].page[rec] =strToSVX
                        bfm.pool[readvals].dirty = True
                        break

                print("Values written")
                break
            else:
                self.catalog[table][__numberOfPages_IDX__] += 1
                self.commit()
                pageid = table + str(self.catalog[table][__numberOfPages_IDX__])
                io_s.initPage(pageid)
                print("Another page created")
예제 #18
0
 def readValues(self, table):
     print("match")
     io_s = general()
     if(table not in self.catalog):
         print("Table does not exists -- attention")
     print (self.catalog[table][__numberOfPages_IDX__])
     values = []
     for x in range(1, self.catalog[table][__numberOfPages_IDX__]+1):
         readvals = io_s.readValues(table + str(x))
         for y in readvals:
             row = y.split(chr(0))[0].split("$")
             if len(row) == 1:
                 if len(row[0]) == 0:
                     continue
             if len(row) > 0:
                 values.append(row)
     print (values)
예제 #19
0
    def replacePage(self, pid):
        ios = general()
        newb = buffer()
        newb.pid = pid

        page = ios.readValues(pid)
        print(page[0])

        newb.page = page[0]#.split(chr(0))[0].split("$")
        newb.rids = page[1]
        victim = self.findVictimPage()
        buffer_pool.pool[victim].forcePage()   #Forces all data to disk before replacing
        #time.sleep(1)
        newb.timestamp = time.time()

        print("Replacing Page: " + str(buffer_pool.pool[victim].pid) + " -> " + str(newb.pid) + " on slot " + str(victim))
        buffer_pool.pool[victim] = newb
        print(buffer_pool.pool[victim].rids)
        print(buffer_pool.pool[victim].page)
        return victim
예제 #20
0
    def replacePage(self, pid):
        ios = general()
        newb = buffer()
        newb.pid = pid

        page = ios.readValues(pid)
        print(page[0])

        newb.page = page[0]  #.split(chr(0))[0].split("$")
        newb.rids = page[1]
        victim = self.findVictimPage()
        buffer_pool.pool[victim].forcePage(
        )  #Forces all data to disk before replacing
        #time.sleep(1)
        newb.timestamp = time.time()

        print("Replacing Page: " + str(buffer_pool.pool[victim].pid) + " -> " +
              str(newb.pid) + " on slot " + str(victim))
        buffer_pool.pool[victim] = newb
        print(buffer_pool.pool[victim].rids)
        print(buffer_pool.pool[victim].page)
        return victim
예제 #21
0
    def forcePage(self):
        if self.pid is None or self.dirty is False:
            return
        ios = general()

        ios.writePage(self.rids, self.page, self.pid)
예제 #22
0
__author__ = 'Bernardo Augusto Godinho de Oliveira - @bernardogo'

from storage.io import general
from query.evaluator import evaluator
from catalog.core import catalogCore
from storage.tablemgr import manager


def main():
    print("dsad")


io = general()
#io.initPage(2)
io.write()

eval = evaluator()
eval.execute("""
    create table table_name
    (
    column_name1 data_type(size),
    column_name2 data_type(size),
    column_name3 data_type(size),
    );
    """)

tblm = manager()
tblm.createTable("students2", [["id", "integer"], ["phone", "string"]])

ctlg2 = catalogCore()
ctlg2.loadCatalog("students2")
예제 #23
0
파일: main.py 프로젝트: BernardoGO/test
__author__ = 'Bernardo Augusto Godinho de Oliveira - @bernardogo'

from storage.io import general
from query.evaluator import evaluator
from catalog.core import catalogCore
from storage.tablemgr import manager

def main():
    print ("dsad")

io = general()
#io.initPage(2)
io.write()

eval = evaluator()
eval.execute(
    """
    create table table_name
    (
    column_name1 data_type(size),
    column_name2 data_type(size),
    column_name3 data_type(size),
    );
    """

)

tblm = manager()
tblm.createTable("students2", [["id", "integer"], ["phone", "string"]])

예제 #24
0
    def forcePage(self):
        if self.pid is None or self.dirty is False:
            return
        ios = general()

        ios.writePage(self.rids, self.page, self.pid)