android-sqlite

why i fail to create this table on android SQLite?

这一生的挚爱 提交于 2019-12-12 10:24:51
问题 I created 4 table on my app. Below is the creation of the last table - this is the query that i get after the parse of the string CREATE TABLE IF NOT EXISTS TABLE_1 (ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,PK_Person TEXT NOT NULL, FOREIGN KEY ( PK_Person ) REFERENCES TABLE_2 , COLUMN_INDEX_AS_TEXT TEXT NOT NULL, FOREIGN KEY( COLUMN_INDEX_AS_TEXT ) REFERENCES TABLE_3 ); When i run this method of creation - i get an exception that the value near the COLUMN_INDEX_AS_TEXT is Error Code : 1

How to select data between two dates from sqlite db in dd-mm-yyyy format?

允我心安 提交于 2019-12-12 08:39:09
问题 i have date column in my database in dd-mm-yyyy format. i want to search the data between two dates. i tried SELECT * FROM t_data where orderdate between '01-05-2012 00:00:00' and '31-05-2012 23:59:59' and SELECT * FROM t_data where orderdate >= '05-05-2012' and orderdate <='31-05-2012' How to resolve this issue? 回答1: use : select * from tbl_name where Attribute_name between 'yyyy-mm-dd' and 'yyyy-mm-dd'; here Attribute_name is date_time column name example : select * from tbl_node where

Insert in SQLite Database android

戏子无情 提交于 2019-12-12 08:36:43
问题 im new on Android. I have some trouble with the insert statement in the database, when im running the application the values have not been inserted. Please someone can help.. public class DatabaseAdapter extends SQLiteOpenHelper { // Database attributes public static final String DB_NAME = "MoneyManagerSystemTr"; public static final int DB_VERSION = 1; // Table attributes public static final String TABLE_ACCOUNT = "account_table"; //Account Table public static final String KEY_BANKNAME =

android.database.CursorIndexOutOfBoundsException

十年热恋 提交于 2019-12-12 07:59:34
问题 The data access code in my Android app raises an exception. Here is the code that causes the exception: String getPost = "SELECT * FROM " + TABLE_POST + ";"; Cursor result = getReadableDatabase().rawQuery(getPost, null); List posts = new ArrayList();{ Log.d("count", result.getCount() + " post rows"); while (result != null && result.moveToNext()); Post post = new Post(); post.setPostId(result.getInt(0)); posts.add(post); .... } The exception raised is: android.database

How to restore Sqlite database after backup Android

馋奶兔 提交于 2019-12-12 06:54:26
问题 I searched a lot about backup/restore Sqlite database i found code to copy sqlite file to SD card this is the code private void exportDB() { try { File sd = Environment.getExternalStorageDirectory(); File data = Environment.getDataDirectory(); if (sd.canWrite()) { String currentDBPath = "//data//" + "<package name>" + "//databases//" + "<db name>"; String backupDBPath = "<destination>"; File currentDB = new File(data, currentDBPath); File backupDB = new File(sd, backupDBPath); FileChannel src

Auto incrementing 'id' value when inserting into sqlite

淺唱寂寞╮ 提交于 2019-12-12 06:49:55
问题 I'm trying to figure out how to get id value into database in an auto increment way, i.e it sets it self automatically depending on what entry is. here is how my DatabaseHandler code looks at the moments (only important bits) // Adding new appointment void addAppointment(Appointment appointment) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(KEY_ID, appointment.getId()); // Appointment ID values.put(KEY_TITLE, appointment.getTitle());

Android - Fragment containg ListView, CursorAdapter using SQLite

旧街凉风 提交于 2019-12-12 06:19:47
问题 I have a Fragment that contains a listView and button. When the button is clicked a DialogFragment will open where the user can input data into EditText fields. Once the user presses setPositiveButton it calls method in DBHelper to insert data into SQLite then dismisses dialogFragment My problem, once it dismisses the ListView should update with the new input listing all future inputs. However I cant seem to get it to work. I have made a CursorAdapter. Does anyone know why it isnt working

How to access and update Sqlite db file stored locally[asset folder] in project file using cordova

若如初见. 提交于 2019-12-12 04:59:07
问题 I have a sqlite db file stored in assets folder of my cordova project ,which i want to access inside my application and also want to update the db. So far i had a look on i found there cordova sqlite plug-in which can create a sqlite db and update it,but not sure how to update a existing db file from asset folder in cordova Here is my below code: <!DOCTYPE html> <html> <head> <title>Storage Example</title> <script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script> <script

Sqlite3 is not inserting multiple rows in order

[亡魂溺海] 提交于 2019-12-12 04:58:11
问题 I am working with node js application and database is sqlite3 (2.15.8). I am using sqlite3 module . In this I have to insert rows in order. I have table tests in which rows should be inserted as the same order in which they coming in loop. My code is as follows: To create Table: GLOBAL.db1 = new sqlite3.Database(APPDATA+'/xyz/mydb.db'); var check; db1.serialize(function() { db1.run("CREATE TABLE IF NOT EXISTS tests (id INTEGER NOT NULL PRIMARY KEY , parent_name varchar(255), test_name varchar

How to retrieve all the rows in my DB?

人盡茶涼 提交于 2019-12-12 04:38:15
问题 Good day sorry for asking these question. Hope somebody help me solve my problem. Also hoping that my question is clear enough so that somebody will not down vote it. I'm just new to this android thing. I only watch and followed some tutorials to get these code done and asking question here in stackoverflow when things gets hard for me to comprehend. this my current code and it only fetches the 1st row but it didn't display it in my CardView? How could I fetch all the rows then display all