sqlite

How to automatically set timestamp in room SQLite database?

天涯浪子 提交于 2020-01-24 22:08:41
问题 I am trying to have SQLite create automatic timestamps with CURRENT_TIMESTAMP. I took the liberty of using Google's code: // roomVersion = '2.2.2' @Entity public class Playlist { @PrimaryKey(autoGenerate = true) long playlistId; String name; @Nullable String description; @ColumnInfo(defaultValue = "normal") String category; @ColumnInfo(defaultValue = "CURRENT_TIMESTAMP") String createdTime; @ColumnInfo(defaultValue = "CURRENT_TIMESTAMP") String lastModifiedTime; } @Dao interface PlaylistDao {

How to automatically set timestamp in room SQLite database?

早过忘川 提交于 2020-01-24 22:08:07
问题 I am trying to have SQLite create automatic timestamps with CURRENT_TIMESTAMP. I took the liberty of using Google's code: // roomVersion = '2.2.2' @Entity public class Playlist { @PrimaryKey(autoGenerate = true) long playlistId; String name; @Nullable String description; @ColumnInfo(defaultValue = "normal") String category; @ColumnInfo(defaultValue = "CURRENT_TIMESTAMP") String createdTime; @ColumnInfo(defaultValue = "CURRENT_TIMESTAMP") String lastModifiedTime; } @Dao interface PlaylistDao {

Error inserting data to SQLite database

橙三吉。 提交于 2020-01-24 21:39:01
问题 I have a method to create a Farm object and insert it into the database, the method is as follows: public Farm createFarm(String name) { SQLiteDatabase database = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(FavegaOpenHelper.COLUMN_NAME, name); long insertId = database.insert(FavegaOpenHelper.TABLE_FARMS, null, values); Cursor cursor = database.query(FavegaOpenHelper.TABLE_FARMS, new String[] {COLUMN_ID, COLUMN_NAME}, FavegaOpenHelper.COLUMN_ID + " = " +

Error inserting data to SQLite database

早过忘川 提交于 2020-01-24 21:38:05
问题 I have a method to create a Farm object and insert it into the database, the method is as follows: public Farm createFarm(String name) { SQLiteDatabase database = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(FavegaOpenHelper.COLUMN_NAME, name); long insertId = database.insert(FavegaOpenHelper.TABLE_FARMS, null, values); Cursor cursor = database.query(FavegaOpenHelper.TABLE_FARMS, new String[] {COLUMN_ID, COLUMN_NAME}, FavegaOpenHelper.COLUMN_ID + " = " +

How can I store Date and Time in SQLite Database when I pick date and time via date picker and time picker?

和自甴很熟 提交于 2020-01-24 21:10:50
问题 I am implementing date picker and time picker functionality after pick date and time I want to store it in SQLite ? Currently I am storing Date and Time using getting value from edit text box and convert into String and Save into SQLite . Is this right way to store date and time like this ? EditText Reminder_Time,Followup_date; Reminder_Time.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Calendar mcurrentTime = Calendar.getInstance(); int hour =

How to store a PDF file in SQLite Data base in Android

帅比萌擦擦* 提交于 2020-01-24 20:46:07
问题 Actually, I want to download a PDF file in our Android phone and don't want to give the permission to open the PDF file in PC when he try to open by connecting the Phone to PC. so I want to go with storing the PDF file in SQLite Data Base solution. My question is... Is it possible to store PDF file in SQLite database? If yes, how? Or is there any other way to implement same functionality? Please Help me... Thanks... 回答1: You can. Simply read all the bytes of the pdf file and store in the blob

Print out the result of sqlite database query with a format

荒凉一梦 提交于 2020-01-24 19:31:08
问题 I have this student db with four columns: first_name, middle_name, last_name, school, birth_year . I have successfully read the content of the db using SELECT statement, but here's where I got stuck at: How do I print the query result with the format like this: first_name middle_name(if available) last_name was born in birth_year ? So for every row in the query the intended result should do this: Aida Blue was born in 1985 . For now if I run print(all_rows) the code will print the query

Cursor returns wrong values - sqlite - Android

喜欢而已 提交于 2020-01-24 19:03:10
问题 I'm developping an Sms Application, I'm trying to get the last sms from each conversation. here's my SQL Statement : SELECT MAX(smsTIMESTAMP) AS smsTIMESTAMP,_id, smsID, smsCONID, smsMSG, smsNUM, smsREAD, smsTYPE, smsSHORTMSG, COUNT(*) AS smsNUMMESSAGES FROM sms GROUP BY smsCONID ORDER BY smsTIMESTAMP desc I ran the query in SQLite Expert and I get the right response : however when I run it in my app I get : Here's my table Here's My Datamanipulator Class : public class DataManipulator {

Cursor returns wrong values - sqlite - Android

风流意气都作罢 提交于 2020-01-24 19:02:16
问题 I'm developping an Sms Application, I'm trying to get the last sms from each conversation. here's my SQL Statement : SELECT MAX(smsTIMESTAMP) AS smsTIMESTAMP,_id, smsID, smsCONID, smsMSG, smsNUM, smsREAD, smsTYPE, smsSHORTMSG, COUNT(*) AS smsNUMMESSAGES FROM sms GROUP BY smsCONID ORDER BY smsTIMESTAMP desc I ran the query in SQLite Expert and I get the right response : however when I run it in my app I get : Here's my table Here's My Datamanipulator Class : public class DataManipulator {

send a row from one listview to another listview

旧城冷巷雨未停 提交于 2020-01-24 18:47:25
问题 i have two listviews in the same activity one of them have elements the other one is empty and i want to send any element to the second lisview by long click and i want the elements to do the same as it is in the first listview(open an activity) here is my code and please tell what to do: MainActivity.java import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle;