Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement