We're coding for SQLite at the moment

This commit is contained in:
Acrobot 2012-11-02 20:48:14 +01:00
parent 533d9eacdd
commit b1528ddc6f
2 changed files with 14 additions and 11 deletions

View File

@ -50,7 +50,14 @@ public class Database {
EntityParser parser = new EntityParser(clazz);
//TODO Finish this
String fields = parser.parseToString();
try {
table.create(fields);
} catch (SQLException e) {
e.printStackTrace();
return false;
}
return true;
}

View File

@ -46,28 +46,24 @@ public class EntityParser {
* @param field Java's field
* @return SQL type
*/
public String convertToSQL(Field field) {
public static String convertToSQL(Field field) {
String sqlType = "";
Class<?> type = field.getType();
if (type.isAssignableFrom(String.class)) {
sqlType += "VARCHAR(255)";
} else if (type.isAssignableFrom(boolean.class)) {
if (type.isAssignableFrom(boolean.class)) {
sqlType += "BOOLEAN";
} else if (type.isAssignableFrom(int.class)) {
sqlType += "INTEGER";
} else if (type.isAssignableFrom(double.class)) {
sqlType += "DOUBLE";
} else if (type.isAssignableFrom(float.class)) {
sqlType += "FLOAT";
} else if (type.isAssignableFrom(double.class) || type.isAssignableFrom(float.class)) {
sqlType += "REAL";
} else {
sqlType += "TEXT";
}
if (field.isAnnotationPresent(Id.class)) {
sqlType += " AUTO INCREMENT";
sqlType += " PRIMARY KEY";
}
return null; //TODO Finish this
return sqlType;
}
}