// searchSugTab表中插入数据 // private void insertSearchSugValues(){ createSQLiteData(); // Log.d("TAG","Search:insertViewName开始"); // sqLiteDatabase=dbHelper.getWritableDatabase(); // int listLength=MainActivity.list.size(); // String searchName; // for(int i=0;i<listLength;i++){ // searchName=MainActivity.list.get(i).getName(); // searchSugValues=new ContentValues(); searchSugValues.put("id",i); // searchSugValues.put("name",searchName); // sqLiteDatabase.insert("searchSugTab",null,searchSugValues); // } // sqLiteDatabase.close(); // } 删除表 // private void deleteData(){ // Log.d("TAG","Search:deleteData开始"); sqLiteDatabase = dbHelper.getWritableDatabase(); // createSQLiteData(); // Log.d("TAG","Search:createSQLiteData运行成功"); sqLiteDatabase.execSQL("delete from searchSugTab"); // sqLiteDatabase.delete("searchSugTab",null,new String[]{"1"}); // Log.d("TAG","Search:execSQL执行成功"); // sqLiteDatabase.close(); // Log.d("TAG","Search:sqLiteDatabase关闭"); // } 获取表的版本信息,更新表的版本 // private void getDbInformation(SQLiteDatabase db){ db=openOrCreateDatabase("searchSugTab",MODE_PRIVATE,null); // db=openOrCreateDatabase("searchHisTab",MODE_PRIVATE,null); // String dbPath=db.getPath(); // Log.d("TAG","searchHisTab的路径:"+dbPath); // int version=db.getVersion(); // Log.d("TAG","searchHisTab的版本:"+version); // db.setVersion(3); // Log.d("TAG","成功设置searchHisTab的版本:"+version); // version=db.getVersion(); // Log.d("TAG","重新设置searchHisTab的版本之后的版本:"+version); insertViewName(); Log.d("TAG","Search:insertViewName()成功"); // } 判断cusor是否为空 // private void getSearchTSugTabCursorCount(){ // Log.d("TAG","Search:正在运行queryData"); // sqLiteDatabase=dbHelper.getReadableDatabase(); // Log.d("TAG","Search:createSQLiteData"); // String sql="select id as _id,name from searchSugTab"; // Cursor cursor=sqLiteDatabase.rawQuery(sql,null); // startManagingCursor(cursor); // Log.d("TAG","Search:Cursor"); // Log.d("TAG","Search:Cursor是否为空"+cursor.getCount()); // sqLiteDatabase.close(); // } 删除表 // private void deleteTable(){ // sqLiteDatabase=dbHelper.getWritableDatabase(); sqLiteDatabase.execSQL("DROP TABLE searchSugTab;",null); // sqLiteDatabase.close(); // } 查找数据库中所有的表 // private void findAllTable(){ // sqLiteDatabase=dbHelper.getWritableDatabase(); // Cursor cursor = sqLiteDatabase.rawQuery("select name from sqlite_master where type='table' order by name", null); // Log.d("TAG","创建的所有表: "); // cursor.moveToFirst(); // do{ // String name = cursor.getString(cursor.getColumnIndex("name")); // Log.i("TAG", name); // }while(cursor.moveToNext()); // } 不可运行的代码,无关的数据 // private void qita(){ 获取TextView的字符 TextView textView=(TextView)view.findViewById(R.id.suggectionTxt); Log.d("TAG","点击item获取到的信息为"+textView.getText().toString()); // // } // // 判断searchHisTab即将要插入的数据是否已经存在 // private boolean hasData(String tempName) { // Log.d("TAG","Search:hasData()开始判断"); // // 从数据库中searchHisTab表里找到name=tempName的id // Cursor cursor = dbHelper.getReadableDatabase().rawQuery( // "select id as _id,name from searchHisTab where name =?", new String[]{tempName}); // startManagingCursor(cursor); // Log.d("TAG","Search:hasData()完成判断"); // // 判断是否有下一个 // return cursor.moveToNext(); // } //获取ListView的item的cursor,以及id,position的值 //Cursor data=(Cursor)myListView.getItemAtPosition(position);//根据位置移动游标 // startManagingCursor(data); // String name = data.getString(data.getColumnIndex("name")); // Log.d("TAG","dataString的值为:"+name); // int m=data.getInt(data.getColumnIndex("_id")); // Log.d("TAG","m为:"+m); // Log.d("TAG","id为:"+id); // Log.d("TAG","position为:"+position); // 对要插入搜索记录的数据进行判断 // if(!hasData(query)){ // insertHisValues(query); // } |
在做搜索页面时用到的查询等方法(保留笔记用)
最新推荐文章于 2021-02-01 01:29:20 发布