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.
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?
> 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'
> > 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'
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:
> 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:
> > 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