WITHOUT ROWID tables

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

WITHOUT ROWID tables

Wayne Collins
My first posting so I hope I get the etiquette correct.

1st question How can I determine from a C-program if a table was
generated with the "WITHOUT ROWID" option? I have an application where
it is important to know if a table has a rowid or not.

2nd Question After a database is defined and the tables created, I have
an application which automatically generates C++ DAO and DTO objects for
each table. At run time, I'd like to be certain that the schema and the
DAO/DTO match. I had thought to use the schema_version pragma but it
increments when the db is VACUUMED. Is there some hidden cookie or value
I can use that I have overlooked?

Thanks in advance


_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: WITHOUT ROWID tables

Richard Hipp-3
On 2/14/20, Wayne Collins <[hidden email]> wrote:
> My first posting so I hope I get the etiquette correct.
>
> 1st question How can I determine from a C-program if a table was
> generated with the "WITHOUT ROWID" option? I have an application where
> it is important to know if a table has a rowid or not.

To determine if table XYZ is a WITHOUT ROWID table, run "PRAGMA
index_info('XYZ');".  If you get back one or more rows, then XYZ is a
WITHOUT ROWID table.  If you get back no rows, then XYZ is a rowid
table.


>
> 2nd Question After a database is defined and the tables created, I have
> an application which automatically generates C++ DAO and DTO objects for
> each table. At run time, I'd like to be certain that the schema and the
> DAO/DTO match. I had thought to use the schema_version pragma but it
> increments when the db is VACUUMED. Is there some hidden cookie or value
> I can use that I have overlooked?
>

There are no magic cookies that change with the schema but not with VACUUM.

Perhaps you could store a strong hash of the sqlite_master.sql column
for each table with your C++ objects, then compare the hash upon
reconnect to see if anything has changed.

--
D. Richard Hipp
[hidden email]
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: WITHOUT ROWID tables

skywalk
>
> To determine if table XYZ is a WITHOUT ROWID table, run "PRAGMA
> index_info('XYZ');".  If you get back one or more rows, then XYZ is a
> WITHOUT ROWID table.  If you get back no rows, then XYZ is a rowid
> table.
>
Confused...What if I made an index on a ROWID table?
CREATE INDEX "Z" ON "DOC" ("n_id");
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: WITHOUT ROWID tables

Simon Slavin-3
On 15 Feb 2020, at 3:14pm, [hidden email] wrote:

>> To determine if table XYZ is a WITHOUT ROWID table, run "PRAGMA
>> index_info('XYZ');".  If you get back one or more rows, then XYZ is a
>> WITHOUT ROWID table.  If you get back no rows, then XYZ is a rowid
>> table.
>>
> Confused...What if I made an index on a ROWID table?
> CREATE INDEX "Z" ON "DOC" ("n_id");

The parameter in index_info() is normally the name of an index.  So if you create an index "Z" and ask for index_info("Z") you will get information on that index.

If you create a WITHOUT ROWID table with name 'Y", and ask for index_info("Y") you will get information on the primary key of that table.

If both exist, you get information about the index.

Simon
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: WITHOUT ROWID tables

skywalk
Ok, not ideal. Still confusing, but I see the difference.
For my code, I know the schemas. I guess a SQL builder could offer up query
options to the user browsing new databases.

On Sat, Feb 15, 2020 at 11:26 AM Simon Slavin <[hidden email]> wrote:

> On 15 Feb 2020, at 3:14pm, [hidden email] wrote:
>
> >> To determine if table XYZ is a WITHOUT ROWID table, run "PRAGMA
> >> index_info('XYZ');".  If you get back one or more rows, then XYZ is a
> >> WITHOUT ROWID table.  If you get back no rows, then XYZ is a rowid
> >> table.
> >>
> > Confused...What if I made an index on a ROWID table?
> > CREATE INDEX "Z" ON "DOC" ("n_id");
>
> The parameter in index_info() is normally the name of an index.  So if you
> create an index "Z" and ask for index_info("Z") you will get information on
> that index.
>
> If you create a WITHOUT ROWID table with name 'Y", and ask for
> index_info("Y") you will get information on the primary key of that table.
>
> If both exist, you get information about the index.
>
> Simon
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: WITHOUT ROWID tables

curmudgeon
Does
sqlite3_table_column_metadata(db,dbName,tblName,"rowid",0,0,0,0,0)==SQLITE_OK
return false if table tblName is a without rowid table?

https://sqlite.org/c3ref/table_column_metadata.html





--
Sent from: http://sqlite.1065341.n5.nabble.com/
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: WITHOUT ROWID tables

Thomas Kurz
In reply to this post by skywalk
Wouldn't be something like

SELECT sql FROM sqlite_master WHERE tbl_name='?' AND type='table'
contains "WITHOUT ROWID"

