Android SqliteDatabase Command getFreeTourName(SQLiteDatabase db, String tourName)

Here you can find the source of getFreeTourName(SQLiteDatabase db, String tourName)

Description

get Free Tour Name

Declaration

public static String getFreeTourName(SQLiteDatabase db, String tourName) 

Method Source Code

//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;
    }
}

Related

  1. insertIntoTable(SQLiteDatabase database, String table, String[] data)
  2. selectFromTable(SQLiteDatabase db, String table, String sample)
  3. updateTable(SQLiteDatabase database, String table, String id, String[] newValues)
  4. getTaskCursor(SQLiteDatabase database, String name)
  5. SQLiteSanitize(String input)
  6. getNewTourPointPosition(SQLiteDatabase db, long tourId)
  7. getTourNames(SQLiteDatabase db)
  8. insertTour(SQLiteDatabase db, String tourName)
  9. isCompanyInTour(SQLiteDatabase db, long companyId, long tourId)