Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. public void onCreateDataBase(List<Map<String, Object>> model) {
  2. String sqlStringT;
  3. if (model != null) {
  4. List<Map<String, Object>> fields;
  5. int cont, totalFields;
  6. for (Map<String, Object> dataTable : model) {
  7. fields = (List<Map<String, Object>>) dataTable.get("fields");
  8. totalFields = fields.size() - 1;
  9. cont = 0;
  10. // create the table
  11. sqlStringT = " CREATE TABLE obj_"
  12. + dataTable.get("name") + "( f_pk_id INTEGER PRIMARY KEY autoincrement,";
  13.  
  14. for (Map<String, Object> dataAttribute : fields) {
  15. String commaS = " , ";
  16. String defaultValue = "" + dataAttribute.get("defaultValue");
  17. defaultValue = " NULL ";
  18.  
  19. if (cont == totalFields) {
  20. commaS = "";
  21. }
  22. String fieldLenght = "";
  23. if (dataAttribute.get("length") != null && !dataAttribute.get("length").toString().equals("")) {
  24. fieldLenght = "(" + dataAttribute.get("length") + ")";
  25. }
  26.  
  27. String fieldType = dataAttribute.get("fieldType") + "";
  28. if (fieldType.equals("-")) {
  29. fieldType = "varchar";
  30. }
  31. sqlStringT += " f_" + dataAttribute.get("fieldName") + " "
  32. + fieldType + fieldLenght
  33. + " DEFAULT " + defaultValue + " " + commaS;
  34. fieldType = null;
  35. cont++;
  36. }
  37.  
  38. sqlStringT += " ); ";
  39. Log.d(TAG, "string sql for table " + sqlStringT);
  40. this.dbLocal.execSQL(sqlStringT);
  41.  
  42. }
  43. fields = null;
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement