Skip to content

Commit cd78634

Browse files
committed
complete functions
1 parent d8984cc commit cd78634

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
applicationId "br.com.sql"
88
minSdkVersion 15
99
targetSdkVersion 29
10-
versionCode 17
11-
versionName "1.0.16"
10+
versionCode 18
11+
versionName "1.0.17"
1212
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1313
}
1414
buildTypes {

simplesql/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
defaultConfig {
88
minSdkVersion 11
99
targetSdkVersion 29
10-
versionCode 1
11-
versionName "1.0.0"
10+
versionCode 18
11+
versionName "1.0.17"
1212

1313
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1414
consumerProguardFiles 'consumer-rules.pro'

simplesql/src/main/java/com/simplesql/simplesql/config/SimpleSQL.java

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,21 @@ public Select selectSingle(Object typeObject) {
3838
}
3939

4040
/**
41-
* incompleto
41+
* COUNT(campo)
4242
*/
4343
public Select selectCount(Object typeObject) {
4444
return new Select(typeObject, "COUNT");
4545
}
4646

4747
/**
48-
* incompleto
48+
* MAX(campo)
4949
*/
5050
public Select selectMax(Object typeObject) {
5151
return new Select(typeObject, "MAX");
5252
}
5353

5454
/**
55-
* incompleto
55+
* MIN(campo)
5656
*/
5757
public Select selectMin(Object typeObject) {
5858
return new Select(typeObject, "MIN");
@@ -76,12 +76,13 @@ public Insert insert(Object o) {
7676
* Method SELECT
7777
*/
7878
public class Select {
79-
private String tableName, field, writeSQL, column, table;
79+
private String tableName, field, writeSQL, column, table, columnFunction;
8080
private String[] fields;
81-
private boolean where, equals, between, or, on, and, like, innerJoin, leftJoin, rightJoin, fullJoin;
81+
private boolean where, equals, between, or, on, and, like, innerJoin, leftJoin, rightJoin, fullJoin, functionParameter;
8282
private Object value;
8383
private String SQLString;
8484
private Object typeObject;
85+
private static final String KEY_FUNCTION_PARAMETER = "%column";
8586

8687
/**
8788
* @param typeObject
@@ -92,16 +93,20 @@ public Select(Object typeObject, String type) {
9293
this.typeObject = typeObject;
9394
switch (type) {
9495
case "COUNT":
95-
SQLString = "SELECT COUNT(*)";
96+
SQLString = "SELECT COUNT(" + KEY_FUNCTION_PARAMETER + ")";
97+
this.functionParameter = true;
9698
break;
9799
case "SINGLE":
98100
SQLString = "SELECT SINGLE ";
101+
this.functionParameter = true;
99102
break;
100103
case "MAX":
101-
SQLString = "SELECT MAX(*)";
104+
SQLString = "SELECT MAX(" + KEY_FUNCTION_PARAMETER + ")";
105+
this.functionParameter = true;
102106
break;
103107
case "MIN":
104-
SQLString = "SELECT MIN(*)";
108+
SQLString = "SELECT MIN(" + KEY_FUNCTION_PARAMETER + ")";
109+
this.functionParameter = true;
105110
break;
106111
default:
107112
SQLString = "SELECT ";
@@ -117,8 +122,13 @@ public Select column(String column) {
117122
return this;
118123
}
119124

125+
public Select functionParameter(String column) {
126+
this.columnFunction = column;
127+
return this;
128+
}
129+
120130
public Select limit(int number) {
121-
SQLString = SQLString + " LIMIT " + value;
131+
SQLString = SQLString + " LIMIT " + number;
122132
return this;
123133
}
124134

@@ -130,7 +140,7 @@ public SimpleSQL.Select fields(String[] fields) {
130140

131141
public Select fieldString(String value) {
132142
this.field = field;
133-
SQLString = SQLString + value;
143+
SQLString = SQLString + "'" + value + "'";
134144
return this;
135145
}
136146

@@ -241,6 +251,9 @@ public Select like() {
241251

242252
public List execute() {
243253
SQLiteDatabase read = helperBD.getReadableDatabase();
254+
if (functionParameter) {
255+
SQLString.replace(KEY_FUNCTION_PARAMETER, columnFunction);
256+
}
244257
SQLString = SQLString + ";";
245258
List lstClasses = new ArrayList<>();
246259
Field[] fields = typeObject.getClass().getDeclaredFields();

0 commit comments

Comments
 (0)