Skip to content

Commit 0bf32d0

Browse files
committed
added Constraints methods
1 parent 44be67f commit 0bf32d0

22 files changed

+353
-57
lines changed

.gradle/4.1/fileHashes/fileHashes.bin

350 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
9.64 KB
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

.idea/workspace.xml

Lines changed: 288 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ allprojects {
1414
Add the dependency
1515
```
1616
dependencies {
17-
implementation 'com.github.p32929:AndroidEasySQL-Library:1.2'
17+
implementation 'com.github.p32929:AndroidEasySQL-Library:1.3'
1818
}
1919
```
2020

@@ -35,20 +35,23 @@ After that you can do:
3535
## Code example
3636
### Initialization, Set Table Name, Add columns, altogether:
3737
```
38-
EasyDB easyDB = EasyDB.init(this, "TEST", null, 1)
39-
.setTableName("DEMO TABLE") // You can ignore this line if you want :D
40-
.addColumn(new Column("C1", DataType.TEXT))
41-
.addColumn(new Column("C2", DataType.TEXT))
42-
.addColumn(new Column("C3", DataType.TEXT))
38+
EasyDB easyDB = EasyDB.init(this, "TEST", null, 1) // TEST is the name of the DATABASE
39+
.setTableName("DEMO TABLE") // You can ignore this line if you want
40+
.addColumn(new Column("C1", new DataType()._text_().unique().done()))
41+
.addColumn(new Column("C2", new DataType()._text_().notNull().done()))
42+
.addColumn(new Column("C3", new DataType()._text_().done()))
4343
.doneTableColumn();
4444
```
45+
46+
You can add as many constraint methods like ```unique()``` , ```notNull()``` etc. Just, don't forget to call the ```done()``` method at the end. See the example above...
47+
4548
> addColumn(column)
4649
4750
> Column(columnName, dataType)
4851
49-
saving the object into a variable will make easier to work with the database later.
52+
** Saving the object into a variable will make easier to work with the database later. **
5053

51-
** You don't have to add any primary key. The library does it by default **
54+
** You don't have to add any primary key. The library does it by default (as ```ID``` column) **
5255

5356
### Adding data:
5457
You can call the ```addData()``` in two ways:
@@ -57,9 +60,9 @@ You can call the ```addData()``` in two ways:
5760
5861
> addData(columnName, data)
5962
60-
```data``` can be either ```integer``` or ```string```
61-
after adding all data, call ```doneDataAdding()``` method.
62-
```columnName``` is String and ```columnNumber``` is integer
63+
```data``` parameter in ```addData()``` can be either integer or string. After adding all data, call ```doneDataAdding()``` method.
64+
65+
```columnName``` is String and ```columnNumber``` is integer
6366

6467
Example:
6568
```
@@ -103,10 +106,10 @@ String aStringVariable = res.getString(columnIndex);
103106

104107
here ```columnIndex``` is an integer, starts from 0
105108

106-
Example
109+
Example:
107110
```
108111
while (res.moveToNext()) {
109-
int anIntegerVariable = res.getString(columnIndex);
112+
int anIntegerVariable = res.getString(columnIndex);
110113
String aStringVariable = res.getString(columnIndex);
111114
}
112115
```
@@ -140,7 +143,7 @@ Hope you'll enjoy using the library :)
140143

141144
> Thanks
142145
143-
## Lisense:
146+
## License:
144147
```
145148
MIT License
146149

androideasysql-library/src/main/java/p32929/androideasysql_library/DataType.java

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,41 @@ of this software and associated documentation files (the "Software"), to deal
2929
*/
3030

3131
public class DataType {
32-
public static String TEXT = " TEXT ";
33-
public static String INTEGER = " INTEGER ";
32+
private static String type = "";
33+
34+
// Data Types
35+
private String TEXT = " TEXT ";
36+
private String INTEGER = " INTEGER ";
37+
38+
// constrains
39+
private String asUnique = " UNIQUE ";
40+
private String notNull = " NOT NULL ";
41+
42+
// Data Type setters
43+
public DataType _text_() {
44+
type += TEXT;
45+
return this;
46+
}
47+
48+
public DataType _int_() {
49+
type += INTEGER;
50+
return this;
51+
}
52+
53+
54+
//
55+
public DataType unique() {
56+
type += asUnique;
57+
return this;
58+
}
59+
60+
public DataType notNull() {
61+
type += notNull;
62+
return this;
63+
}
64+
65+
//
66+
public String done() {
67+
return type;
68+
}
3469
}

androideasysql-library/src/main/java/p32929/androideasysql_library/EasyDB.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ public EasyDB addData(String columnName, int data) {
7575
}
7676

7777

78-
7978
public boolean doneDataAdding() {
8079
long result = writableDatabase.insert(TABLE_NAME, null, contentValues);
8180
contentValues = new ContentValues();
@@ -157,12 +156,14 @@ public void initDatabase() {
157156
public static EasyDB init(Context context, String dbName, SQLiteDatabase.CursorFactory factory, int version) {
158157
if (!dbName.endsWith(".db"))
159158
dbName += ".db";
159+
dbName = dbName.replaceAll(" ", "_");
160160
return new EasyDB(context, dbName, factory, version);
161161
}
162162

163163
public static EasyDB init(Context context, String dbName, SQLiteDatabase.CursorFactory factory, int version, DatabaseErrorHandler errorHandler) {
164164
if (!dbName.endsWith(".db"))
165165
dbName += ".db";
166+
dbName = dbName.replaceAll(" ", "_");
166167
return new EasyDB(context, dbName, factory, version, errorHandler);
167168
}
168169

app/src/main/java/p32929/databaseeasier/MainActivity.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ protected void onCreate(Bundle savedInstanceState) {
2525
textView = (TextView) findViewById(R.id.dataText);
2626

2727
easyDB = EasyDB.init(this, "TEST", null, 1)
28-
.addColumn(new Column("C1", DataType.TEXT))
29-
.addColumn(new Column("C2", DataType.TEXT))
30-
.addColumn(new Column("C3", DataType.TEXT))
28+
.addColumn(new Column("C1", new DataType()._text_().unique().done()))
29+
.addColumn(new Column("C2", new DataType()._text_().notNull().done()))
30+
.addColumn(new Column("C3", new DataType()._text_().done()))
3131
.doneTableColumn();
3232
}
3333

build/android-profile/profile-2018-07-22-11-15-20-202.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Binary file not shown.

build/android-profile/profile-2018-07-22-11-15-38-175.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Binary file not shown.

build/android-profile/profile-2018-08-15-23-17-19-059.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Binary file not shown.

build/android-profile/profile-2018-08-15-23-17-59-303.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Binary file not shown.

build/android-profile/profile-2018-08-15-23-18-10-071.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Binary file not shown.

build/android-profile/profile-2018-08-15-23-18-24-298.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Binary file not shown.

0 commit comments

Comments
 (0)