android-sqlite

group_concat and how to use row number in sqlite

折月煮酒 提交于 2019-12-11 19:26:43
问题 i have a data in a table, column id and column date id || datetime 1 || 2013-05-24 19:23:16 2 || 2013-05-28 19:24:20 3 || 2013-05-28 19:25:05 4 || 2013-05-30 19:25:39 5 || 2013-05-30 19:26:05 how query to show only one day with count?or one row with count. so the result is. || datetime || count 1 || 2013-05-24 19:23:16 || 1 2 || 2013-05-28 19:24:20 || 2 3 || 2013-05-30 19:25:39 || 2 i try in mysql and it works , there is my query. SELECT id, GROUP_CONCAT( datetime ) AS date, COUNT( id ) AS

Getting a unique row in SQLite

丶灬走出姿态 提交于 2019-12-11 18:58:26
问题 I am trying to search an item in sqlite by using String, & trying to return description contained in that row. items are stored in the table named Articles with column name A_name , Description column name is AS_name This is my code, the cursor is not null, but the while loop is not getting executed once public String searchData(String text) { Cursor cursor = sdb.query("Articles", new String[] {"A_name","AS_name"}, " A_name=?",new String[]{text}, null, null, null); Log.e("running", "cursor

Return the searched data from sqlite

烈酒焚心 提交于 2019-12-11 18:50:16
问题 I am trying to search an item in sqlite by using String, & trying to return description contained in that row. items are stored in the table named Articles with column name AS_name , & the description column name is Desc_art which I am unable to return. This is my code: public String searchData(String item) { String strvalue = null; SQLiteDatabase db = this.getWritableDatabase(); Cursor cur = null; String strquery = "select * from Articles where AS_name = "+item; cur = db.rawQuery(strquery

Android sqlite db.query leads to CursorIndexOutOfBoundsException

a 夏天 提交于 2019-12-11 18:28:17
问题 I am trying to select certain rows from my database, but since I kept getting index out of bound I decided to remove the WHERE part for now and just get all of the data. I have used the android tutorial http://developer.android.com/training/basics/data-storage/databases.html#DbHelper , in order to create this method. But when I am trying to get values from the query I am getting CursorIndexOutOfBoundsException. My Code: String getSite() { SQLiteDatabase db = this.getReadableDatabase(); //get

Diffrent Result After Save Number As Long in Database

三世轮回 提交于 2019-12-11 17:37:16
问题 i want to save 10 digit numbers in database , but after save , when show the numbers ,The stored numbers are stored As other numbers sorry for my poor english my Database : get Number : long studentId = Long.parseLong(studentId_et.getText().toString()); database.OpenDatabase(); database.SaveStudent(studentId , classId , studentName); database.close(); save Number : public void SaveStudent(long studentId, int classID, String studentName) { Cursor cursor = database.rawQuery("select * from " +

Sqlite Dropping Column from table

烂漫一生 提交于 2019-12-11 16:58:35
问题 Why sqlite database has the limitation of "not to drop a column from a table" in a single command? Are there any chances it would be added in future versions? 回答1: SQLite supports a limited subset of ALTER TABLE. The ALTER TABLE command in SQLite allows the user to rename a table or to add a new column to an existing table. It is not possible to rename a column, remove a column, or add or remove constraints from a table. https://sqlite.org/lang_altertable.html No, you can't. Are there any

Returning string array and use it on AutoCompleteTextview

风流意气都作罢 提交于 2019-12-11 16:47:05
问题 I'm developing an android application in which I retrieve some piece of data ( all the village village names) from SQLite database table. I returned this via String Array. Code is public String[] getAllVillage() { String[] villagelist=new String[2000]; int i=0; Cursor c=sqLiteDatabase.rawQuery("SELECT * FROM " + MYDATABASE_TABLE2 ,null); if (c.moveToFirst()) { do { villagelist[i]=c.getString(1); i++; }while(c.moveToNext()); } c.close(); return villagelist; } and, In my android application I

Create new table in existing DB in separate SQLiteOpenHelper class

倖福魔咒の 提交于 2019-12-11 16:43:17
问题 In my already created and deployed application, I've created a database MainDB , using a single class file which extended SQLiteOpenHelper , viz. public class BaseSQLiteOpenHelper extends SQLiteOpenHelper { private final static String DATABASE_NAME = "MainDB"; .... .... } Issue is I've tied this class, too much to a particular functionality. Now I'm adding a totally new module in application, which will also interact with DB, but with different new tables. Issue is I can't use the same class,

Exception while Retriving data from the SqliteDatabase

两盒软妹~` 提交于 2019-12-11 16:21:58
问题 I have written the code to Store the image in sqlitedatabase and also written the method to getall the records,but while getting data I am getting Exception as Nullpointer Exception.I am doing anything wrong in selectall method ? public class DBUserAdapter { private static final String DATABASE_NAME = "users"; private static final int DATABASE_VERSION = 1; private static final String USERDETAILS= "create table userdetails(usersno integer primary key autoincrement,photo BLOB,date text not null

sqlite JOIN query for multiple entries

℡╲_俬逩灬. 提交于 2019-12-11 15:58:09
问题 My database has "diary" table and "food" table. In diary table I have following columns: date, food1,food2, ...food10. In food table I have: id, name, allergen1, allergen2, allergen3. So basically you log up to 10 foods a day to diary. Now I'm trying to build a query which would let me find last date that I've eaten food with allergen3. So that's the query I came up with, which you probably know is not working ;-) Cursor findDateRes = db.rawQuery("SELECT date(" + DIARY_COL_DATE + ") FROM " +