Ejemplo n.º 1
0
    def get_seller_categories(self, seller_id, if_modified_since, check):
        resp = {}

        if not if_modified_since.isdigit():
            resp["status"] = REQUEST_PARAM_ERROR
            return json.dumps(resp, ensure_ascii=False)
        if_modified_since = int(if_modified_since)

        check = int(check)

        where = "WHERE %s=%s" % (self.entry.COLUMN_NAME_SELLER_ID, seller_id)
        other = "ORDER BY %s" % (self.entry.COLUMN_NAME_MODIFY_TIME)
        rows = mysql.select(self.entry.TABLE_NAME, self.entry.COLUMNS, where, other)
        if rows == None:
            resp["status"] = SERVER_MYSQL_ERROR
            return json.dumps(resp, ensure_ascii=False)

        objects = []
        num = 0
        for r in rows:
            d = {self.entry.COLUMNS[i]: r[i] for i in range(len(self.entry.COLUMNS))}
            if d[self.entry.COLUMN_NAME_MODIFY_TIME] > if_modified_since:
                objects.append(d)
            else:
                num += d[self.entry.COLUMN_NAME_ID]

        resp["status"] = OK if not check or num == check else CHECK_ERROR
        resp["categories"] = objects

        return json.dumps(resp, ensure_ascii=False)
Ejemplo n.º 2
0
    def get_seller_barcodes(self, seller_id, if_modified_since, check):
        resp = {}

        if not if_modified_since.isdigit():
            resp['status'] = REQUEST_PARAM_ERROR
            return json.dumps(resp, ensure_ascii=False)
        if_modified_since = int(if_modified_since)

        where = "WHERE %s='%s'" % (self.entry.COLUMN_NAME_SELLER_ID, seller_id)
        other = "ORDER BY %s" % (self.entry.COLUMN_NAME_MODIFY_TIME)
        rows = mysql.select(self.entry.TABLE_NAME, self.entry.COLUMNS, where,
                            other)
        if rows == None:
            resp['status'] = SERVER_MYSQL_ERROR
            return json.dumps(resp, ensure_ascii=False)

        objects = []
        num = 0
        for r in rows:
            d = {
                self.entry.COLUMNS[i]: r[i]
                for i in range(len(self.entry.COLUMNS))
            }
            if d[self.entry.COLUMN_NAME_MODIFY_TIME] > if_modified_since:
                objects.append(d)
            else:
                num += d[self.entry.COLUMN_NAME_ID]

        resp['status'] = OK if not check or num == check else CHECK_ERROR
        resp['barcodes'] = objects

        return json.dumps(resp, ensure_ascii=False)
Ejemplo n.º 3
0
    def get_area_sellers(self, area):
        resp = {}

        columns = [SellerServiceAreaEntry.COLUMN_NAME_SELLER_ID]
        where = "WHERE %s='%s'" % (SellerServiceAreaEntry.COLUMN_NAME_AREA, area) 
        rows = get_instance().select(SellerServiceAreaEntry.TABLE_NAME, columns, where)
        if rows == None:
            resp['status'] = SERVER_MYSQL_ERROR
            return json.dumps(resp, ensure_ascii=False)
        ids = set([r[0] for r in rows])
        print ids
        if ids:    
            rows = mysql.select(self.entry.TABLE_NAME, self.entry.COLUMNS, '')
            if rows == None:
                resp['status'] = SERVER_MYSQL_ERROR
                return json.dumps(resp, ensure_ascii=False)
            objects = []
            for r in rows:
                d = {self.entry.COLUMNS[i]:r[i] for i in range(len(self.entry.COLUMNS))}
                if d[self.entry.COLUMN_NAME_ID] in ids:
                    objects.append(d)
        
        resp['status'] = OK
        resp['sellers'] = objects
            
        return json.dumps(resp, ensure_ascii=False)
Ejemplo n.º 4
0
    def get_area_sellers(self, area):
        resp = {}

        columns = [SellerServiceAreaEntry.COLUMN_NAME_SELLER_ID]
        where = "WHERE %s='%s'" % (SellerServiceAreaEntry.COLUMN_NAME_AREA,
                                   area)
        rows = get_instance().select(SellerServiceAreaEntry.TABLE_NAME,
                                     columns, where)
        if rows == None:
            resp['status'] = SERVER_MYSQL_ERROR
            return json.dumps(resp, ensure_ascii=False)
        ids = set([r[0] for r in rows])
        print ids
        if ids:
            rows = mysql.select(self.entry.TABLE_NAME, self.entry.COLUMNS, '')
            if rows == None:
                resp['status'] = SERVER_MYSQL_ERROR
                return json.dumps(resp, ensure_ascii=False)
            objects = []
            for r in rows:
                d = {
                    self.entry.COLUMNS[i]: r[i]
                    for i in range(len(self.entry.COLUMNS))
                }
                if d[self.entry.COLUMN_NAME_ID] in ids:
                    objects.append(d)

        resp['status'] = OK
        resp['sellers'] = objects

        return json.dumps(resp, ensure_ascii=False)
Ejemplo n.º 5
0
 def get(self, id):
     resp = {}
     where = "WHERE %s='%s'" % (self.entry.COLUMN_NAME_ID, id)
     rs = mysql.select(self.entry.TABLE_NAME, self.entry.COLUMNS, where)
     if rs == None or len(rs) != 1:
         resp['status'] = SERVER_MYSQL_ERROR
     else:
         d = {self.entry.COLUMNS[i]:rs[0][i] for i in range(len(self.entry.COLUMNS))}
         resp['status'] = OK
         resp[self.entry.NAME] = d
         
     return json.dumps(resp, ensure_ascii=False)
Ejemplo n.º 6
0
def get_columns(db_name, table_name):
    columns = ["COLUMN_NAME", "DATA_TYPE"]
    where = "where TABLE_SCHEMA='%s' and TABLE_NAME='%s'" % (db_name, table_name)
    rows = mysql.select("INFORMATION_SCHEMA.COLUMNS", columns, where)
    return rows
Ejemplo n.º 7
0
def get_columns(db_name, table_name):
    columns = ['COLUMN_NAME', 'DATA_TYPE', 'COLUMN_KEY']
    where = "where TABLE_SCHEMA='%s' and TABLE_NAME='%s'" % (db_name,
                                                             table_name)
    rows = mysql.select('INFORMATION_SCHEMA.COLUMNS', columns, where)
    return rows
Ejemplo n.º 8
0
def get_columns(db_name, table_name):
    columns = ['COLUMN_NAME']
    where = "where TABLE_SCHEMA='%s' and TABLE_NAME='%s'" % (db_name, table_name)
    rows = mysql.select('INFORMATION_SCHEMA.COLUMNS', columns, where)
    return [x[0] for x in rows]