Sqlite Database creation, Best practise Android -
Sqlite Database creation, Best practise Android -
i have database few tables. wish know, best way create table in database. tables contain both strings(text) , numbers(int , doubles). should create table datatypes text, int, double etc., or should create table texts , convert them before inserting , reading display.
let's table have...
sqldb.execsql("create table if not exists "+scriptname+"(dateofpurchase text, buyorsell text," + " purchasedquantity int, purchasedprice double, investmentwithoutbrokerage double," + " brokerage double, servicetax double, stt double, stampduty double, othertaxes double," + " investmentwithbrokerage double)");
instead of creating table different datatypes, if create table "text"s , needful conversions on strings whenever needed.
sqldb.execsql("create table if not exists "+scriptname+"(dateofpurchase text, buyorsell text," + " purchasedquantity text, purchasedprice text, investmentwithoutbrokerage text," + " brokerage text, servicetax text, stt text, stampduty text, othertaxes text," + " investmentwithbrokerage text)");
before inserting info table, convert values strings , while retrieving values table, (for calculations) convert them respective datatypes. displaying on screen, can utilize them straight strings.
if create table above, disadvantages/advantages on creating table datatypes?
always create tables proper datatypes. while in sqlite, don't need differentiate between, say, byte , integer or varchar(n) , text, there marked difference between number , string. using accurate types makes model more understandable, , guard against invalid values, i.e. string in numeric field. conversions numeric field string cheap; consider may want format currency values properly. thus, storing them strings not impractical, may complicate (and break) code.
android android-sqlite
Comments
Post a Comment