Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WITHOUT ROWID for TEXT column #240

Closed
fu-hsi opened this issue Mar 28, 2015 · 18 comments
Closed

WITHOUT ROWID for TEXT column #240

fu-hsi opened this issue Mar 28, 2015 · 18 comments
Labels
bug Confirmed bugs or reports that are very likely to be bugs.

Comments

@fu-hsi
Copy link

fu-hsi commented Mar 28, 2015

SqliteBrowser allows using WITHOUT ROWID only for INTEGER column.
SQLite does not have this limitation:
https://www.sqlite.org/withoutrowid.html

@fu-hsi fu-hsi changed the title WITCHOUT ROWID for string column WITHOUT ROWID for string column Mar 28, 2015
@justinclift
Copy link
Member

@MKleusberg ?

@fu-hsi
Copy link
Author

fu-hsi commented Mar 28, 2015

@fu-hsi fu-hsi changed the title WITHOUT ROWID for string column WITHOUT ROWID for TEXT column Mar 28, 2015
@rp-
Copy link
Contributor

rp- commented Apr 10, 2015

should be fixed:
cecf681

@justinclift
Copy link
Member

Cool. 😄

@fu-hsi Do you have time to test the next nightly build, and let us know if it works ok now?

@fu-hsi
Copy link
Author

fu-hsi commented Apr 11, 2015

Of course.

@fu-hsi
Copy link
Author

fu-hsi commented Apr 12, 2015

My current table schema:

CREATE TABLE `test` (
    `Field1`    TEXT NOT NULL,
    `Field2`    INTEGER NOT NULL DEFAULT 1,
    PRIMARY KEY(Field1)
) WITHOUT ROWID;

When I try modify the table schema and check Unique checkbox, application not respond and crashes.

Screen1

Inserting data from Browse Data tab don't work, I don't know why...
When I click New record I received:

Screen2

Manually insert works:

Query executed successfully: insert into test values('bla',1); (took 0ms)
Query executed successfully: insert into test values('bla2',1); (took 0ms)

Look on SQL Log on right panel...
SELECT MAX() from TEXT field??

I am usung now SQLiteStudio since two weeks (sorry guys :)) and works like a charm :)

@justinclift
Copy link
Member

@rp- Thoughts? 😄

@fu-hsi:

I am usung now SQLiteStudio since two weeks (sorry guys :)) and works like a charm :)

That's no worries. When there's a problem that needs solving I often use whatever works first too. 😉

@fu-hsi
Copy link
Author

fu-hsi commented Apr 12, 2015

Editing and deleting also doesn't work :)
Even if I change Primary key to NUMERIC.

Log:

UPDATE `test` SET `Field1`=? WHERE `Field1`=0;
DELETE FROM `test` WHERE `Field1`=0;

Field Field1 always equal 0.

When I create new table with NUMERIC key, then it works.

@justinclift
Copy link
Member

@rp- Sounds like the fix really didn't work. 😉

@fu-hsi
Copy link
Author

fu-hsi commented Apr 12, 2015

This is more complex than the programmer thought.
Many functions operates on numeric keys, and now... all must be changed? :)
Maybe I'm wrong and the key can not be text...?

@rp-
Copy link
Contributor

rp- commented Apr 12, 2015

well, all i did was enabling to have tables without rowid and pks of any type, as allowed by sqlite3.
I think we still don't really support editing tables without rowid, because most of our code depends on it.

@MKleusberg
Copy link
Member

At least the thing with the crash when adding a UNIQUE constraint in that special case seems to be a bug in SQLite itself. The same happens when executing this code using the command line utility:

CREATE TABLE `test` (
    `Field1`    TEXT UNIQUE NOT NULL,
    `Field2`    INTEGER NOT NULL DEFAULT 1,
    PRIMARY KEY(Field1)
) WITHOUT ROWID;

In the latest development version of SQLite, however, I couldn't reproduce this anymore.

@justinclift
Copy link
Member

Ok. What's the right way forward here? Should we go back to having "without rowid" only for numeric columns?

MKleusberg added a commit that referenced this issue Apr 25, 2015
Add support for non-integer primary keys, especially on table without
rowid column. The previous code often assumed that the rowid column or
its equivalent was a 64bit integer but SQLite allows any data, including
text, to be stored in there.

See issue #240.
@MKleusberg
Copy link
Member

Ok, to quickly summarise the situation:

  • The UNIQUE TEXT primary key thing is a SQLite bug which seems to be fixed in the latest version. So I suggest ignoring this one.
  • Without Rowid table are more or less supported, so editing, deleting, adding, etc. of rows works most of the times. I don't think there's any code left which really depends on the rowid column, the only remaining issues may occur because we don't handle some situations not entirely correct yet.
  • One of this was the text primary key thing. The SQLite documentation says the primary key column in a without rowid table must be numeric but apparently this isn't the case. @fu-hsi is right that most of our code assumed the primary key was numeric which caused a lot of trouble when it wasn't. The commit I've just pushed should fix these issues, so we handle non-numeric primary keys correctly.

So I think we don't need to go back because it as easy enough to fix the problematic parts. The new code needs a bit of testing (in a scenario like the one described in this issue as well as under normal circumstances) but should fix all the problems described in this issue (except for the SQLite bug that is of course).

@MKleusberg MKleusberg added bug Confirmed bugs or reports that are very likely to be bugs. fix applied labels Apr 25, 2015
MKleusberg added a commit that referenced this issue Apr 25, 2015
Add support for non-integer primary keys, especially on table without
rowid column. The previous code often assumed that the rowid column or
its equivalent was a 64bit integer but SQLite allows any data, including
text, to be stored in there.

See issue #240.
@justinclift
Copy link
Member

Cool. 😄

Is this something we should ask @fu-hsi to test again in the next nightly build?

@MKleusberg
Copy link
Member

Yes definitely, if he has the time and motivation 😄
@fu-hsi Do you? 😉

@MKleusberg MKleusberg added this to the 3.6 milestone Apr 25, 2015
@MKleusberg
Copy link
Member

Somebody willing to test this? If not I'd suggest closing this issue and if there should be any more problems with this it can always be reopened.

@justinclift
Copy link
Member

Closing it for now. @fu-hsi Do you have a few minutes to test our latest nightly build, and let us know if it's not working after all?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bugs or reports that are very likely to be bugs.
Projects
None yet
Development

No branches or pull requests

4 participants