Пример #1
0
def bin(leftExpr, binaryOp, rightExpr):
    c = Context(namespace=Names.Expression.BinaryOperator)
    res1, res2 = convert(leftExpr, rightExpr)
    c.varBinaryLeft = str(res1)
    c.varBinaryRight = str(res2)
    c.varBinaryOperator = binaryOp
    return c
Пример #2
0
    def sql(self):
        
        context = Context(namespace=Names.Update)
        context.varTableName = self.model.Name
        
        def gene():
            nonlocal context
            assert len(self._fields)
             
            if self._where:
                context.varWhereExpr = str(self._where)

            for field, expr in self._fields:
                c = Context(namespace=Names.Update.ColumnsLevel)
                c.varColumnName = field.Name
                c.varColumnUpdateExpr = expr
                context.level(c)

            return self.builder.build(context)
        
        if self._instances: 
            for model_inst in self._instances:
                if not self.only_fields:
                    self._fields = list(zip(self.model, model_inst.storage_values()))
                else:
                    self._fields = [(x, model_inst.storage_value(x)) for x in self.only_fields]
                value = model_inst.value(self.model.PrimaryKey())
                assert value != None, "Не указано значение первичного ключа для обновления!"
                self._where = self.model.PrimaryKey() == value
                yield gene()
        else:
            yield gene()
Пример #3
0
 def test_context(self):
     a = Context(namespace=Names.Create)
     a.flagTemp = True
     a.varDatabaseName = "test"
     def fail_test():
         nonlocal a
         a.varDatabaseName = 123
     self.assertRaises(ValueError, fail_test)
Пример #4
0
 def field(self, model, field):
     
     c = Context(namespace=Names.Create.ColumnsLevel)
     c.varColumnName = field.Name
     c.varColumnType = field.StorageType
     
     for feature in field.features:
         feature.createHook(self, field, c)  
             
     return c   
Пример #5
0
        def gene():
            nonlocal context
            assert len(self._fields)
             
            if self._where:
                context.varWhereExpr = str(self._where)

            for field, expr in self._fields:
                c = Context(namespace=Names.Update.ColumnsLevel)
                c.varColumnName = field.Name
                c.varColumnUpdateExpr = expr
                context.level(c)

            return self.builder.build(context)
Пример #6
0
    def sql(self):
        table = self.model.Name
        context = Context(namespace=Names.Select)
        context.varSelectTable = table
        if self._where:
            context.varWhereExpr = str(self._where)

        if self._fields:
            names = [f.name for f in self._fields]
            for name in names:
                c = Context(namespace=Names.Select.ColumnsLevel)
                c.varTableName = table
                c.varColumnName = name
                context.level(c)

        return self.builder.build(context)
Пример #7
0
def like(leftExpr, rightExpr, reverse=False, match=False):
    c = Context(namespace=Names.Expression.Like)
    c.varLikeLeft = str(leftExpr)
    c.varLikeRight = str(rightExpr)
    if reverse:
        c.flagReverse = True
    if not match:
        c.flagLike = True
    else:
        c.flagMatch = True
    return c
Пример #8
0
    def sql(self):
        
        context = Context(namespace=Names.Insert)
        context.varTableName = self.model.Name
        
        for instance in self.models:

            for name, value in instance.storage_items():
                c = Context(namespace=Names.Insert.ValuesLevel)
                c.varValue = value
                field = instance[name]                      
                for feature in field.features:
                    feature.insertHook(self, instance, field , c)
                context.level(c)

            yield self.builder.build(context)
Пример #9
0
 def sql(self):        
     context = Context(namespace=Names.Create)
     context.varTableName = self.model.Name
     for field in self.model:
         context.level(self.field(self.model, field))            
     return self.builder.build(context)
Пример #10
0
 def sql(self):
     context = Context(namespace=Names.Delete)
     assert self._where
     context.varTableName = self.model.Name
     context.varWhereExpr = str(self._where)
     return self.builder.build(context)