Android :: Finding Auto Incremented Values From An INSERT OR IGNORE Statement In SQLite
Sep 25, 2010
I have a table called "images":
CODE:.........
On inserting a row, I'd like the URL column to be unique. At the same time, I'd like to find out the id of the row with that URL.
INSERT OR IGNORE images (url, caption) VALUES ("http://stackoverflow.com", "A logo"); SELECT last_insert_rowid(); -- returns the id iff there was an insert.
Of course, I'd like to do it as quickly as possible, though my first thought was along the the lines of the following pseudo code:
CODE:...........
But this seems hopelessly inefficient.
What is the most performant way of getting the Auto incremented row id from an INSERT OR IGNORE statement.
View 1 Replies
Aug 13, 2010
I'm trying to insert values on Android SQLite Database. The question is, Iḿ trying to insert a word, the table has 3 columns, ID, WORD, COUNT. When I insert a word in the database, some method will verify if this word exists on the database. If yes, it will increment the value of COUNT for this word.
View 1 Replies
View Related
Jul 23, 2010
I'm developing an application that tracks the user's current position and stores it into a SQLite database. Everything works fine, but now I have the problem when querying the database for a track with more than 1000 records it takes nearly 1.5 minutes. On my Desktop it just takes 1 second. I know it's a query with many subselects but I wasn't able to get the right result another way. In my opinion this belongs to the aggregate functions like avg() and sum().
Here's my query:.................
View 3 Replies
View Related
Mar 23, 2010
I have a query that selects rows in a ListView without having a limit. But now that i have implemented a SharedPreferences that the user can select how much rows will be displayed in the ListView, my SQLite query doesnt work. Im passing the argument this way:
CODE:...................
View 1 Replies
View Related
Aug 13, 2010
When creating my SQLite database in Android I set the database locale - db.setLocale(new Locale("cz_CZ")). This is a Czech locale. A SELECT statement works and takes the locale into account, for example:
SELECT * from table WHERE name='sctzy' COLLATE LOCALIZED
But using LIKE will fail: SELECT * from table WHERE name LIKE '%sctzy%' COLLATE LOCALIZED
BTW. There is no java.text.Normalized class in Android. I thought I could make a second column with a normalized text, stripped of special characters, which would be used for searching - but I am missing a class or way how to normalize the String.
View 1 Replies
View Related
Apr 25, 2009
Anyone working with big sqlite tables and trying to match rows using patterns (for example for autocomplete purposes) ? recently i played with LIKE statement and it seems it will never use table index (if any), you have to use GLOB instead. but....... the weird thing is that you cannot use selectionParams in your query: you have to specify your pattern in selection like:
CODE:........
My words table has two TEXT columns: 'key' and 'value' and index on 'key'
For example: i have table with ~28000 rows and when using selectionParams my query took 1500 ms and without selectionParams 20 ms does it have anything to do with android or its sqlite weird feature?
View 2 Replies
View Related
May 8, 2010
I am trying to update a datetime column in an android sqlite db to use international date format (yyyy-mm-dd) instead of the current format (mm/dd/yyyy). I want to use the sqlite date() function to reformat the current value of the column. I thought it would be as simple as the following: update tblename set thedate = date(thedate)
But the above does not work.
How would i write the sql statement to accomplish this?
View 1 Replies
View Related
May 11, 2012
I'm trying to select the items that have a expiration date >= that an selected date.I'm using the format yyyy-mm-dd, and this is my sql statement:
String sql = "SELECT _id, item, value, finalDate FROM "+DATABASE_TABLE+" WHERE date(finalDate) >= date("+selectedDate+")";
This query always result a "full select" in my database, as if there were no conditions.Some useful information:
selectDate is a String which have a date in yyyy-mm-dd format
I'm executing the query like this:
return db.rawQuery(sql,null);
View 3 Replies
View Related
Oct 28, 2009
For my application, I am trying to add entries without having a duplicate entry, and if there are a duplicate notify the user and have him try again. Using SQLite, which I know very very little about, I have tried these two ways and want to know which one is better, more efficient or a better way to develop it? First way:
db.execSQL("INSERT INTO " + DatabaseHelper.DATABASE_TABLE +
"(LATITUDE, LONGITUDE, RATING) SELECT " + latitude + ", " + longitude + ", " + rating +
" WHERE NOT EXISTS (SELECT 1 FROM " + DatabaseHelper.DATABASE_TABLE +
" WHERE LATITUDE = " + latitude + " AND LONGITUDE = " + longitude + ")");
Second way:
long id = -1;
try { id = db.compileStatement(
"SELECT COUNT(*) FROM " + DatabaseHelper.DATABASE_TABLE
+ " WHERE LATITUDE = " + latitude
+ " AND LONGITUDE = " + longitude)
.simpleQueryForLong();
} catch (NullPointerException e) { return -1;
} return id;
The first way, either inserts or ignores the values, I check by doing so, storing the row-count of the rows into a variable before the call, call that function, and then check its results. If the results is not higher than it was before the call, the insert was made ignored, prompt the user with the 'values exist' message. (Very sloppy, I know but desperate times calls for desperate measures). The second way, returns the actual count of rows that match the numbers I want to store, if the number returned greater than 1, prompt the user with the 'values exist' message. I have been going back and forth, trying different ways but I do not know how to set up SQLite to have UNIQUE pairs, which I was told would be the easiest.
View 3 Replies
View Related
Aug 8, 2010
I have a database with tables called box, item, and box_contents and I want to get any item that is contained in the box_content table (all items, but discard the ones that arent in the box_contents table). What would be the correct sqllite syntax for this?
View 2 Replies
View Related
Sep 16, 2010
I want to insert a String value call temp but I don't seems to get it working for the INSERT INTO statement. Anything wrong with the code? This is the initialization to create table and insert some default values into the table if the database doesn't exist. Code...
View 4 Replies
View Related
Nov 1, 2010
I have a database (stored on a Class 6 SD card) with a single empty table (5 columns). There is an index on each column. Performing a single INSERT statement (whether using an SQLiteStatement or calling SQLiteDatabase.insert()) takes about 800ms on my N1 (2.2.1). The INSERT statement does NOT do anything fancy (like subselects). Is there any way to speed this up?
View 4 Replies
View Related
Sep 10, 2010
I need to insert 1000 rows into SQLite DB. Each row has 12 columns, text and numbers, none is big. It takes literraly minutes to insert all 1000 items. I use SQLiteDatabase.insert to insert each row.
What can I do to improve this performance?
View 5 Replies
View Related
Nov 17, 2010
I'm trying to insert text into my SQLite database, but for some reason it doesn't work. It never executes..
Code below (this is my function that I'm calling):
public void setInfo(final String tableName, final int id, final String title, final String time, final String content) code...
View 1 Replies
View Related
Apr 16, 2009
Say, we have a table created as:
create table notes (_id integer primary key autoincrement, created_date date)
To insert a record, I'd use
ContentValues initialValues = new ContentValues();
initialValues.put("date_created", "");
long rowId = mDb.insert(DATABASE_TABLE, null, initialValues);
But how to set the date_created column to "now"? To make it clear, the
initialValues.put("date_created", "datetime('now')");
Is not the right solution. It just sets the column to "datetime('now')" text.
View 6 Replies
View Related
Sep 15, 2010
I have array list of geopoints
List<GeoPoint> geoPointsArray = new ArrayList<GeoPoint>();
I want to put geoPointsArray array in to SQLite database and then fetch the data back as an array.
Now I use ContentValues for insert into array as:
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_TIME, time);
db.insert(tableName, null, initialValues);
View 2 Replies
View Related
Aug 7, 2010
In Android is it possible to insert a sqlite timestamp into a database using ContentValues?
When I try to add it using something like
ContentValues args = new ContentValues();
args.put(MY_DATE,my_date);
I get an error telling me that my_date needs to be a string
View 1 Replies
View Related
Jul 5, 2010
I wanna set a textview as the values from SQLite when I click the ListView Here is my way...
View 1 Replies
View Related
May 22, 2010
In my project, I would like to create a database with single table. I would also like to insert data on this table from word or excel document. is it possible? if so please how can I do it? some code snippets would be of great help. I have four different activities which I would like them to interact with this single table. the first is the main activity and its purpose is just to launch the other three activities according to user choice. so it has no interaction with the DB. but the other three activities will read from the table whenever called. Can you please tell me how to call the dbhelper on these activities? I am unable to do this and I am currently creating one db per each activity which is not the optimal way.
View 1 Replies
View Related
Jun 21, 2010
i have a problem with double values i need to store in an android homed sqlite database. since these double values represent gps values (lat & lng), i really NEED an absolute precision down to the 9th number after the comma.when reading lng from this table into some (java) double variable, i get a value like "0.999956837" - this renders the values pretty useless to me.is there a way to enforce the precision i need other than storing the values as "text" fields (what would make expensive casts neccessary) or storing them as integers (meaning i need to multiply/divide at each write/read-op)?
View 2 Replies
View Related
Apr 2, 2010
I am currently in the process of creating an application that records current location of a mobile device in intervals, displaying the route as a coloured line on the device in real-time. At the same time the application is storing the longitude and latitude in a SQLite database as I want the user to be able to bring up that specific route again.The route has a primary key and each waypoint is linked to that route by a foreign key. What would be the easiest way to display the saved route on the map?
View 2 Replies
View Related
Jul 10, 2010
I have got an edit text where I want that when someone insert her values it will narrow his option's. the options are stored in a DB (up to 1200 values to one editbox ). i cant get the concept of how to do it.
View 1 Replies
View Related
Oct 16, 2012
I have a rooted Nexus s on 4.1.2
I am wondering if there is an app that can power off my device when battery drops to a certain level. Tasker's shutdown task not seems working for me.
View 3 Replies
View Related
Oct 30, 2013
How to make a module which sets the auto brightness to custom values like on cm or codename?
View 2 Replies
View Related
Jul 25, 2010
I have an Android SQLite/ContentProvider problem that I have been beating my head against the wall for over the past 3 hours.
View 1 Replies
View Related
Apr 9, 2014
I want to ask where does the defaults values of memory min-free values of a Rom reside? I mean what file I would have to edit to edit those values?
View 1 Replies
View Related
Nov 21, 2009
My Treo had this option, and so did the Hero that I had for a few weeks. When a call is coming in, there is an option on the screen to ignore the call and reply with a text message. I realize this can be done just by pressing the "hangup" button and then unlocking the phone, and then opening the SMS app, finding the person's contact info, and replying, but a one-button process would be really nifty.If there is not such an app, where's a good place to start learning how to write one?
View 6 Replies
View Related
Jun 4, 2010
I would like to have my android app ignore flip, is that possible? I added android:screenOrientation="portrait" to all of my activities but that is about as effective as the close door button on an elevator.
View 1 Replies
View Related
Feb 16, 2010
I have a strange issue. I am new to java/android but come from a programming background maybe I am just missing or doing something stupid with syntax here. I have a string variable called reportlength
String reportlength;
I then go: reportlength = intent.getExtras().getString("ReportLengt");
Now in my debug console for the variable reportlength it has it set as "d" (that is the correct value it should have)
At this point I have my if statement:
CODE:......................
View 3 Replies
View Related
Jul 20, 2010
So I've got this code (updated for solution).
CODE:.............
The problem I was having was that one of the TextViews would turn grey when it wasn't supposed to. I tried fixing it by always setting the text to black again, but that turned every single one of them grey.
Until I tried:
CODE:................
Don't know why the latter works when setting text grey, but there it is. I guess I'm just a little retarded.
View 7 Replies
View Related