@@ -4824,7 +4824,8 @@ this.recline.View = this.recline.View || {};
48244824 . find ( ".extract-data-input" )
48254825 . val ( JSON . stringify ( query ) ) ;
48264826
4827- var sql_query = this . jsQueryToSQL ( query ) ;
4827+ var model_fields = self . model . fields ;
4828+ var sql_query = this . jsQueryToSQL ( query , model_fields ) ;
48284829 this . extractFile ( self , sql_query , format ) ;
48294830 } ,
48304831 extractFile : function ( self , sql_query , format ) {
@@ -4972,7 +4973,7 @@ this.recline.View = this.recline.View || {};
49724973 modal . style . display = "none" ;
49734974 } ;
49744975 } ,
4975- jsQueryToSQL : function ( query_obj ) {
4976+ jsQueryToSQL : function ( query_obj , model_fields ) {
49764977 let query = "" ;
49774978 let distinct = "" ;
49784979
@@ -4996,7 +4997,7 @@ this.recline.View = this.recline.View || {};
49964997 query += ` FROM \`${ query_obj [ "resource_id" ] } \` ` ;
49974998
49984999 if ( "filters" || "q" in query_obj ) {
4999- let where_str = this . where_clauses ( query_obj [ "fields" ] , query_obj ) ;
5000+ let where_str = this . where_clauses ( query_obj [ "fields" ] , query_obj , model_fields ) ;
50005001 query += ` ${ where_str } ` ;
50015002 }
50025003 if ( "sort" in query_obj ) {
@@ -5009,7 +5010,7 @@ this.recline.View = this.recline.View || {};
50095010 }
50105011 return query ;
50115012 } ,
5012- where_clauses : function ( fields , query_obj ) {
5013+ where_clauses : function ( fields , query_obj , model_fields ) {
50135014 let filters = query_obj [ "filters" ] ;
50145015 let q = query_obj [ "q" ] ;
50155016 let where_str = "" ;
@@ -5021,7 +5022,7 @@ this.recline.View = this.recline.View || {};
50215022 for ( const [ key , value ] of Object . entries ( filters ) ) {
50225023 let single_where_statament = "" ;
50235024 value . forEach ( ( value_item ) => {
5024- if ( this . get_field_type ( value_item ) == "num" ) {
5025+ if ( this . get_field_type ( key , value_item , model_fields ) == "num" ) {
50255026 single_where_statament += `${ key } = ${ value_item } OR ` ;
50265027 } else {
50275028 single_where_statament += `${ key } = "${ value_item } " OR ` ;
@@ -5036,7 +5037,7 @@ this.recline.View = this.recline.View || {};
50365037 if ( q != "" ) {
50375038 let where_q = " WHERE " ;
50385039 for ( const [ key , value ] of Object . entries ( filters ) ) {
5039- if ( this . get_field_type ( value ) == "string" ) {
5040+ if ( this . get_field_type ( key , value , model_fields ) == "string" ) {
50405041 where_q_str += ` LOWER(${ key } ) like LOWER("${ value . slice (
50415042 0 ,
50425043 - 2
@@ -5053,9 +5054,14 @@ this.recline.View = this.recline.View || {};
50535054 }
50545055 return where_str ;
50555056 } ,
5056- get_field_type : function ( value ) {
5057-
5058- if ( typeof value === "number" ) {
5057+ get_field_type : function ( key , value , model_fields ) {
5058+ var num_types = [ "number" , "NUMBER" ,
5059+ "integer" , "INTEGER" ,
5060+ "bigint" , "BIGINT" ] ;
5061+
5062+ var type = model_fields . get ( key ) . attributes . type
5063+
5064+ if ( num_types . includes ( type ) ) {
50595065 return "num" ;
50605066 } else {
50615067 return "string" ;
0 commit comments