예제 #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
    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
예제 #3
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))
예제 #4
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))
예제 #5
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))
예제 #6
0
    def selection(self, table, values):
        ctlg = catalogCore()
        ctlg.loadCatalog(table)
        pgmg = pageManager()
        io_s = general()
        print("Values not verified.")

        pgmg.readValues(table)
예제 #7
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
예제 #8
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
예제 #9
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")
예제 #10
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")
예제 #11
0
    def execute(self, query):
        if ("create table") in query:
            createTbl = r"(?:\s*)create table(?:\s*)(.*?)(?:\s*)\((?:\s*)(.*?)\);"
            groups =  re.findall(createTbl, query, re.S)
            print ("----->" + str(groups))
            attribsre = r"((?:.*?) (?:.*?),(?:\s*))"
            attribs = re.findall(attribsre, groups[0][1], re.S)
            print ("----->" + str(attribs))
            ctrl = catalogCore()
            ctrl.newCatalog(groups[0][0])
            for x in attribs:
                attr = x.split(" ")
                ctrl.insertAttr(attr[0], attr[1].replace(",", "").replace("\n", ""))

            ctrl.commitCatalog()
예제 #12
0
    def execute(self, query):
        if ("create table") in query:
            createTbl = r"(?:\s*)create table(?:\s*)(.*?)(?:\s*)\((?:\s*)(.*?)\);"
            groups = re.findall(createTbl, query, re.S)
            print("----->" + str(groups))
            attribsre = r"((?:.*?) (?:.*?),(?:\s*))"
            attribs = re.findall(attribsre, groups[0][1], re.S)
            print("----->" + str(attribs))
            ctrl = catalogCore()
            ctrl.newCatalog(groups[0][0])
            for x in attribs:
                attr = x.split(" ")
                ctrl.insertAttr(attr[0], attr[1].replace(",",
                                                         "").replace("\n", ""))

            ctrl.commitCatalog()
예제 #13
0
파일: main.py 프로젝트: BernardoGO/test
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()

from query.commands.insert import *
from query.commands.select import *

ins = insert()
#ins.insertRecord("students2", ["24", "terce321iro"])

sel = select()
sel.selection("students2", [])
예제 #14
0
 def createTable(self, name, attrs):
     ctlg = catalogCore()
     ctlg.tableName = name
     for x in attrs:
         ctlg.insertAttr(x[0], x[1])
     ctlg.commitCatalog()
예제 #15
0

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()

from query.commands.insert import *
from query.commands.select import *

ins = insert()
#ins.insertRecord("students2", ["24", "terce321iro"])

sel = select()
sel.selection("students2", [])
예제 #16
0
 def createTable(self, name, attrs):
     ctlg = catalogCore()
     ctlg.tableName = name
     for x in attrs:
         ctlg.insertAttr(x[0], x[1])
     ctlg.commitCatalog()