be sufficient?

Just being curious.

----- Original Message -----
From: [hidden email] <[hidden email]>
To: SQLite mailing list <[hidden email]>
Sent: Saturday, February 15, 2020, 18:06:47
Subject: [sqlite] WITHOUT ROWID tables

Ok, not ideal. Still confusing, but I see the difference.
For my code, I know the schemas. I guess a SQL builder could offer up query
options to the user browsing new databases.

On Sat, Feb 15, 2020 at 11:26 AM Simon Slavin <[hidden email]> wrote:

> On 15 Feb 2020, at 3:14pm, [hidden email] wrote:

> >> To determine if table XYZ is a WITHOUT ROWID table, run "PRAGMA
> >> index_info('XYZ');".  If you get back one or more rows, then XYZ is a
> >> WITHOUT ROWID table.  If you get back no rows, then XYZ is a rowid
> >> table.
> >>
> > Confused...What if I made an index on a ROWID table?
> > CREATE INDEX "Z" ON "DOC" ("n_id");

> The parameter in index_info() is normally the name of an index.  So if you
> create an index "Z" and ask for index_info("Z") you will get information on
> that index.

> If you create a WITHOUT ROWID table with name 'Y", and ask for
> index_info("Y") you will get information on the primary key of that table.

> If both exist, you get information about the index.

> Simon
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: WITHOUT ROWID tables

J. King-3
On February 15, 2020 2:14:30 p.m. EST, Thomas Kurz <[hidden email]> wrote:

>Wouldn't be something like
>
>SELECT sql FROM sqlite_master WHERE tbl_name='?' AND type='table'
>contains "WITHOUT ROWID"
>
>be sufficient?
>
>Just being curious.
>
>----- Original Message -----
>From: [hidden email] <[hidden email]>
>To: SQLite mailing list <[hidden email]>
>Sent: Saturday, February 15, 2020, 18:06:47
>Subject: [sqlite] WITHOUT ROWID tables
>
>Ok, not ideal. Still confusing, but I see the difference.
>For my code, I know the schemas. I guess a SQL builder could offer up
>query
>options to the user browsing new databases.
>
>On Sat, Feb 15, 2020 at 11:26 AM Simon Slavin <[hidden email]>
>wrote:
>
>> On 15 Feb 2020, at 3:14pm, [hidden email] wrote:
>
>> >> To determine if table XYZ is a WITHOUT ROWID table, run "PRAGMA
>> >> index_info('XYZ');".  If you get back one or more rows, then XYZ
>is a
>> >> WITHOUT ROWID table.  If you get back no rows, then XYZ is a rowid
>> >> table.
>> >>
>> > Confused...What if I made an index on a ROWID table?
>> > CREATE INDEX "Z" ON "DOC" ("n_id");
>
>> The parameter in index_info() is normally the name of an index.  So
>if you
>> create an index "Z" and ask for index_info("Z") you will get
>information on
>> that index.
>
>> If you create a WITHOUT ROWID table with name 'Y", and ask for
>> index_info("Y") you will get information on the primary key of that
>table.
>
>> If both exist, you get information about the index.
>
>> Simon
>> _______________________________________________
>> sqlite-users mailing list
>> [hidden email]
>> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
>_______________________________________________
>sqlite-users mailing list
>[hidden email]
>http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
>_______________________________________________
>sqlite-users mailing list
>[hidden email]
>http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

CREATE TABLE t(
c TEXT DEFAULT 'WITHOUT ROWID'
-- this comment mentions something about WITHOUT ROWID
);


Contrived, no question, but possible.
--
J. King
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: WITHOUT ROWID tables

Bernardino Ramos
In reply to this post by Wayne Collins

I've got no rows for both with and without rowid tables:

SQLite version 3.27.2 2019-02-25 16:06:06
Enter ".help" for usage hints.
sqlite> create table t1(name);
sqlite> create table t2(name primary key, phone) without rowid;
sqlite> pragma index_info(t1);
sqlite> pragma index_info(t2);
sqlite> pragma index_info('t1');
sqlite> pragma index_info('t2');
sqlite> .tab
t1  t2
sqlite> select * from t1 where rowid=1;
sqlite> select * from t2 where rowid=1;
Error: no such column: rowid


>
> To determine if table XYZ is a WITHOUT ROWID table, run "PRAGMA
> index_info('XYZ');".  If you get back one or more rows, then XYZ is a
> WITHOUT ROWID table.  If you get back no rows, then XYZ is a rowid
> table.
>
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: WITHOUT ROWID tables

Simon Slavin-3
On 16 Feb 2020, at 6:00pm, Bernardo Ramos <[hidden email]> wrote:

> I've got no rows for both with and without rowid tables:

<https://sqlite.org/pragma.html#pragma_index_info>

