Here you can find the source of getFreeTourName(SQLiteDatabase db, String tourName)
public static String getFreeTourName(SQLiteDatabase db, String tourName)
//package com.java2s; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; public class Main { protected final static String TOUR_TABLE_NAME = "Tour"; protected final static String TOUR_NAME = "name"; public static String getFreeTourName(SQLiteDatabase db, String tourName) { if (!tourNameExists(db, tourName)) { return tourName; }/*w ww . j a v a 2s .c o m*/ for (int i = 1; i < Integer.MAX_VALUE; i++) { String checkTourName = tourName + " " + Integer.toString(i); if (!tourNameExists(db, checkTourName)) return checkTourName; } // more than Integer.MAY_VALUE entries in table return tourName + " changeme"; } public static boolean tourNameExists(SQLiteDatabase db, String tourName) { Cursor cursor = db.query(TOUR_TABLE_NAME, new String[] { TOUR_NAME }, TOUR_NAME + "=?", new String[] { tourName }, null, null, null); cursor.moveToFirst(); if (cursor.getCount() == 0) return false; else return true; } }