Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
SQLite query using a UUID key
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
SnowDrifter  
View profile  
 More options Dec 9 2007, 6:22 pm
From: SnowDrifter <amacp...@gmail.com>
Date: Sun, 9 Dec 2007 15:22:58 -0800 (PST)
Local: Sun, Dec 9 2007 6:22 pm
Subject: SQLite query using a UUID key
I am having some issues getting my database query working since I
changed the primary key from an int to a UUID. I wanted to use a more
unique identifier than an auto incremented int so I chose UUID
(java.util.UUID). My problem, besides being uneducated in SQLite, is
that when I try to query a row I get an error.

This is how I set it up:

UUID locationID = UUID.randomUUID();
ContentValues initialValues = new ContentValues();
initialValues.put("rowid", locationID.toString());
//...other stuff...//
db.insert(DATABASE_TABLE_LOCATIONS, null, initialValues);

Then on a query I do this:

Cursor c =
            db.query(true, DATABASE_TABLE, new String[] {
                "rowid", "stuff", "things"}, "rowid=" + rowId, null,
null, null, null);

The error is occurring on the "rowid=" + rowId part of the call since
I am getting UUID values of "129e3178-2047-416b-8993-b9b2cf9d4f3e" for
instance I think that the query is disliking the "-" values and giving
me an SQLite Exception of:

Unrecognized token: "416b", while compiling SELECT COUNT(*) FROM
(SELECT DISTINCT rowid, stuff, things FROM table WHERE
rowid=129e3178-2047-416b-8993-b9b2cf9d4f3e).

Is there a way to create a where clause that can use that UUID data?
do I need to clean out the "-"'s  to make it work?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rick Genter  
View profile  
 More options Dec 9 2007, 7:06 pm
From: Rick Genter <rick_gen...@comcast.net>
Date: Sun, 9 Dec 2007 16:06:13 -0800
Local: Sun, Dec 9 2007 7:06 pm
Subject: Re: [android-developers] SQLite query using a UUID key
On Dec 9, 2007, at 3:22 PM, SnowDrifter wrote:

> The error is occurring on the "rowid=" + rowId part of the call since
> I am getting UUID values of "129e3178-2047-416b-8993-b9b2cf9d4f3e" for
> instance I think that the query is disliking the "-" values and giving
> me an SQLite Exception of:

> Unrecognized token: "416b", while compiling SELECT COUNT(*) FROM
> (SELECT DISTINCT rowid, stuff, things FROM table WHERE
> rowid=129e3178-2047-416b-8993-b9b2cf9d4f3e).

> Is there a way to create a where clause that can use that UUID data?
> do I need to clean out the "-"'s  to make it work?

It's a string; you have to quote it. The WHERE clause should read

WHERE rowid = '129e3178-2047-416b-8993-b9b2cf9d4f3e'

--
Rick Genter
rick_gen...@comcast.net


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
SnowDrifter  
View profile  
 More options Dec 9 2007, 9:46 pm
From: SnowDrifter <amacp...@gmail.com>
Date: Sun, 9 Dec 2007 18:46:29 -0800 (PST)
Local: Sun, Dec 9 2007 9:46 pm
Subject: Re: SQLite query using a UUID key
That did the trick. Thanks for the help.

Just to make this complete, here is what I added to the query:

db.query(true, DATABASE_TABLE, new String[] {
                "rowid", "stuff", "things"}, "rowid='" + rowId + "'",
null, null, null, null);

thats a single quote after the = and I added a single quote in quotes
at the end.

Thanks Rick!

On Dec 9, 5:06 pm, Rick Genter <rick_gen...@comcast.net> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
baker  
View profile  
 More options Dec 10 2007, 5:55 am
From: baker <craigbba...@gmail.com>
Date: Mon, 10 Dec 2007 02:55:42 -0800 (PST)
Local: Mon, Dec 10 2007 5:55 am
Subject: Re: SQLite query using a UUID key
Can I suggest that you might find it helpful to use a sequence based
primary key and add a second column for the UUID. The UUID can then be
used for global identification of the data and the sequence based
primary key can be used for local row based lookups. It all depends on
your applications usage but this is a pattern I have found useful at
times.

Craig.

On Dec 10, 1:46 pm, SnowDrifter <amacp...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »