限制SQLite数据库条目

时间:2013-09-28 05:25:39

标签: android database sqlite

我开发了一个Android应用程序,这是一个试用版...用户只有有限的设施..所以我想将用户输入限制为1 ...就像只有一个用户名应该能够注册..和结果显示必须限制为4我必须做的事情..我正在给出正确的代码......

package com.example.loginpage;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DataBaseHelper extends SQLiteOpenHelper

{

      public DataBaseHelper(Context context, String name,CursorFactory factory, int version) 
        {
                   super(context, name, factory, version);


        }


        // Called when no database exists in disk and the helper class needs
        // to create a new one.


        @Override
        public void onCreate(SQLiteDatabase _db) 
        {
                _db.execSQL(LoginDataBaseAdapter.DATABASE_CREATE);

        }



        // Called when there is a database version mismatch meaning that the version
        // of the database on disk needs to be upgraded to the current version.



        @Override
        public void onUpgrade(SQLiteDatabase _db, int _oldVersion, int _newVersion) 
        {



                // Log the version upgrade.


                Log.w("TaskDBAdapter", "Upgrading from version " +_oldVersion + " to " +_newVersion + ", which will destroy all old data");

                // Upgrade the existing database to conform to the new version. Multiple
                // previous versions can be handled by comparing _oldVersion and _newVersion
                // values.
                // The simplest case is to drop the old table and create a new one.


                _db.execSQL("DROP TABLE IF EXISTS " + "TEMPLATE");


                // Create a new one.


                onCreate(_db);
        }





}

1 个答案:

答案 0 :(得分:0)

使用Select Count(column Name) from tbalename和代码if(count>=1){ //Message to user}中的放置条件

从表中获取计数