예제 #1
0
    def to_sql(self, schema, not_null=False, boolean=False):
        lhs = SQLang[self.lhs].partial_eval()
        rhs = SQLang[self.rhs].partial_eval()
        lhs_sql = lhs.to_sql(schema, not_null=True)
        rhs_sql = rhs.to_sql(schema, not_null=True)
        if is_literal(rhs) and lhs_sql[0].sql.b != None and rhs.value in ("T",
                                                                          "F"):
            rhs_sql = BooleanOp(rhs).to_sql(schema)
        if is_literal(lhs) and rhs_sql[0].sql.b != None and lhs.value in ("T",
                                                                          "F"):
            lhs_sql = BooleanOp(lhs).to_sql(schema)

        if len(lhs_sql) != len(rhs_sql):
            Log.error("lhs and rhs have different dimensionality!?")

        acc = []
        for l, r in zip(lhs_sql, rhs_sql):
            for t in "bsnj":
                if r.sql[t] == None:
                    if l.sql[t] == None:
                        pass
                    else:
                        acc.append(ConcatSQL(l.sql[t], SQL_IS_NULL))
                elif l.sql[t] == None:
                    acc.append(ConcatSQL(r.sql[t], SQL_IS_NULL))
                else:
                    acc.append(
                        ConcatSQL(sql_iso(l.sql[t]), SQL_EQ,
                                  sql_iso(r.sql[t])))
        if not acc:
            return FALSE.to_sql(schema)
        else:
            return wrap([{"name": ".", "sql": {"b": JoinSQL(SQL_OR, acc)}}])
예제 #2
0
 def to_sql(self, schema, not_null=False, boolean=False):
     lhs = self.lhs.to_sql(schema)
     rhs = self.rhs.to_sql(schema)
     acc = []
     if len(lhs) != len(rhs):
         Log.error("lhs and rhs have different dimensionality!?")
     for l, r in zip(lhs, rhs):
         for t in "bsnj":
             if l.sql[t] == None:
                 if r.sql[t] == None:
                     pass
                 else:
                     acc.append(sql_iso(r.sql[t]) + " IS " + SQL_NULL)
             else:
                 if r.sql[t] == None:
                     acc.append(sql_iso(l.sql[t]) + " IS " + SQL_NULL)
                 else:
                     acc.append("(" + sql_iso(l.sql[t]) + " = " +
                                sql_iso(r.sql[t]) + " OR (" +
                                sql_iso(l.sql[t]) + " IS" + SQL_NULL +
                                SQL_AND + "(" + r.sql[t] + ") IS NULL))")
     if not acc:
         return FALSE.to_sql(schema)
     else:
         return wrap([{"name": ".", "sql": {"b": SQL_OR.join(acc)}}])
예제 #3
0
 def to_sql(self, schema, not_null=False, boolean=False):
     term = SQLang[self.term].partial_eval()
     if term.type == "boolean":
         sql = term.to_sql(schema)
         return sql
     elif is_literal(term) and term.value in ('T', 'F'):
         if term.value == 'T':
             return TRUE.to_sql(schema)
         else:
             return FALSE.to_sql(schema)
     else:
         sql = term.exists().partial_eval().to_sql(schema)
         return sql
예제 #4
0
    def to_sql(self, schema, not_null=False, boolean=False):
        lhs = SQLang[self.lhs].to_sql(schema)
        rhs = SQLang[self.rhs].to_sql(schema)
        acc = []
        if len(lhs) != len(rhs):
            Log.error("lhs and rhs have different dimensionality!?")

        for l, r in zip(lhs, rhs):
            for t in "bsnj":
                if l.sql[t] == None:
                    if r.sql[t] == None:
                        pass
                    else:
                        acc.append(sql_iso(r.sql[t]) + SQL_IS_NULL)
                elif l.sql[t] is ZERO:
                    if r.sql[t] == None:
                        acc.append(SQL_FALSE)
                    elif r.sql[t] is ZERO:
                        Log.error(
                            "Expecting expression to have been simplified already"
                        )
                    else:
                        acc.append(r.sql[t])
                else:
                    if r.sql[t] == None:
                        acc.append(sql_iso(l.sql[t]) + SQL_IS_NULL)
                    elif r.sql[t] is ZERO:
                        acc.append(l.sql[t])
                    else:
                        acc.append(
                            sql_iso(l.sql[t]) + SQL_EQ + sql_iso(r.sql[t]))
        if not acc:
            return FALSE.to_sql(schema)
        else:
            return SQLScript(
                expr=SQL_OR.join(acc),
                frum=self,
                data_type=BOOLEAN,
                miss=FALSE,
                schema=schema,
            )