Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help regarding Logic for sqlite database

 
Pramod P Deore
Ranch Hand
Posts: 632
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am developing an application for Android platform. And I am stuck at one point.This question is not about android specific therefore I am asking it here.

At the start of application I a showing a list of rooms (i.e list containing room names) to the user. User select one room name from this list. Now I want to store this selected item to database. For that I had created one table name as RoomTable. which has 3 columns as - RoomID (primary key), RoomName, and RoomSuffix.

So let suppose user selected room name as Hall then inside database entry becomes as

RoomID RoomName RoomSuffix
1 Hall 0
2 Kitchen 0
3 Hall1 1
4 Hall2 2
5 Bedroom 0

Means suppose user select second time again room name as Hall then it must becomes roomname+roomsuffix (i.e Hall1, Hall2... )

For this I had write following code


But this code doesn't give me the expected output. I got following output.




 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To search the suffix you are searching for Hall, but Hall1 and Hall2 do not have Hall as room name.

If I were you I'd keep all room names as Hall, then either calculate the displayed room name or add a new field for the full room name.

So:
1)
In displaying, you append RoomSuffix to RoomName if it isn't 0.

2)

The difference is when you calculate the full name. In 1) it's when displaying, in 2) it's when inserting into the database.

Now you can search for RoomName to find the RoomSuffix.
 
Pramod P Deore
Ranch Hand
Posts: 632
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob, you are right. After adding one more column it works fine. Thanks once again.
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic