|
@@ -58,12 +58,19 @@ def get(arg=None): |
|
|
|
|
|
|
|
|
if not data.get('order_by'): |
|
|
if not data.get('order_by'): |
|
|
data['order_by'] = tables[0] + '.modified desc' |
|
|
data['order_by'] = tables[0] + '.modified desc' |
|
|
|
|
|
|
|
|
|
|
|
if len(tables) > 1: |
|
|
|
|
|
data['group_by'] = "group by " + tables[0] + ".name" |
|
|
|
|
|
else: |
|
|
|
|
|
data['group_by'] = '' |
|
|
|
|
|
|
|
|
check_sort_by_table(data.get('order_by'), tables) |
|
|
check_sort_by_table(data.get('order_by'), tables) |
|
|
|
|
|
|
|
|
add_limit(data) |
|
|
add_limit(data) |
|
|
|
|
|
|
|
|
query = """select %(fields)s from %(tables)s where %(conditions)s |
|
|
query = """select %(fields)s from %(tables)s where %(conditions)s |
|
|
order by %(order_by)s %(limit)s""" % data |
|
|
|
|
|
|
|
|
%(group_by)s order by %(order_by)s %(limit)s""" % data |
|
|
|
|
|
|
|
|
return webnotes.conn.sql(query, as_dict=1) |
|
|
return webnotes.conn.sql(query, as_dict=1) |
|
|
|
|
|
|
|
|
def check_sort_by_table(sort_by, tables): |
|
|
def check_sort_by_table(sort_by, tables): |
|
@@ -132,7 +139,7 @@ def build_conditions(filters): |
|
|
|
|
|
|
|
|
# match conditions |
|
|
# match conditions |
|
|
build_match_conditions(data, conditions) |
|
|
build_match_conditions(data, conditions) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return conditions |
|
|
return conditions |
|
|
|
|
|
|
|
|
def build_filter_conditions(data, filters, conditions): |
|
|
def build_filter_conditions(data, filters, conditions): |
|
@@ -175,6 +182,8 @@ def get_tables(): |
|
|
# add tables from fields |
|
|
# add tables from fields |
|
|
for f in json.loads(data['fields']): |
|
|
for f in json.loads(data['fields']): |
|
|
table_name = f.split('.')[0] |
|
|
table_name = f.split('.')[0] |
|
|
|
|
|
if table_name.lower().startswith('group_concat('): |
|
|
|
|
|
table_name = table_name[13:] |
|
|
# check if ifnull function is used |
|
|
# check if ifnull function is used |
|
|
if table_name.lower().startswith('ifnull('): |
|
|
if table_name.lower().startswith('ifnull('): |
|
|
table_name = table_name[7:] |
|
|
table_name = table_name[7:] |
|
|