示例#1
0
 def deleteValues(self, row, xx, yy, newValues):
     bfm = buffer_pool()
     for xxs in range(len(newValues)):
         if newValues[xxs] is None:
             continue
         else:
             bfm.pool[xx].page[yy] = self.buildRow(row)
             bfm.pool[xx].dirty = True
             bfm.pool[xx].rids[yy] = storage.io.__CONS_EMPTY_SLOT__
示例#2
0
 def deleteValues(self, row, xx, yy, newValues):
     bfm = buffer_pool()
     for xxs in range(len(newValues)):
         if newValues[xxs] is None:
             continue
         else:
             bfm.pool[xx].page[yy] = self.buildRow(row)
             bfm.pool[xx].dirty = True
             bfm.pool[xx].rids[yy] = storage.io.__CONS_EMPTY_SLOT__
示例#3
0
 def updateValues(self, row, xx, yy, newValues):
     bfm = buffer_pool()
     for xxs in range(len(newValues)):
         if newValues[xxs] is None:
             continue
         else:
             row[xxs] = newValues[xxs]
             bfm.pool[xx].page[yy] = self.buildRow(row)
             bfm.pool[xx].dirty = True
示例#4
0
 def updateValues(self, row, xx, yy, newValues):
     bfm = buffer_pool()
     for xxs in range(len(newValues)):
         if newValues[xxs] is None:
             continue
         else:
             row[xxs] = newValues[xxs]
             bfm.pool[xx].page[yy] = self.buildRow(row)
             bfm.pool[xx].dirty = True
示例#5
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
示例#6
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")
示例#7
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
示例#8
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")
示例#9
0
 def replaceControl(self, page):
     bfm = buffer_pool()
     readvals = bfm.findPage(page)
     if readvals == -1:
         bfm.replacePage(page)
     return bfm.findPage(page)
示例#10
0
文件: main.py 项目: jango2015/PyDB
__author__ = 'Bernardo Augusto Godinho de Oliveira - @bernardogo'

from query.evaluator import evaluator
from storage.io import general
from catalog.core import catalogCore
from storage.tablemgr import manager
from buffer.bufmgr import buffer_pool
from query.commands.insert import *
from query.commands.select import *
from query.commands.update import *

main_pool = buffer_pool()


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),
        );
        """)
示例#11
0
 def replaceControl(self, page):
     bfm = buffer_pool()
     readvals = bfm.findPage(page)
     if readvals == -1:
         bfm.replacePage(page)
     return bfm.findPage(page)
示例#12
0
__author__ = 'Bernardo Godinho - @bernardogo'

from query.evaluator import evaluator
from storage.io import general
from catalog.core import catalogCore
from storage.tablemgr import manager
from buffer.bufmgr import buffer_pool
from query.commands.insert import *
from query.commands.select import *
from query.commands.update import *

main_pool = buffer_pool()

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),
        );