Created
May 11, 2017 12:01
-
-
Save iamrajendra/b60ca7f23197c37beb963d3b290fed09 to your computer and use it in GitHub Desktop.
In place of writing string statement to create table use this class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.android.sunshine.experiment.model; | |
import com.example.android.sunshine.data.WeatherContract; | |
import java.util.ArrayList; | |
import java.util.HashMap; | |
import java.util.Iterator; | |
import java.util.List; | |
import java.util.Map; | |
/** | |
* Created by gwl on 11/5/17. | |
*/ | |
public class CreateTableHelper { | |
private HashMap<String,String> mHashMapColumnName; | |
public static final String CONSTANT_PRIMARY_KEY = "INTEGER PRIMARY KEY AUTOINCREMENT,"; | |
public static final String CONSTANT_INTEGER = "INTEGER NOT NULL,"; | |
public static final String CONSTANT_REAL = "REAL NOT NULL,"; | |
private String tableName; | |
public CreateTableHelper(String tableName) { | |
this.tableName = tableName; | |
mHashMapColumnName = new HashMap<>(); | |
} | |
public void addColumn(String name,String type) | |
{ | |
mHashMapColumnName.put(name,type); | |
} | |
public String createStatement() | |
{ | |
Iterator iter = (Iterator) mHashMapColumnName.keySet().iterator(); | |
String tablequery = "CREATE TABLE " + tableName + " (" ; | |
while(iter.hasNext()) { | |
Map.Entry entry = (Map.Entry) iter.next(); | |
tablequery= tablequery + entry.getKey().toString() + entry.getValue().toString(); | |
} | |
tablequery = tablequery+")"; | |
return tablequery; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment