-
-
Save Basuhampali/f8ab67e3e6fc2b2973b9 to your computer and use it in GitHub Desktop.
Creating Data Base tables in Android programatically
This file contains hidden or 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
public static String createSQLiteTable() { | |
TableCreater tableCreator[]= { | |
new TableCreater(KEY_ID ,TableCreater.integerDataType), | |
new TableCreater(KEY_TODO,TableCreater.textDataType), | |
new TableCreater(KEY_STATUS ,TableCreater.integerDataType) | |
}; | |
return MySQLiteHelper.createTable(TABLE_NAME, tableCreator); | |
} |
This file contains hidden or 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
/** | |
* Send TableCreater {@link array} object and get the table string | |
* @param tableName | |
* @param tableCreator {@link array} object | |
* @return table {@link string} | |
* @throws <code>null</code> if sent TableCreater {@link array} object size is not greater than one. | |
*/ | |
public static String createTable(String tableName,TableCreater tableCreator[]) { | |
if(tableCreator.length > 1) { | |
String CREATE_TABLE = "create table "; | |
CREATE_TABLE = CREATE_TABLE.concat(tableName + "(" + tableCreator[0].parameterName + " integer primary key autoincrement, "); | |
for(int i=1;i<tableCreator.length;i++) { | |
if(i == tableCreator.length-1) { | |
CREATE_TABLE = CREATE_TABLE.concat(tableCreator[i].parameterName + " "+ tableCreator[i].dataType + " not null " + ");"); | |
} | |
else { | |
CREATE_TABLE = CREATE_TABLE.concat(tableCreator[i].parameterName + " "+ tableCreator[i].dataType + " not null, "); } | |
} | |
return CREATE_TABLE; | |
} | |
return null; | |
} |
This file contains hidden or 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
public class TableCreater { | |
public static String integerDataType = "integer"; | |
public static String textDataType = "text"; | |
public static String realDataType = "real"; | |
public String parameterName; | |
public String dataType; | |
public TableCreater(String string, String string2) { | |
// TODO Auto-generated constructor stub | |
this.parameterName = string; | |
this.dataType = string2; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment