@@ -85,7 +85,8 @@ public class Select {
8585 private String SQLString ;
8686 private Object typeObject ;
8787 private static final String KEY_FUNCTION_PARAMETER = "%column" ;
88-
88+ private static final String KEY_COLIMN_NAME_MAX = "value_function" ;
89+ private String type ;
8990 /**
9091 * @param typeObject
9192 * @param type
@@ -103,7 +104,7 @@ public Select(Object typeObject, String type) {
103104 this .functionParameter = true ;
104105 break ;
105106 case "MAX" :
106- SQLString = "SELECT MAX(" + KEY_FUNCTION_PARAMETER + ")" ;
107+ SQLString = "SELECT MAX(" + KEY_FUNCTION_PARAMETER + ") INTO " + KEY_COLIMN_NAME_MAX ;
107108 this .functionParameter = true ;
108109 break ;
109110 case "MIN" :
@@ -113,8 +114,8 @@ public Select(Object typeObject, String type) {
113114 default :
114115 SQLString = "SELECT " ;
115116
116-
117117 }
118+ this .type = type ;
118119 }
119120
120121
@@ -246,19 +247,38 @@ public Select like() {
246247 return this ;
247248 }
248249
249- public List execute () {
250+ public Object execute () {
250251 SQLiteDatabase read = helperBD .getReadableDatabase ();
251252 if (functionParameter ) {
252253 if (fields [0 ] == null || fields [0 ].equals ("" ))
253254 columnFunction = "*" ;
254- SQLString = SQLString .replace ("*" , "" ).replace (KEY_FUNCTION_PARAMETER , fields [0 ]);
255+ SQLString = SQLString .replace (fields [ 0 ], "" ).replace (KEY_FUNCTION_PARAMETER , ( CharSequence ) getString ( fields [0 ]) );
255256 }
256257 SQLString = SQLString + ";" ;
257258 List lstClasses = new ArrayList <>();
258259 Field [] fields = typeObject .getClass ().getDeclaredFields ();
259260 HashMap <String , Object > hashMap = new HashMap <>();
260261 try {
261- Cursor cursor = read .rawQuery (SQLString , null );
262+ Cursor cursor = read .rawQuery (SQLString , null );
263+ if (type .equals ("COUNT" )){
264+ cursor .moveToFirst ();
265+ return cursor .getInt (0 );
266+ }else if (type .equals ("MAX" ) || type .equals ("MIN" )){
267+ if (cursor !=null ){
268+ cursor .moveToFirst ();
269+ while (!cursor .isAfterLast ()) {
270+ for (Field f : fields ) {
271+ Object object = checkItem (f , cursor );
272+ if (object != null )
273+ hashMap .put (f .getName (), object );
274+ }
275+ String hashJson = new Gson ().toJson (hashMap );
276+ lstClasses .add (new Gson ().fromJson (hashJson , (Type ) typeObject .getClass ()));
277+ }
278+ }
279+ cursor .close ();
280+ return lstClasses ;
281+ }
262282 while (cursor .moveToNext ()) {
263283 for (Field f : fields ) {
264284 Object object = checkItem (f , cursor );
@@ -453,7 +473,7 @@ public boolean execute() {
453473 }
454474
455475 public Object getString (String string ) {
456- String s = "A;B;C;D;E;F;G;H;I;J;K;L;M;N;O;P;Q;R;S;T;U;V;W;X;Y;Z;a;b;c;d;d;e;f;g;h;i;j;k;l;m;n;o;p;q;r;s;t;u;v;w;x;y;z;\\ ;\\ " ;
476+ String s = "A;B;C;D;E;F;G;H;I;J;K;L;M;N;O;P;Q;R;S;T;U;V;W;X;Y;Z;a;b;c;d;d;e;f;g;h;i;j;k;l;m;n;o;p;q;r;s;t;u;v;w;x;y;z;\\ ;\\ * " ;
457477 String [] arrays = s .split (";" );
458478 for (String array : arrays ) {
459479 if (string .contains (array )) {
0 commit comments