Пример #1
0
def whereFormat(in_dict):
    first = True
    whereDict = sqldict.flatDict(in_dict['where'])
    alias = in_dict['alias']
    wherelist = []
    for key, value in whereDict.items():
        if type(value) in [tuple, list]:
            key = sqldict.seq2sqlColumn(key)
        elif type(value) is bool:
            value = int(value)
        elif isinstance(value, newdict.AnyObject):
            key = sqldict.object2sqlColumn(key)
            value = cPickle.dumps(value.o, cPickle.HIGHEST_PROTOCOL)
        evalue = str(value)
        if key == "DEF_timelimit":
            #       For MySQL 4.1.1 or greater
            #       sqlwhere = ''' %s.%s >= ADDTIME(NOW(), '%s') ''' % (backquote(alias), backquote('DEF_timestamp'), evalue)
            parts = evalue.split('\t')
            if len(parts) == 1:
                evalue = parts[0]
                sqlwhere = '''%s.%s >= DATE_ADD(now(), INTERVAL '%s' DAY_SECOND) ''' % (
                    backquote(alias), backquote('DEF_timestamp'), evalue)
            elif len(parts) == 2:
                mintime, maxtime = parts
                sqlwhere = '''%s.%s BETWEEN %s AND %s''' % (backquote(
                    alias), backquote('DEF_timestamp'), mintime, maxtime)
        else:
            sqlwhere = ''' %s.%s="%s" ''' % (backquote(alias), backquote(key),
                                             evalue)
        wherelist.append(sqlwhere)
    wherestr = ' AND '.join(wherelist)
    return wherestr
def whereFormat(in_dict):
        first = True
        whereDict = sqldict.flatDict(in_dict['where'])
        alias = in_dict['alias']
        wherelist = []
        for key, value in whereDict.items():
                if type(value) in [tuple, list]:
                        key = sqldict.seq2sqlColumn(key)
                elif type(value) is bool:
                        value = int(value)
                elif isinstance(value,newdict.AnyObject):
                        key = sqldict.object2sqlColumn(key)
                        value = cPickle.dumps(value.o, cPickle.HIGHEST_PROTOCOL)
                evalue = str(value)
                if key=="DEF_timelimit":
                #       For MySQL 4.1.1 or greater
                #       sqlwhere = ''' %s.%s >= ADDTIME(NOW(), '%s') ''' % (backquote(alias), backquote('DEF_timestamp'), evalue)
                        parts = evalue.split('\t')
                        if len(parts) == 1:
                                evalue = parts[0]
                                sqlwhere = '''%s.%s >= DATE_ADD(now(), INTERVAL '%s' DAY_SECOND) ''' % (backquote(alias), backquote('DEF_timestamp'), evalue)
                        elif len(parts) == 2:
                                mintime,maxtime = parts
                                sqlwhere = '''%s.%s BETWEEN %s AND %s''' % (backquote(alias), backquote('DEF_timestamp'), mintime, maxtime)
                else:
                        sqlwhere = ''' %s.%s="%s" ''' % (backquote(alias), backquote(key), evalue)
                wherelist.append(sqlwhere)
        wherestr = ' AND '.join(wherelist)
        return wherestr
Пример #3
0
def whereFormatSimple(in_dict):
    first = True
    whereDict = sqldict.flatDict(in_dict)
    wherelist = []
    for key, value in whereDict.items():
        if type(value) in [tuple, list]:
            key = sqldict.seq2sqlColumn(key)
        elif isinstance(value, newdict.AnyObject):
            key = sqldict.object2sqlColumn(key)
        evalue = str(value)
        wherelist.append(''' %s="%s" ''' % (backquote(key), evalue))
    wherestr = ' AND '.join(wherelist)
    return wherestr
def whereFormatSimple(in_dict):
        first = True
        whereDict = sqldict.flatDict(in_dict)
        wherelist = []
        for key, value in whereDict.items():
                if type(value) in [tuple, list]:
                        key = sqldict.seq2sqlColumn(key)
                elif isinstance(value,newdict.AnyObject):
                        key = sqldict.object2sqlColumn(key)
                evalue = str(value)
                wherelist.append(''' %s="%s" ''' % (backquote(key), evalue))
        wherestr = ' AND '.join(wherelist)
        return wherestr