Skip to content

Commit

Permalink
Sql syntax fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Sp4Rx committed Dec 2, 2017
1 parent 3c3030e commit 4cf6cb2
Show file tree
Hide file tree
Showing 20 changed files with 65 additions and 42 deletions.
Binary file modified .gradle/4.1/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/4.1/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/4.1/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified .gradle/4.1/javaCompile/classAnalysis.bin
Binary file not shown.
Binary file modified .gradle/4.1/javaCompile/jarAnalysis.bin
Binary file not shown.
Binary file modified .gradle/4.1/javaCompile/javaCompile.lock
Binary file not shown.
Binary file modified .gradle/4.1/javaCompile/taskHistory.bin
Binary file not shown.
Binary file modified .gradle/4.1/javaCompile/taskJars.bin
Binary file not shown.
Binary file modified .gradle/4.1/taskHistory/fileSnapshots.bin
Binary file not shown.
Binary file modified .gradle/4.1/taskHistory/taskHistory.bin
Binary file not shown.
Binary file modified .gradle/4.1/taskHistory/taskHistory.lock
Binary file not shown.
1 change: 0 additions & 1 deletion build/android-profile/profile-2017-11-29-16-14-28-979.json

This file was deleted.

Binary file not shown.
4 changes: 4 additions & 0 deletions demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
}

