示例#1
0
 def orderby(self, column):
     list = dt.getTypeFields(self.type)
     if column in list:
         if list[column] == False:
             self.order = column
             return self
         else:
             raise dal.IsList(column)
     else:
         raise dal.FieldNotDefined(column, self.type)
示例#2
0
 def filter(self, *fields):
     list = dt.getTypeFields(self.type)
     for i in fields:
         if i in list:
             if not i in self.fields:
                 if list[i] == False:
                     self.fields[i] = False
                 else:
                     raise dal.IsList(i)
         else:
             raise dal.FieldNotDefined(i, self.type)
     return self
示例#3
0
 def __init__(self, type_name, id=-1):    
     self.fields=[]    
     if id >= 0:
         self.type_name = type_name
         self.id = id
         return
         
     self.type_id = dt.get_type_id(type_name) 
     self.attributes = dt.getTypeFields(self.type_id)
     for i in self.attributes:
         if not self.attributes[i]:
             setattr(self, i, None)
         else: 
             setattr(self, i, [])
     self.table = dals.table_space[dals.composeTableName(type_name)]
     self.__class__.table = dals.table_space[dals.composeTableName(type_name)]
     try:
         o = self.table.insert().execute()
     except Exception as e:
         print e
 
     self.id = o.lastrowid
示例#4
0
 def fetch(self):
     """ El fetch obtindra primerament la llista dels ids que siguin necessaris
      limitara si fos el cas i fara diferents selects per els camps que li demanem.
     Fara una unio de les diferents files empilant tots els objectes amb els camps
     que pertoquin i retornara la llista d'objectes"""
     objs = []
     extrawork = False
     version = 1
     fieldName = str(dt.getTypeName(self.type))
     cls = getattr(dal.object, fieldName)
     if len(self.fields) == 0:
         self.fields = dt.getTypeFields(self.type)
     if self.id != 0:
         """ La crida ve desde una instancia: recuperem nomes els objectes que pertanyen a aquesta instancia"""
         if self.order == None:
             """Si no es vol cap ordre especial sobtenen els registres utilitzan una crida en una de les taules """
             if self.limit == 0 and self.offset != 0:
                 query = select([self.table.c.value]).where(self.table.c.obj_id == self.id).offset(self.offset)
             elif self.limit != 0 and self.offset == 0:
                 query = select([self.table.c.value]).where(self.table.c.obj_id == self.id).limit(self.limit)
             elif self.limit == 0 and self.offset != 0:
                 query = select([self.table.c.value]).where(self.table.c.obj_id == self.id).offset(self.offset)
             else:
                 query = select([self.table.c.value]).where(self.table.c.obj_id == self.id)
         else:
             extrawork = True
             query = select([self.table.c.value]).where(self.table.c.obj_id == self.id)
     else:
         """La crida ve des dun objecte: """
         if self.order != None:
             table = dals.composeTableName(self.type, self.order)
             if self.limit == 0 and self.offset != 0:
                 oQuery = select([table.c.value, table.c.obj_id]).order_by(table.c.value).limit(self.limit)
             elif self.limit != 0 and self.offset == 0:
                 oQuery = (
                     select([table.c.value, table.c.obj_id])
                     .order_by(table.c.value)
                     .offset(self.offset)
                     .limit(self.limit)
                 )
             elif self.limit == 0 and self.offset != 0:
                 oQuery = select([table.c.value, table.c.obj_id]).order_by(table.c.value).offset(self.offset)
             else:
                 oQuery = select([table.c.value, table.c.obj_id]).order_by(table.c.value)
             "aqui creamos una tabla con el orden de los ids"
         else:
             if self.limit == 0 and self.offset != 0:
                 query = select([self.table.c.id]).order_by(self.table.c.id).limit(self.limit)
             elif self.limit != 0 and self.offset == 0:
                 query = select([self.table.c.id]).order_by(self.table.c.id).offset(self.offset).limit(self.limit)
             elif self.limit == 0 and self.offset != 0:
                 query = select([self.table.c.id]).order_by(self.table.c.id).offset(self.offset)
             else:
                 query = select([self.table.c.id]).order_by(self.table.c.id)
             objs = {}
             ids = dals.executeQuery(query).fetchall()
             for i in ids:
                 objs[i["id"]] = cls()
             for nom in self.fields:
                 if not self.fields[nom]:
                     table = dals.composeTableName(self.type, nom)
                     result = dals.executeQuery(
                         select([dals.table_space[table].c.value, dals.table_space[table].c.obj_id]).order_by(
                             dals.table_space[table].c.obj_id
                         )
                     ).fetchall()
                     for row in result:
                         if row["obj_id"] in objs:
                             setattr(objs[row["obj_id"]], nom, row["value"])
                         else:
                             break
             return objs
     result = dals.executeQuery(query).fetchall()
     if version == 1:
         for row in result:
             id_obj = row["value"]
             absObj = cls(id_obj)
             for nom in self.fields:
                 if self.fields[nom] == False:
                     table = dals.composeTableName(self.type, nom)
                     values = dals.executeQuery(
                         select([dals.table_space[table].c.value]).where(dals.table_space[table].c.obj_id == id_obj)
                     ).fetchone()
                     if values != None:
                         setattr(absObj, nom, values["value"])
             objs.append(absObj)
             if extrawork:
                 c = Compare(self.order)
                 objs.sort(c)
     if version == 2:
         for nom in self.fields:
             if nom != self.order & self.fields[nom] == False:
                 values = dals.executeQuery(select([dals.table_space[table].c.value])).fetchall()
                 for value in values:
                     pass
     return objs