Related
I have an SQL method here. I would like to return the data in a String[] array.
How do I do that exactly?
Thank you!
public String[] getLikedSongs() {
SQLiteDatabase db = this.getReadableDatabase();
String[] LikeSong;
Cursor cursor = db.rawQuery(" SELECT " + COL_4 + " FROM " + Table_Name + " WHERE " + COL_4 + " IS NOT NULL", null);
while (cursor.moveToNext()) {
String note = cursor.getString(0);
}
cursor.close();
db.close();
return LikeSong;
}
You must define the array's length and this can be done only after the Cursor fetches all the rows. Then set its length to the nimber of rows of the Cursor.
Then inside the while loop set the items of the array:
public String[] getLikedSongs() {
String[] LikeSong = null;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT " + COL_4 + " FROM " + Table_Name + " WHERE " + COL_4 + " IS NOT NULL", null);
if (cursor.getCount() > 0) {
LikeSong = new String[cursor.getCount()];
int i = 0;
while (cursor.moveToNext()) {
LikeSong[i] = cursor.getString(0);
i++;
}
}
cursor.close();
db.close();
return LikeSong;
}
Currently I have a query retrieves images from my bucket in MediaStore and it's in ascending order (the oldest posts appear first). How do I modify my query so that it displays the newest images first?
String[] PROJECTION_BUCKET = {
MediaStore.Images.ImageColumns.BUCKET_ID,
MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME,
MediaStore.Images.ImageColumns.DATE_TAKEN,
MediaStore.Images.ImageColumns.DATA};
Uri images = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
//Not sure how to modify query here
Cursor cur = getContentResolver().query(images, PROJECTION_BUCKET,
MediaStore.Images.Media.BUCKET_DISPLAY_NAME + " like ? ",
new String[] {"%Download%"} , null);
Log.i("ListingImages"," query count=" + cur.getCount());
if (cur.moveToFirst()) {
String bucket;
String date;
String data;
int bucketColumn = cur.getColumnIndex(
MediaStore.Images.Media.BUCKET_DISPLAY_NAME);
int dateColumn = cur.getColumnIndex(
MediaStore.Images.Media.DATE_TAKEN);
int dataColumn = cur.getColumnIndex(
MediaStore.Images.Media.DATA);
do {
bucket = cur.getString(bucketColumn);
date = cur.getString(dateColumn);
data = cur.getString(dataColumn);
Log.i("ListingImages", " bucket=" + bucket
+ " date_taken=" + date
+ " _data=" + data);
} while (cur.moveToNext());
}
You will have to use the last argument of the query() method which is the sortOrder.
So instead of null pass the column followed by DESC to sort descending:
Cursor cur = getContentResolver().query(
images,
PROJECTION_BUCKET,
MediaStore.Images.Media.BUCKET_DISPLAY_NAME + " like ? ",
new String[] {"%Download%"},
MediaStore.Images.Media.DATE_TAKEN + " DESC"
);
I was trying to get buckets having audio files using MediaStore. This is working fine on Android 10 API 29 but not working previous Android versions. I've attached a screenshot of working example on Android 10 API 29.
Caused by: android.database.sqlite.SQLiteException: no such column:
bucket_display_name (code 1 SQLITE_ERROR): , while compiling: SELECT
bucket_display_name, bucket_id FROM audio ORDER BY date_added ASC
logcat.
Caused by: android.database.sqlite.SQLiteException: no such column: bucket_display_name (code 1 SQLITE_ERROR): , while compiling: SELECT bucket_display_name, bucket_id FROM audio ORDER BY date_added ASC
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:179)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:418)
at android.content.ContentResolver.query(ContentResolver.java:802)
at android.content.ContentResolver.query(ContentResolver.java:752)
at android.content.ContentResolver.query(ContentResolver.java:710)
at com.aisar.mediaplayer.fragments.AudioFolderFragment$AsyncVideoFolderLoader.doInBackground(AudioFolderFragment.java:148)
at com.aisar.mediaplayer.fragments.AudioFolderFragment$AsyncVideoFolderLoader.doInBackground(AudioFolderFragment.java:130)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Code:
class AsyncVideoFolderLoader extends AsyncTask<String, String, List<ModelAudioFolder>> {
private String sortBy;
public AsyncVideoFolderLoader(String sortBy) {
this.sortBy = sortBy;
}
#Override
protected List<ModelAudioFolder> doInBackground(String... strings) {
List<ModelAudioFolder> videoItems = new ArrayList<>();
videoItems.clear();
final HashMap<String, ModelAudioFolder> output = new HashMap<>();
final Uri contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
final String[] projection = {MediaStore.Audio.Media.BUCKET_DISPLAY_NAME, MediaStore.Audio.Media.BUCKET_ID};
try (final Cursor cursor = getActivity().getContentResolver().query(
contentUri,
projection,
null,
null,
"" + sortBy)) {
if ((cursor != null) && (cursor.moveToFirst())) {
final int columnBucketName = cursor.getColumnIndex(MediaStore.Audio.Media.BUCKET_DISPLAY_NAME);
final int columnBucketId = cursor.getColumnIndex(MediaStore.Audio.Media.BUCKET_ID);
do {
final String bucketName = cursor.getString(columnBucketName);
final String bucketId = cursor.getString(columnBucketId);
if (!output.containsKey(bucketId)) {
final int count = getCount(contentUri, bucketId);
final ModelAudioFolder item = new ModelAudioFolder(
"" + bucketId,
"" + bucketName,
"",
"" + getPath(bucketId),
"" + count
);
output.put(bucketId, item);
videoItems.add(item);
}
} while (cursor.moveToNext());
}
}
return videoItems;
}
private int getCount(#NonNull final Uri contentUri, #NonNull final String bucketId) {
try (final Cursor cursor = getActivity().getContentResolver().query(contentUri,
null, MediaStore.Audio.Media.BUCKET_ID + "=?", new String[]{bucketId}, null)) {
return ((cursor == null) || (cursor.moveToFirst() == false)) ? 0 : cursor.getCount();
}
}
private String getPath(String BUCKET_ID) {
String path = "";
String selection = null;
String[] projection = {
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.BUCKET_ID
};
Cursor cursor = getActivity().getContentResolver().query(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
projection,
selection,
null,
null);
while (cursor.moveToNext()) {
if (BUCKET_ID.equals(cursor.getString(1))) {
//add only those videos that are in selected/chosen folder
path = cursor.getString(0);
}
}
return path;
}
#Override
protected void onPostExecute(List<ModelAudioFolder> audioFolderList) {
super.onPostExecute(audioFolderList);
if (audioFolderList.size() <= 0) {
noFoldersRl.setVisibility(View.VISIBLE);
foldersRl.setVisibility(View.GONE);
} else {
noFoldersRl.setVisibility(View.GONE);
foldersRl.setVisibility(View.VISIBLE);
}
Log.d("FoldersSize", "onPostExecute: " + audioFolderList.size());
adapterAudioFolder = new AdapterAudioFolder(getActivity(), audioFolderList, dashboardActivity);
foldersRv.setAdapter(adapterAudioFolder);
}
}
...
The reason of the exception is BUCKET_DISPLAY_NAME. It is added in API 29. Before this we were using DISPLAY_NAME for API 28 & below. Please refer to the docs BUCKET_DISPLAY_NAME.
For solution you can write conditions according to current API level. And for getting folder name, you can use RELATIVE_PATH.
In API verions <= 28 BUCKET_DISPLAY_NAME only exists for images and videos, so, accesible via MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME or MediaStore.Vidos.VideoColumns.BUCKET_DISPLAY_NAME.
That said, the solution to get the BUCKET_DISPLAY_NAME for audios in versions bellow 29, is to parse the MediaStore.Files.FileColumns.DATA. This field is deprecated in 29, but still valid in previous versions.
The field contains the actual path + filename, and since a BUCKET_DISPLAY_NAME is in reality the actual parent folder name where a file is located, what you need to do is to remove the file name, and then get the sub-string starting at the last found backward-slash from the path.
I did it my self now. First retrieved all audio files, then separated audio URIs. From audio URIs, I've got Folder Names. I'm posting my solution here so maybe someone else can get benefit from it.
class AsyncVideoFolderLoader extends AsyncTask<String, String, List<ModelAudioFolder>> {
private Cursor cursor;
List<ModelAudioTe> audioList;
private String sortBy;
public AsyncVideoFolderLoader(String sortBy) {
this.sortBy = sortBy;
}
#Override
protected List<ModelAudioFolder> doInBackground(String... strings) {
String selection = null;
String[] projection;
projection = new String[]{
MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.DURATION,
MediaStore.Audio.Media.ALBUM,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.SIZE,
MediaStore.Audio.Media.ALBUM_ID
};
cursor = getActivity().getContentResolver().query(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
projection,
selection,
null,
null);
audioList = new ArrayList<>();
ModelAudioTe modelAudio;
while (cursor.moveToNext()) {
modelAudio = new ModelAudioTe(
"" + cursor.getString(0),
"" + cursor.getString(1),
"" + cursor.getString(2),
"" + cursor.getString(3),
"" + cursor.getString(4),
"" + cursor.getString(5),
"" + cursor.getString(6),
"" + cursor.getString(7));
audioList.add(modelAudio);
}
//creating audio paths/uris list
ArrayList<String> pathsList = new ArrayList<>();
pathsList.clear();
for (int i = 0; i < audioList.size(); i++) {
String folderName = new File(audioList.get(i).getDATA()).getParentFile().getName();
String folderId = new File(audioList.get(i).getDATA()).getParentFile().getParent();
pathsList.add(folderId + "/" + folderName);
}
//generating folder names from audio paths/uris
List<ModelAudioFolder> folderList = new ArrayList<>();
folderList.clear();
for (int i = 0; i < audioList.size(); i++) {
String folderName = new File(audioList.get(i).getDATA()).getParentFile().getName();
String folderId = new File(audioList.get(i).getDATA()).getParentFile().getParent();
int count = Collections.frequency(pathsList, folderId + "/" + folderName);
String folderRoot;
String folderRoot1 = "";
if (audioList.get(i).getDATA().contains("emulated")) {
folderRoot = "emulated";
} else {
folderRoot = "storage";
}
if (i > 0) {
if (audioList.get(i - 1).getDATA().contains("emulated")) {
folderRoot1 = "emulated";
} else {
folderRoot1 = "storage";
}
}
if (i == 0) {
ModelAudioFolder model = new ModelAudioFolder("" + folderId + "/" + folderName, "" + folderName, "", "" + folderId + "/" + folderName, "" + count);
folderList.add(model);
Log.d("The_Tag1", "onCreate: " + folderName + " " + folderRoot + " " + folderId + "/" + folderName + " " + count);
} else if (
folderName.equals(new File(audioList.get(i - 1).getDATA()).getParentFile().getName())
&&
folderRoot.equals(folderRoot1)
) {
//exclude
} else {
ModelAudioFolder model = new ModelAudioFolder("" + folderId + "/" + folderName, "" + folderName, "", "" + folderId + "/" + folderName, "" + count);
folderList.add(model);
Log.d("The_Tag1", "onCreate: " + folderName + " " + folderRoot + " " + folderId + "/" + folderName + " " + " " + count);
}
}
return folderList;
}
#Override
protected void onPostExecute(List<ModelAudioFolder> audioFolderList) {
super.onPostExecute(audioFolderList);
Log.d("ModelAudioFolder_Size", "Count:" + audioFolderList.size());
try {
if (audioFolderList.size() <= 0) {
noFoldersRl.setVisibility(View.VISIBLE);
foldersRl.setVisibility(View.GONE);
} else {
noFoldersRl.setVisibility(View.GONE);
foldersRl.setVisibility(View.VISIBLE);
}
Log.d("FoldersSize", "onPostExecute: " + audioFolderList.size());
adapterAudioFolder = new AdapterAudioFolder(getActivity(), audioFolderList, dashboardActivity);
foldersRv.setAdapter(adapterAudioFolder);
} catch (Exception e) {
e.printStackTrace();
}
}
}
my problem is with very specific query. My SQLite datbase is only 1 table with 11 entries. It creates just fine, but upon execution of this piece of code it crashes. When I change the query to simply:
SELECT * FROM Items
Then it works fine, but I need more narrow results, therefore I modify with the "WHERE" clause. But then it crashes and the application stops. If I comment out the Cursor... it runs fine.
public int findPictureNumber(String itemtitle) {
String query = "SELECT nr_of_pics FROM Items WHERE ItemTitle = \"" + itemtitle + "\"";
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(query, null);
...
}
Where is the error? I can't seem to find it even after narrowing it down to those lines of code.
EDIT:
This is a method for adding an item to a database.
public void newItemFuro () {
MyDBHandler dbHandler = new MyDBHandler(this, null, null, 1);
String title = "Furo";
String author = "Fernando Brizio";//í
String category = "Decoracao";//çã
int date = 2012;
String type = "Taca";//ç
String country = "Portugal";
String colour = "Castanho/Cortica";//ç
String material = "Castanho/Cortica";//ç
boolean isFavourite = false;
String imgres = "furoo";
int nr_of_pics = 3;
Item item = new Item(title, author, category, date, type, country, colour, material, isFavourite, imgres, nr_of_pics);
dbHandler.addItem(item);
}
//helper for types
public static final String VARCHAR_TYPE = " VARCHAR(50)";
public static final String BOOL_TYPE = " BOOLEAN";
public static final String INT_TYPE = " INTEGER";
Here it creates the table:
public void onCreate(SQLiteDatabase db) {
String CREATE_ITEMS_TABLE = "CREATE TABLE " + TABLE_ITEMS +
"("
+ COLUMN_ENTRY_ID + INT_TYPE +" PRIMARY KEY AUTOINCREMENT,"
+ COLUMN_TITLE + VARCHAR_TYPE + ","
+ COLUMN_AUTHOR + VARCHAR_TYPE + ","
+ COLUMN_CATEGORY + VARCHAR_TYPE + ","
+ COLUMN_DATE + INT_TYPE + ","
+ COLUMN_TYPE + VARCHAR_TYPE + ","
+ COLUMN_COUNTRY + VARCHAR_TYPE + ","
+ COLUMN_COLOUR + VARCHAR_TYPE + ","
+ COLUMN_MATERIAL + VARCHAR_TYPE + ","
+ COLUMN_FAVOURITE + BOOL_TYPE + ","
+ COLUMN_IMGRES + VARCHAR_TYPE + ","
+ COLUMN_NUMBER_OF_PICS + INT_TYPE +
")";
db.execSQL(CREATE_ITEMS_TABLE);
}
Adding item:
public void addItem(Item item) {
ContentValues values = new ContentValues();
values.put(COLUMN_TITLE, item.getItemTitle());
values.put(COLUMN_AUTHOR, item.getAuthor());
values.put(COLUMN_CATEGORY, item.getCategory());
values.put(COLUMN_DATE, item.getDate());
values.put(COLUMN_TYPE, item.getType());
values.put(COLUMN_COUNTRY, item.getCountry());
values.put(COLUMN_COLOUR, item.getColour());
values.put(COLUMN_MATERIAL, item.getMaterial());
values.put(COLUMN_FAVOURITE, item.getFavourite());
values.put(COLUMN_IMGRES, item.getImgres());
values.put(COLUMN_NUMBER_OF_PICS, item.getNumberOfPics());
SQLiteDatabase db = this.getWritableDatabase();
db.insert(TABLE_ITEMS, null, values);
db.close();
}
Here full function for searching nr_of_pics:
public int findPictureNumber(String itemtitle) {
String query = "SELECT nr_of_pics FROM Items WHERE ItemTitle = '" + itemtitle + "'";
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(query, null);
int PicsNumber=0;
if (cursor.moveToFirst()) {
cursor.moveToFirst();
PicsNumber=Integer.parseInt(cursor.getString(0));
cursor.close();
return PicsNumber;
} else {
//wtf?
}
db.close();
return 0;
}
And the errors say as follows:
(1) table Items has no column named imgres
Error inserting colour=Castanho/Cortiça author=Fernando Brízio
imgres=furo category=Decoração title=Furo type=Taça date=2012
nr_of_pics=3 material=Castanho/Cortiça is_favourite=false
country=Portugal
android.database.sqlite.SQLiteException: table Items has no column named imgres (code 1): , while
compiling: INSERT INTO
Items(colour,author,imgres,category,title,type,date,nr_of_pics,material,is_favourite,country)
VALUES (?,?,?,?,?,?,?,?,?,?,?)
You do not give any exception but I think you have error in your SQL. You need to use ' instead of ".
Change your query as below.
String query = "SELECT nr_of_pics FROM Items WHERE ItemTitle = '" + itemtitle + "'";
It is clear that you don't have any column that named "imgres"!
You should modify your query
"INSERT INTO Items(colour,author,imgres,category,title,type,date,nr_of_pics,material,is_favourite,country)
VALUES (?,?,?,?,?,?,?,?,?,?,?)"
I am trying to set two databases.
After lunch the emulator, and trying to enter data, I have tried to find the exact reason of this error but without success.
I get an error:
05-17 16:23:06.410: E/AndroidRuntime(311): android.database.sqlite.SQLiteException: near "NULLbaby_age_month": syntax error: CREATE TABLE settings ( _id INTEGER PRIMARY KEY AUTOINCREMENT, uri_baby TEXT NOT NULL, baby_name TEXT NOT NULL, baby_gender TEXT NOT NULL, baby_age_year TEXT NOT NULLbaby_age_month TEXT NOT NULLbaby_age_day TEXT NOT NULL);
The Database Code is:
package com.tamar.efrat;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
public class DatBas {
public static final String KEY_ROWID = "_id";
public static final String KEY_SHOURS = "start_hour";
public static final String KEY_SMINUTE = "start_minute";
public static final String KEY_SDATE = "start_date";
public static final String KEY_AMOUNT = "amount";
public static final String KEY_SIDE = "side";
public static final String KEY_KIND = "kind";
public static final String KEY_ROW_BABY_ID = "_id";
public static final String KEY_BABY_IMAGE_PATH = "uri_baby";
public static final String KEY_BABY_NAME = "baby_name";
public static final String KEY_BABY_GENDER = "baby_gender";
public static final String KEY_BABY_BORN_DATE_YEAR = "baby_age_year";
public static final String KEY_BABY_BORN_DATE_MONTH = "baby_age_month";
public static final String KEY_BABY_BORN_DATE_DAY = "baby_age_day";
private static final String DATABASE_NAME = "TamatDB";
private static final String DATABASE_TABLE = "stop_watch_records";
private static final String DATABASE_TABLE_SETTINGS = "settings";
private static final int DATABASE_VERSION = 20;
private TamarDatabase thdb;
private static Context tcontext;
private SQLiteDatabase tdb;
private static class TamarDatabase extends SQLiteOpenHelper {
public TamarDatabase(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
#Override
public void onCreate(SQLiteDatabase db) {
String ctData = "CREATE TABLE " + DATABASE_TABLE + " ( "
+ KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ KEY_SHOURS + " TEXT NOT NULL, " + KEY_SMINUTE
+ " TEXT NOT NULL, " + KEY_SDATE + " TEXT NOT NULL, "
+ KEY_AMOUNT + " TEXT NOT NULL, " + KEY_SIDE
+ " TEXT NOT NULL, " + KEY_KIND + " TEXT NOT NULL );";
db.execSQL(ctData);
String ctSettings = "CREATE TABLE " + DATABASE_TABLE_SETTINGS
+ " ( " + KEY_ROW_BABY_ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ KEY_BABY_IMAGE_PATH + " TEXT NOT NULL, " + KEY_BABY_NAME
+ " TEXT NOT NULL, " + KEY_BABY_GENDER + " TEXT NOT NULL, "
+ KEY_BABY_BORN_DATE_YEAR + " TEXT NOT NULL"
+ KEY_BABY_BORN_DATE_MONTH + " TEXT NOT NULL"
+ KEY_BABY_BORN_DATE_DAY + " TEXT NOT NULL);";
db.execSQL(ctSettings);
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE_SETTINGS);
onCreate(db);
}
}
public DatBas(Context c) {
tcontext = c;
}
public DatBas open() throws SQLiteException {
thdb = new TamarDatabase(tcontext);
tdb = thdb.getWritableDatabase();
return this;
}
public void close() {
thdb.close();
}
public long createEntry(String sh, String sm, String sd, String at,
String tside, String tkind) {
ContentValues cv = new ContentValues();
cv.put(KEY_SHOURS, sh);
cv.put(KEY_SMINUTE, sm);
cv.put(KEY_SDATE, sd);
cv.put(KEY_AMOUNT, at);
cv.put(KEY_SIDE, tside);
return tdb.insert(DATABASE_TABLE, null, cv);
}
public long createEntrySettings(String bbdy, String bbdm, String bbdd,
String pt, String bg, String bfName) {
ContentValues cv2 = new ContentValues();
cv2.put(KEY_BABY_IMAGE_PATH, pt);
cv2.put(KEY_BABY_NAME, bfName);
cv2.put(KEY_BABY_GENDER, bg);
cv2.put(KEY_BABY_BORN_DATE_YEAR, bbdy);
cv2.put(KEY_BABY_BORN_DATE_MONTH, bbdm);
cv2.put(KEY_BABY_BORN_DATE_DAY, bbdd);
return tdb.insert(DATABASE_TABLE_SETTINGS, null, cv2);
}
public String getData() {
String[] columns = new String[] { KEY_ROWID, KEY_SHOURS, KEY_SMINUTE,
KEY_SDATE, KEY_AMOUNT, KEY_SIDE, KEY_KIND };
Cursor c = tdb.query(DATABASE_TABLE, columns, null, null, null, null,
null);
String results = "";
int iRaw = c.getColumnIndex(KEY_ROWID);
int iShours = c.getColumnIndex(KEY_SHOURS);
int iSminute = c.getColumnIndex(KEY_SMINUTE);
int iDate = c.getColumnIndex(KEY_SDATE);
int iAmount = c.getColumnIndex(KEY_AMOUNT);
int iSide = c.getColumnIndex(KEY_SIDE);
int iKind = c.getColumnIndex(KEY_KIND);
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
results = results + "the id is " + c.getString(iRaw)
+ " the sart hour is " + " " + c.getString(iShours)
+ " the start minute is " + " " + c.getString(iSminute)
+ " the start date is " + " " + c.getString(iDate)
+ " the amount is " + " " + c.getString(iAmount)
+ " the side is " + " " + c.getString(iSide)
+ " the kind is " + " " + c.getString(iKind) + "\n";
}
return results;
}
public String getDataSettings() {
String[] columns = new String[] { KEY_ROW_BABY_ID, KEY_BABY_IMAGE_PATH,
KEY_BABY_NAME, KEY_BABY_GENDER, KEY_BABY_BORN_DATE_YEAR,
KEY_BABY_BORN_DATE_MONTH, KEY_BABY_BORN_DATE_DAY };
Cursor c = tdb.query(DATABASE_TABLE_SETTINGS, columns, null, null,
null, null, null);
String results = "";
int iRawBabyId = c.getColumnIndex(KEY_ROW_BABY_ID);
int iBIPath = c.getColumnIndex(KEY_BABY_IMAGE_PATH);
int iBName = c.getColumnIndex(KEY_BABY_NAME);
int iGender = c.getColumnIndex(KEY_BABY_GENDER);
int iBBDateYear = c.getColumnIndex(KEY_BABY_BORN_DATE_YEAR);
int iBBDateMonth = c.getColumnIndex(KEY_BABY_BORN_DATE_MONTH);
int iBBDateDay = c.getColumnIndex(KEY_BABY_BORN_DATE_DAY);
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
results = results + " the kind is " + " " + c.getString(iRawBabyId)
+ " the kind is " + " " + c.getString(iBIPath)
+ " the kind is " + " " + c.getString(iBName)
+ " the kind is " + " " + c.getString(iGender)
+ " the kind is " + " " + c.getString(iBBDateYear)
+ " the kind is " + " " + c.getString(iBBDateMonth)
+ " the kind is " + " " + c.getString(iBBDateDay) + "\n";
}
return results;
}
public DatBas delete() {
tdb.delete(DATABASE_TABLE, null, null);
tdb.delete(DATABASE_TABLE_SETTINGS, null, null);
return null;
}
}
forget to add , in query ...
TEXT NOT NULL,baby_age_month
AND
TEXT NOT NULL,baby_age_day
CREATE TABLE settings ( _id INTEGER PRIMARY KEY AUTOINCREMENT, uri_baby TEXT NOT NULL, baby_name TEXT NOT NULL, baby_gender TEXT NOT NULL, baby_age_year TEXT NOT NULL,baby_age_month TEXT NOT NULL,baby_age_day TEXT NOT NULL);
having small error : forgetted ( , )separater
CREATE TABLE settings ( _id INTEGER PRIMARY KEY AUTOINCREMENT, uri_baby TEXT NOT NULL,
baby_name TEXT NOT NULL, baby_gender TEXT NOT NULL, baby_age_year TEXT NOT
NULL, baby_age_month TEXT NOT NULL,baby_age_day TEXT NOT NULL);