dependencies {
Expand Down
24 changes: 19 additions & 5 deletions demo/demo.iml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</configuration>
</facet>
</component>
<component name="NewModuleRootManager">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
<exclude-output />
Expand Down Expand Up @@ -84,20 +84,35 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/build-info" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/check-manifest" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-runtime-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-verifier" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-resources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-support" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaPrecompile" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/prebuild" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/processing-tools" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/split-apk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/splits-support" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/tmp" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="jdk" jdkName="Android API 26 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="com.android.support:support-media-compat-26.1.0" level="project" />
<orderEntry type="library" scope="TEST" name="junit:junit:4.12@jar" level="project" />
Expand Down Expand Up @@ -127,6 +142,5 @@
<orderEntry type="library" scope="TEST" name="net.sf.kxml:kxml2:2.3.0@jar" level="project" />
<orderEntry type="library" name="com.android.support:animated-vector-drawable-26.1.0" level="project" />
<orderEntry type="module" module-name="shorthanddb" />
<orderEntry type="library" name="android-android-26" level="project" />
</component>
</module>
30 changes: 14 additions & 16 deletions demo/src/main/java/io/github/sp4rx/shorthanddb/DbHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@


public class DbHelper extends SQLiteOpenHelper {
private static final String DB_NAME = "qr_login";
private static final int VERSION = 4;
private static final String DB_NAME = "short.db";
private static final int VERSION = 11;

private static final String TAG = "DbHelper";
private static DbHelper mInstance;
Expand All @@ -44,23 +44,21 @@ private DbHelper(Context context) {
public void onCreate(SQLiteDatabase db) {

//Method 3
Map<String, DataType> tableStructure = new HashMap<>();
tableStructure.put(KEY_USER_EMAIL, DataType.TEXT);
tableStructure.put(KEY_USER_ID, DataType.INTEGER);

Table.create(TABLE_USER, tableStructure, db);
// Map<String, DataType> tableStructure = new HashMap<>();
// tableStructure.put(KEY_USER_EMAIL, DataType.TEXT);
// tableStructure.put(KEY_USER_ID, DataType.INTEGER);
//
// Table.create(TABLE_USER, tableStructure, db);

//Method 4
ShortHandSchema shortHandSchema = new ShortHandSchema() {
@Override
public ArrayList<Schema> getSchema() {
ArrayList<Schema> schemas = new ArrayList<>();
schemas.add(new Schema(KEY_USER_ID, new Constraint[]{Constraint.PRIMARY_KEY, Constraint.UNIQUE}, DataType.INTEGER));
schemas.add(new Schema(KEY_USER_EMAIL, DataType.TEXT));
return schemas;
}
ShortHandSchema shortHandSchema = () -> {
ArrayList<Schema> schemas = new ArrayList<>();
schemas.add(new Schema("id", DataType.INTEGER, new Constraint[]{ Constraint.PRIMARY_KEY, Constraint.AUTOINCREMENT} ));
schemas.add(new Schema(KEY_USER_ID, DataType.TEXT));
schemas.add(new Schema(KEY_USER_EMAIL, DataType.TEXT));
return schemas;
};
Table.create(TABLE_USER_2, shortHandSchema, db);
Table.create(TABLE_USER, shortHandSchema, db);

}

Expand Down
16 changes: 8 additions & 8 deletions demo/src/main/java/io/github/sp4rx/shorthanddb/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ protected void onCreate(Bundle savedInstanceState) {
Log.d(TAG, Table.generateSql(TABLE_USER, tableStructure));

//Method 2
ShortHandSchema shortHandSchema = new ShortHandSchema() {
@Override
public ArrayList<Schema> getSchema() {
ArrayList<Schema> schemas = new ArrayList<>();
schemas.add(new Schema(KEY_USER_ID, new Constraint[]{Constraint.PRIMARY_KEY, Constraint.UNIQUE}, DataType.INTEGER));
schemas.add(new Schema(KEY_USER_EMAIL, DataType.TEXT));
return schemas;
}
ShortHandSchema shortHandSchema = () -> {
ArrayList<Schema> schemas = new ArrayList<>();
schemas.add(new Schema(KEY_USER_ID, DataType.INTEGER, new Constraint[]{Constraint.PRIMARY_KEY, Constraint.UNIQUE} ));
schemas.add(new Schema(KEY_USER_EMAIL, DataType.TEXT));
return schemas;
};

Log.d(TAG, Table.generateSql(TABLE_USER, shortHandSchema));

DbHelper.initDb(this);
System.out.println( DbHelper.getInfo(this));
}
}
10 changes: 7 additions & 3 deletions shorthanddb/shorthanddb.iml
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,20 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/attr" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/check-manifest" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/intermediate-jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaPrecompile" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/tmp" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 26 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@

public class Schema {
private String columnName;
private Constraint[] constraints;
private DataType dataType;
private Constraint[] constraints;

public Schema(String columnName, DataType dataType) {
this.columnName = columnName;
this.dataType = dataType;
}

public Schema(String columnName, Constraint[] constraints, DataType dataType) {
public Schema(String columnName, DataType dataType, Constraint[] constraints) {
this.columnName = columnName;
this.constraints = constraints;
this.dataType = dataType;
this.constraints = constraints;
}

public DataType getDataType() {
Expand Down Expand Up @@ -60,8 +60,8 @@ public void setConstraints(Constraint[] constraints) {
public String toString() {
return "Schema{" +
"columnName='" + columnName + '\'' +
", constraints=" + Arrays.toString(constraints) +
", dataType=" + dataType +
", constraints=" + Arrays.toString(constraints) +
'}';
}
}
14 changes: 9 additions & 5 deletions shorthanddb/src/main/java/io/github/sp4rx/shothanddb/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ public synchronized static String generateSql(String tableName, ShortHandSchema
int count = 0;
for (Schema schema : shortHandSchema.getSchema()) {
if (count == shortHandSchema.getSchema().size() - 1) {
createTableSql.append(schema.getColumnName()).append(" ").append(schema.getConstraintsString()).append(" ").append(schema.getDataType().getValue()).append(" )");
createTableSql.append(schema.getColumnName()).append(" ").append(schema.getDataType().getValue()).append(" ").append(schema.getConstraintsString()).append(" )");
} else {
createTableSql.append(schema.getColumnName()).append(" ").append(schema.getConstraintsString()).append(" ").append(schema.getDataType().getValue()).append(", ");
createTableSql.append(schema.getColumnName()).append(" ").append(schema.getDataType().getValue()).append(" ").append(schema.getConstraintsString()).append(", ");
}
count++;
}
Expand Down Expand Up @@ -133,7 +133,8 @@ public synchronized static boolean create(String tableName, Map<String, DataType
try {
db.execSQL(createTableSql.toString());
} catch (SQLException e) {
e.printStackTrace();
if (Logger.isDebuggable)
e.printStackTrace();
return false;
}
return true;
Expand All @@ -152,16 +153,19 @@ public synchronized static boolean create(String tableName, ShortHandSchema shor
int count = 0;
for (Schema schema : shortHandSchema.getSchema()) {
if (count == shortHandSchema.getSchema().size() - 1) {
createTableSql.append(schema.getColumnName()).append(" ").append(schema.getConstraintsString()).append(" ").append(schema.getDataType().getValue()).append(" )");
createTableSql.append(schema.getColumnName()).append(" ").append(schema.getDataType().getValue()).append(" ").append(schema.getConstraintsString()).append(" )");
} else {
createTableSql.append(schema.getColumnName()).append(" ").append(schema.getConstraintsString()).append(" ").append(schema.getDataType().getValue()).append(", ");
createTableSql.append(schema.getColumnName()).append(" ").append(schema.getDataType().getValue()).append(" ").append(schema.getConstraintsString()).append(", ");
}
count++;
}

Logger.i(TAG, "SQL: " + createTableSql);

try {
db.execSQL(createTableSql.toString());
} catch (SQLException e) {
if (Logger.isDebuggable)
e.printStackTrace();
return false;
}
Expand Down

0 comments on commit 4cf6cb2

Please sign in to comment.