hi people of stackoverflow.
I have a problem when create column in sqlite data base. the error is that I create column but this not created in database. I realize Debug using logs and before add data base this exist afters this is null
help me please.
add code
public void onCreateDataBase(List<Map<String, Object>> model) {
String sqlStringT;
if (model != null) {
List<Map<String, Object>> fields;
int cont, totalFields;
for (Map<String, Object> dataTable : model) {
fields = (List<Map<String, Object>>) dataTable.get("fields");
totalFields = fields.size() - 1;
cont = 0;
// create the table
sqlStringT = " CREATE TABLE obj_"
+ dataTable.get("name") + "( f_pk_id INTEGER PRIMARY KEY autoincrement,";
for (Map<String, Object> dataAttribute : fields) {
String commaS = " , ";
String defaultValue = "" + dataAttribute.get("defaultValue");
defaultValue = " NULL ";
if (cont == totalFields) {
commaS = "";
}
String fieldLenght = "";
if (dataAttribute.get("length") != null && !dataAttribute.get("length").toString().equals("")) {
fieldLenght = "(" + dataAttribute.get("length") + ")";
}
String fieldType = dataAttribute.get("fieldType") + "";
if (fieldType.equals("-")) {
fieldType = "varchar";
}
sqlStringT += " f_" + dataAttribute.get("fieldName") + " "
+ fieldType + fieldLenght
+ " DEFAULT " + defaultValue + " " + commaS;
fieldType = null;
cont++;
}
sqlStringT += " ); ";
Log.d(TAG, "string sql for table " + sqlStringT);
this.dbLocal.execSQL(sqlStringT);
}
fields = null;
}
}
Aucun commentaire:
Enregistrer un commentaire