Skip to content

Commit b2907ad

Browse files
committed
update insert
1 parent 59c233e commit b2907ad

5 files changed

Lines changed: 103 additions & 8 deletions

File tree

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package br.com.sql;
2+
3+
import com.simplesql.simplesql.annotations.AutoIncrement;
4+
import com.simplesql.simplesql.annotations.Column;
5+
import com.simplesql.simplesql.annotations.ForeignKey;
6+
import com.simplesql.simplesql.annotations.Key;
7+
import com.simplesql.simplesql.annotations.Table;
8+
9+
import java.io.Serializable;
10+
11+
@Table
12+
public class Categoria implements Serializable {
13+
14+
@Column(type = "INTEGER")
15+
@AutoIncrement()
16+
@Key
17+
private int id;
18+
19+
@Column(type = "INTEGER",non_null = true)
20+
private long idCnpj;
21+
22+
@Column(type = "TEXT",non_null = true)
23+
private String nome;
24+
25+
@Column(type = "BLOB",non_null = true)
26+
private byte[] img;
27+
28+
@Column(type = "DECIMAL",non_null = true)
29+
private float valor;
30+
31+
@Column(type = "INTEGER",non_null = true)
32+
private short value;
33+
34+
public Categoria() {
35+
}
36+
37+
public long getIdCnpj() {
38+
return idCnpj;
39+
}
40+
41+
public void setIdCnpj(long idCnpj) {
42+
this.idCnpj = idCnpj;
43+
}
44+
45+
public String getNome() {
46+
return nome;
47+
}
48+
49+
public void setNome(String nome) {
50+
this.nome = nome;
51+
}
52+
53+
public int getId() {
54+
return id;
55+
}
56+
57+
public void setId(int id) {
58+
this.id = id;
59+
}
60+
61+
public byte[] getImg() {
62+
return img;
63+
}
64+
65+
public void setImg(byte[] img) {
66+
this.img = img;
67+
}
68+
69+
public float getValor() {
70+
return valor;
71+
}
72+
73+
public void setValor(float valor) {
74+
this.valor = valor;
75+
}
76+
77+
public short getValue() {
78+
return value;
79+
}
80+
81+
public void setValue(short value) {
82+
this.value = value;
83+
}
84+
}

app/src/main/java/br/com/sql/Example.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,18 @@ protected void onCreate(Bundle savedInstanceState) {
1616
super.onCreate(savedInstanceState);
1717
setContentView(R.layout.activity_example);
1818
SimpleSQL simpleSQL = new SimpleSQL(new HelperBD(this));
19-
Pessoa pessoa = new Pessoa();
20-
pessoa.setName("paulo");
21-
simpleSQL.insert(pessoa).execute(pessoa);
19+
// Pessoa pessoa = new Pessoa();
20+
// pessoa.setName("paulo");
21+
// simpleSQL.insert(pessoa).execute();
22+
//
23+
Categoria categoria = new Categoria();
24+
categoria.setIdCnpj(999999999);
25+
categoria.setNome("Teste");
26+
categoria.setImg(new byte[]{21,31,31});
27+
categoria.setValor(1f);
28+
categoria.setValue((short) 100);
29+
simpleSQL.insert(categoria).execute();
30+
2231

2332
List<Pessoa> list = simpleSQL.selectTable(new Pessoa())
2433
.fields(new String[]{"name"})

app/src/main/java/br/com/sql/HelperBD.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
public class HelperBD extends SQLiteOpenHelper {
1818
private static final String NAME = "nome_banco.bd";
19-
private static final int VERSION = 11;
19+
private static final int VERSION = 13;
2020
private SimpleSQL simpleSQL;
2121

2222
public HelperBD(@Nullable Context context) {

app/src/main/java/br/com/sql/Pessoa.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public class Pessoa {
1515
@Column(type = "TEXT")
1616
private String name;
1717

18+
19+
1820
public int getId() {
1921
return id;
2022
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -515,15 +515,15 @@ private void checkObject(Field field, Object obj) {
515515
try {
516516
if (field.get(obj).getClass() == String.class)
517517
values.put(field.getName(), (String) field.get(obj));
518-
else if (field.get(obj).getClass() == long.class)
518+
else if (field.get(obj).getClass() == Long.class)
519519
values.put(field.getName(), (long) field.get(obj));
520-
else if (field.get(obj).getClass() == float.class)
520+
else if (field.get(obj).getClass() == Float.class)
521521
values.put(field.getName(), (float) field.get(obj));
522522
else if (field.get(obj).getClass() == byte[].class)
523523
values.put(field.getName(), (byte[]) field.get(obj));
524-
else if (field.get(obj).getClass() == int.class)
524+
else if (field.get(obj).getClass() == Integer.class)
525525
values.put(field.getName(), (int) field.get(obj));
526-
else if (field.get(obj).getClass() == short.class)
526+
else if (field.get(obj).getClass() == Short.class)
527527
values.put(field.getName(), (short) field.get(obj));
528528
} catch (IllegalAccessException e) {
529529
e.printStackTrace();

0 commit comments

Comments
 (0)