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); 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; return true;
} }

View File

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