Skip to content

Commit 29c0e05

Browse files
committed
add functions in select
1 parent 7b2481a commit 29c0e05

File tree

2 files changed

+57
-10
lines changed

2 files changed

+57
-10
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 16
11-
versionName "1.0.15"
10+
versionCode 17
11+
versionName "1.0.16"
1212
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1313
}
1414
buildTypes {

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

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,44 @@ public SimpleSQL(SQLiteOpenHelper helperBD) {
3030
}
3131

3232
public Select selectTable(Object typeObject) {
33-
return new Select(typeObject);
33+
return new Select(typeObject, "SELECT");
34+
}
35+
36+
public Select selectSingle(Object typeObject) {
37+
return new Select(typeObject, "SINGLE");
38+
}
39+
40+
/**
41+
* incompleto
42+
*/
43+
public Select selectCount(Object typeObject) {
44+
return new Select(typeObject, "COUNT");
45+
}
46+
47+
/**
48+
* incompleto
49+
*/
50+
public Select selectMax(Object typeObject) {
51+
return new Select(typeObject, "MAX");
52+
}
53+
54+
/**
55+
* incompleto
56+
*/
57+
public Select selectMin(Object typeObject) {
58+
return new Select(typeObject, "MIN");
3459
}
3560

3661
public DeleteColumn deleteColumn(Object objectType) {
3762
return new DeleteColumn(objectType);
3863
}
3964

4065

41-
4266
public Update updateTable(Object typeObject) {
4367
return new Update(typeObject);
4468
}
4569

46-
public Insert insert(Object o){
70+
public Insert insert(Object o) {
4771
return new Insert(o);
4872
}
4973

@@ -61,11 +85,29 @@ public class Select {
6185

6286
/**
6387
* @param typeObject
88+
* @param type
6489
*/
65-
public Select(Object typeObject) {
90+
public Select(Object typeObject, String type) {
6691
this.tableName = typeObject.getClass().getSimpleName();
6792
this.typeObject = typeObject;
68-
SQLString = "SELECT ";
93+
switch (type) {
94+
case "COUNT":
95+
SQLString = "SELECT COUNT(*)";
96+
break;
97+
case "SINGLE":
98+
SQLString = "SELECT SINGLE ";
99+
break;
100+
case "MAX":
101+
SQLString = "SELECT MAX(*)";
102+
break;
103+
case "MIN":
104+
SQLString = "SELECT MIN(*)";
105+
break;
106+
default:
107+
SQLString = "SELECT ";
108+
109+
110+
}
69111
}
70112

71113

@@ -75,6 +117,11 @@ public Select column(String column) {
75117
return this;
76118
}
77119

120+
public Select limit(int number) {
121+
SQLString = SQLString + " LIMIT " + value;
122+
return this;
123+
}
124+
78125
public SimpleSQL.Select fields(String[] fields) {
79126
this.fields = fields;
80127
SQLString = SQLString + getFields(fields) + " FROM " + tableName;
@@ -125,6 +172,7 @@ public Select table(String table) {
125172
return this;
126173
}
127174

175+
128176
public Select equals() {
129177
this.equals = true;
130178
SQLString = SQLString + " = ";
@@ -466,7 +514,6 @@ public String create(Object obj, SQLiteDatabase db) {
466514
/**
467515
* Developed by Paulo Iury
468516
* Method INSERT
469-
*
470517
*/
471518
public class Insert {
472519
private Object obj;
@@ -576,7 +623,7 @@ public class DeleteColumn {
576623

577624
public DeleteColumn(Object objectType) {
578625
this.table = objectType.getClass().getSimpleName();
579-
this.SQLString = "DELETE FROM "+table;
626+
this.SQLString = "DELETE FROM " + table;
580627
}
581628

582629
public DeleteColumn equals() {
@@ -605,7 +652,7 @@ public DeleteColumn like(String s) {
605652
}
606653

607654
public DeleteColumn fieldString(String value) {
608-
SQLString += "\""+value+"\"";
655+
SQLString += "\"" + value + "\"";
609656
return this;
610657
}
611658

0 commit comments

Comments
 (0)