" as of SQLite version 3.30.0 on 2019-10-04 "
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: WITHOUT ROWID tables

Peter da Silva-2
In reply to this post by J. King-3
If you have control over the schema you can put a schema version in some
table.

On Sat, Feb 15, 2020, 13:21 J. King <[hidden email]> wrote:

> On February 15, 2020 2:14:30 p.m. EST, Thomas Kurz <[hidden email]>
> wrote:
> >Wouldn't be something like
> >
> >SELECT sql FROM sqlite_master WHERE tbl_name='?' AND type='table'
> >contains "WITHOUT ROWID"
> >
> >be sufficient?
> >
> >Just being curious.
> >
> >----- Original Message -----
> >From: [hidden email] <[hidden email]>
> >To: SQLite mailing list <[hidden email]>
> >Sent: Saturday, February 15, 2020, 18:06:47
> >Subject: [sqlite] WITHOUT ROWID tables
> >
> >Ok, not ideal. Still confusing, but I see the difference.
> >For my code, I know the schemas. I guess a SQL builder could offer up
> >query
> >options to the user browsing new databases.
> >
> >On Sat, Feb 15, 2020 at 11:26 AM Simon Slavin <[hidden email]>
> >wrote:
> >
> >> On 15 Feb 2020, at 3:14pm, [hidden email] wrote:
> >
> >> >> To determine if table XYZ is a WITHOUT ROWID table, run "PRAGMA
> >> >> index_info('XYZ');".  If you get back one or more rows, then XYZ
> >is a
> >> >> WITHOUT ROWID table.  If you get back no rows, then XYZ is a rowid
> >> >> table.
> >> >>
> >> > Confused...What if I made an index on a ROWID table?
> >> > CREATE INDEX "Z" ON "DOC" ("n_id");
> >
> >> The parameter in index_info() is normally the name of an index.  So
> >if you
> >> create an index "Z" and ask for index_info("Z") you will get
> >information on
> >> that index.
> >
> >> If you create a WITHOUT ROWID table with name 'Y", and ask for
> >> index_info("Y") you will get information on the primary key of that
> >table.
> >
> >> If both exist, you get information about the index.
> >
> >> Simon
> >> _______________________________________________
> >> sqlite-users mailing list
> >> [hidden email]
> >> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
> >
> >_______________________________________________
> >sqlite-users mailing list
> >[hidden email]
> >http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
> >
> >_______________________________________________
> >sqlite-users mailing list
> >[hidden email]
> >http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
> CREATE TABLE t(
> c TEXT DEFAULT 'WITHOUT ROWID'
> -- this comment mentions something about WITHOUT ROWID
> );
>
>
> Contrived, no question, but possible.
> --
> J. King
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: WITHOUT ROWID tables

curmudgeon
In reply to this post by Simon Slavin-3
Re my earlier post (which didn’t go out to mailing list)

sqlite3_table_column_metadata(db,dbName,tblName,"rowid",0,0,0,0,0)==SQLITE_OK
returns false if table tblName is a without rowid table

seems to work for me.

Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10

________________________________
From: sqlite-users <[hidden email]> on behalf of Simon Slavin <[hidden email]>
Sent: Sunday, February 16, 2020 6:11:02 PM
To: SQLite mailing list <[hidden email]>
Subject: Re: [sqlite] WITHOUT ROWID tables

On 16 Feb 2020, at 6:00pm, Bernardo Ramos <[hidden email]> wrote:

> I've got no rows for both with and without rowid tables:

<https://sqlite.org/pragma.html#pragma_index_info>

" as of SQLite version 3.30.0 on 2019-10-04 "
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: WITHOUT ROWID tables

skywalk
'rowid' is a common name and could be in anyone's schema regardless of
table type.

On Mon, Feb 17, 2020 at 2:35 AM x <[hidden email]> wrote:

> Re my earlier post (which didn’t go out to mailing list)
>
>
> sqlite3_table_column_metadata(db,dbName,tblName,"rowid",0,0,0,0,0)==SQLITE_OK
> returns false if table tblName is a without rowid table
>
> seems to work for me.
>
> Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for
> Windows 10
>
> ________________________________
> From: sqlite-users <[hidden email]> on
> behalf of Simon Slavin <[hidden email]>
> Sent: Sunday, February 16, 2020 6:11:02 PM
> To: SQLite mailing list <[hidden email]>
> Subject: Re: [sqlite] WITHOUT ROWID tables
>
> On 16 Feb 2020, at 6:00pm, Bernardo Ramos <[hidden email]> wrote:
>
> > I've got no rows for both with and without rowid tables:
>
> <https://sqlite.org/pragma.html#pragma_index_info>
>
> " as of SQLite version 3.30.0 on 2019-10-04 "
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users