Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/199.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android中sqlite数据库中的设置标志_Android_Sqlite - Fatal编程技术网

android中sqlite数据库中的设置标志

android中sqlite数据库中的设置标志,android,sqlite,Android,Sqlite,在我的应用程序中,我想为收藏夹报价设置标志。单击按钮,我想为特定行设置该标志。在我的数据库中,对于引号,我采用了文本数据格式,对于boo-lean-BOOL,我已经成功地从数据库中检索到文本值,但我无法在数据库中设置布尔值。由于我是这个主题的新手,非常感谢在这方面提供的任何帮助。 下面是我的代码 public class DatabaseHelper extends SQLiteOpenHelper{ //The Android's default system path of your

在我的应用程序中,我想为收藏夹报价设置标志。单击按钮,我想为特定行设置该标志。在我的数据库中,对于引号,我采用了文本数据格式,对于boo-lean-BOOL,我已经成功地从数据库中检索到文本值,但我无法在数据库中设置布尔值。由于我是这个主题的新手,非常感谢在这方面提供的任何帮助。 下面是我的代码

public class DatabaseHelper extends SQLiteOpenHelper{
    //The Android's default system path of your application database.
    private static String DB_PATH = "/data/data/com.t4t.smspopup/databases/";
    private static String DB_NAME = "smspopupplus.sqlite";
    private static SQLiteDatabase myDataBase; 
    private final Context myContext;
    public static String Column_Favorite="0"; 

    public DatabaseHelper(Context context) {
        super(context, DB_NAME, null, 1);
        this.myContext = context;
    }

    public void createDataBase() throws IOException
    {
        boolean dbExist = checkDataBase();      
        SQLiteDatabase db_Read = null;
        if(dbExist)
        {

        }
        else
        {
            db_Read=this.getReadableDatabase();
            db_Read.close();
            Log.i("debug++++", "databse created");
            try
            {
                copyDataBase();
            }
            catch (IOException e)
            {
                e.printStackTrace();
                throw new Error("Error copying database");
            }
        }
    }

    public boolean checkDataBase()
    {
        SQLiteDatabase checkDB = null;

        try
        {
            String myPath = DB_PATH + DB_NAME;
            checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
        }
        catch(SQLiteException e)
        {

        }

        if(checkDB != null)
        {
            checkDB.close();
        }

        return checkDB != null ? true : false;
    }

    public void copyDataBase() throws IOException
    {
        InputStream myInput = myContext.getAssets().open(DB_NAME);
        String outFileName = DB_PATH + DB_NAME;
        OutputStream myOutput = new FileOutputStream(outFileName);
        byte[] buffer = new byte[1024];
        int length;
        while ((length = myInput.read(buffer))>0)
        {
            myOutput.write(buffer, 0, length);
        }

        myOutput.flush();
        myOutput.close();
        myInput.close();
    }

    public void openDataBase() throws SQLException
    {
        String myPath = DB_PATH + DB_NAME;
        myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
        Log.i("debug++++", "databse opened");
    }

    public void close()
    {
        if(myDataBase != null)
            myDataBase.close();

        super.close();
    }

    @Override
    public void onCreate(SQLiteDatabase db)
    {

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
    {

    }

    public boolean updateDB(String status,String what,int value)
    {
        return false;

    }
    //retrive sms text from DB
    public  ArrayList<String> getSMSList(String categoryName)
    {
        ArrayList<String> SMSList = new ArrayList<String>();

        try{
            Cursor cursor=null;


            cursor = myDataBase.query(true,categoryName,null,null,null,null,null,null,null);
            while(cursor.moveToNext())
            {
                //ProgressData progress = new ProgressData(cursor.getString(0),cursor.getString(1));
                String SMSString=cursor.getString(1);
                SMSList.add(SMSString);
                //Log.i("debug++++", ""+progressList);
            }
            cursor.close();

        }catch (Exception e) {
            e.printStackTrace();
        }

        return SMSList;
    }


    @SuppressWarnings("null")
    public void execSql(String sql,Object[] args)
    {
        SQLiteDatabase sqLiteDatabase = null;
        if(args==null)
        {
            sqLiteDatabase.execSQL(sql);
        }
        else

        {
            Log.e("debug -----------", "command execuated");
            sqLiteDatabase.execSQL(sql,args);
        }

    } 

要更改表中的值,需要UPDATE语句。
您可以在中检查语法。

要更改表中的值,您需要一条UPDATE语句。 您可以在中检查语法。

SQLite SQLite没有单独的布尔存储类。相反,布尔值存储为整数0 false和1 true

可以通过以下方式将布尔值转换为int:

int flag = (boolValue==true)? 1:0;
String query = "UPDATE "+ TABLE_NAME + " set "+COLUMN_NAME+" = "+flag + " where "+CONDITION;
myDataBase.exeSQL(query);
您可以按如下方式将int转换回boolean:

 // Select COLUMN_NAME 'flag' values from db. 
 // This will be integer value, you can convert this int value back to Boolean as follows
Boolean flag2 = (intValue==1)?true:false;
SQLite SQLite没有单独的布尔存储类。相反,布尔值存储为整数0 false和1 true

可以通过以下方式将布尔值转换为int:

int flag = (boolValue==true)? 1:0;
String query = "UPDATE "+ TABLE_NAME + " set "+COLUMN_NAME+" = "+flag + " where "+CONDITION;
myDataBase.exeSQL(query);
您可以按如下方式将int转换回boolean:

 // Select COLUMN_NAME 'flag' values from db. 
 // This will be integer value, you can convert this int value back to Boolean as follows
Boolean flag2 = (intValue==1)?true:false;

如果要在SQLite数据库中存储布尔值,可以将布尔值存储为整数0 false和1 true

如果要在SQLite数据库中存储布尔值,可以将布尔值存储为整数0 false和1 true

我始终使用TINYINT在我的数据库中保存标志,因为它需要 数据库中的最小空间。后来我只是简单地切换状态 使用if速记:

post.postFaved = post.postFaved == 1 ? 0 : 1;

我总是使用TINYINT在数据库中保存标志,因为它需要 数据库中的最小空间。后来我只是简单地切换状态 使用if速记:

post.postFaved = post.postFaved == 1 ? 0 : 1;
execSQL为rest做了这件事,rest全部到位,使用rawQuery让我不知道execSQL为什么做了这件事,rest全部到位,使用rawQuery让我不知道在哪里