Here each time
suf = c4.getInt(c4.getColumnIndex("MAX_SUFFIX")); gives me '0'. But
how is this possible because each time I am saving next suffix.

On Nov 30, 12:40 pm, "pramod.deore" <[email protected]> wrote:
> Anyone  know what is wrong here?
>
> On Nov 30, 11:00 am, "pramod.deore" <[email protected]> wrote:
>
> > Hi, I have a table RoomTable which have 3 columns as
> > 1.RoomID (primary key),2.  RoomName 3. RoomSuffix
>
> > public void insertToRoomTable(String rName)
> > {
> >       try
> >         {
> >              sampleDB.execSQL("CREATE TABLE IF NOT EXISTS " +
> >                     ROOM_TABLE_NAME +
> >                     " (RoomID integer primary key
> > autoincrement,RoomName VARCHAR,RoomSuffix integer);");
>
> >                 boolean roomExist = checkRoomExist(roomName);
> >                         System.out.println ("RoomExist is"+roomExist);
> >                         if (roomExist)
> >                         {
> >                                 Cursor c4 = sampleDB.rawQuery("SELECT 
> > MAX(RoomSuffix) AS
> > MAX_SUFFIX FROM RoomTable WHERE RoomName = '"+roomName+"'",null);
>
> >                                 if (c4 != null )
> >                         {
> >                                 if  (c4.moveToFirst())
> >                                 {
> >                                         System.out.println 
> > ("??????????"+c4.getCount());
> >                                         do
> >                                         {
> >                                                 System.out.println
> > (c4.getInt(c4.getColumnIndex("MAX_SUFFIX")));
> >                                                 suf = 
> > c4.getInt(c4.getColumnIndex("MAX_SUFFIX"));
> >                                                 suf++;
> >                                                 System.out.println 
> > ("!!!!!!!!!!!!"+suf);
>
> >                                         }
> >                                         while (c4.moveToNext());
>
> >                                 }
> >                         }
>
> >                                 roomName = roomName+suf;
> >                                 c4.close();
>
> >                         }
>
> >                 sampleDB.execSQL("INSERT INTO " +
> >                                 ROOM_TABLE_NAME +
> >                                 " Values (null,'"+roomName+"','"+suf+"');");
>
> >                 System.out.println ("Inserted values into RoomTable
> > are"+roomName+":"+suf);
>
> >         }
> >                 catch (Exception e)
> >                 {
> >                         e.printStackTrace();
> >                 }
> >   }
>
> > public boolean checkRoomExist(String name)
> >         {
> >                 c = sampleDB.rawQuery("SELECT RoomName FROM " 
> > +ROOM_TABLE_NAME ,
> > null);
> >                 if (c != null )
> >         {
> >                 System.out.println ("%%%%%%%%%%%"+c.getCount());
> >                 if  (c.moveToFirst())
> >                 {
> >                         do
> >                         {
> >                                 rname = 
> > c.getString(c.getColumnIndex("RoomName"));
> >                                 System.out.println ("RoomName is"+rname);
>
> >                                 if (rname.equalsIgnoreCase(name))
> >                                 {
> >                                         System.out.println ("Room Exist");
> >                                         return true;
> >                                 }
>
> >                         }
> >                         while (c.moveToNext());
> >                 }
> >         }
>
> >         c.close();
> >         return false;
>
> >         }
>
> > Here what I want is - If suppose user insert first record as
> > 1   Hall   0
> > and again if he insert record with same RoomName i.e Hall then
> > RoomName must be Hall1(i.e. RoomName+suffix)
> > 2  Hall1   1
> > Third record must be
> > 3   Hall2  2
> > If user enter other roomname thenit must be
>
> > 4   Kitchen  0
> > again insert suppose Hall then
>
> > 5   Hall   3 (Because last Hall suffix is 2)
>
> > Means I want different suffix for different RoomName. But using above
> > code I get output as
>
> > 1   Hall     0
> > 2   Hall 1  1
> > 3   Hall1   1
> > 4   Hall1   1
>
> > Each time I get Suffix as 1.
> > What is wrong in this code?  And if I remove where clause and write it
> > as
>
> > if (roomExist)                                                              
> >                                                                             
> > {
> >                                 Cursor c4 = sampleDB.rawQuery("SELECT 
> > MAX(RoomSuffix) AS
> > MAX_SUFFIX FROM RoomTable ",null);
>
> > .....
>
> > }
>
> > Then here it is not maintaining different suffix for different
> > RoomName and I get output as
>
> > 1  Hall            0
> > 2  Hall1           1
> > 3  Hall 2          2
> > 4 Kitchen3       3
>
> > And what I want is
> > 1  Hall     0
> > 2  Hall1    1
> > 3  Hall2    2
> > 4 Kitchen  0
>
> > How to get This? Thanks in advance
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to