Replies: 14 comments
-
SQLite2 or SQLite3 database? |
Beta Was this translation helpful? Give feedback.
-
SQlite3 |
Beta Was this translation helpful? Give feedback.
-
Can you share DDL of your table? |
Beta Was this translation helpful? Give feedback.
-
CREATE TABLE C ( |
Beta Was this translation helpful? Give feedback.
-
p.s. for example in Access, when i add new row i can see default values filled into grid. |
Beta Was this translation helpful? Give feedback.
-
You need to also set "NOT NULL" constraint to have DEFAULT values inserted always. If there is not NOT NULL, then NULL values are allowed and that's exactly what is happening. SQLiteStudio doesn't really know if you want to insert NULL or DEFAULT value, that's why it's not enforcing DEFAULT value. On the other hand - if NOT NULL is set on the column, SQLiteStudio will know that it has to use DEFAULT value if no value was provided by user, because NULL is no-go. Even if you enable "NOT NULL" the default value will appear only after committing the new row. Until you commit, it's up to user what value goes there. If it remains NULL, then it will be replaced with DEFAULT, to satisfy NOT NULL constraint. |
Beta Was this translation helpful? Give feedback.
-
No, you are wrong. If i do not edit column then INSERT inserts default values! You dont have to have NOT NULL constraint. e.g. |
Beta Was this translation helpful? Give feedback.
-
I know that INSERT works this way. Now let's consider how SQLiteStudio (or basically any DB tool that allows insertion from Grid) works. So what about skipping these, that have NULL value and have DEFAULT defined? Well, what if you do want to insert NULL value and not the DEFAULT one? It is valid to insert NULL. So how about pre-filling columns with DEFAULT values, like in Access and let user decide what to do (leave default or set to NULL)? You can declare NOT NULL if you want to use DEFAULT value by default. There is no consistent way of implementing it the way you want, because soon after it works that way, someone else will come here and report issue, that it works wrong. I guess Access have it figured out somehow. If you know how they handle cases like above (with sequence, or virtually any stateful default value), feel free to explain and we will see if that's doable with SQLite. |
Beta Was this translation helpful? Give feedback.
-
I think if table is design with default values then it is strange if user is surprised with prefilled defaults. |
Beta Was this translation helpful? Give feedback.
-
I was writting long explanation here, on why this is difficult to do in SQLite and I came up with idea how to solve it, so below I'm writing a note to myself in future, so when I get to work on it, I remember what I wanted to do to implemented it as you suggest. To future me: @tataremka If you wonder how it works now, SQLiteStudio always have 1 active connection with certain database, therefore it cannot afford to keep open transactions like that, because user could add a row (keep transaction open), then switch to other window, do something (which would be included in this transaction) and then go back to that new row and rollback it, canceling that other change too. That's why currently new rows are not in transaction until you commit/rollback. Because of that it is (currently) impossible to preload default values, without changing stateful values (sequences, functions). Anyway, thanks for your persistence on arguing back. Thanks to you I figured out solution ;) Still, it's not a simple change, but the result of it will give SQLiteStudio many more new possibilities, not only this one discussed here. |
Beta Was this translation helpful? Give feedback.
-
One more cent to discussion... |
Beta Was this translation helpful? Give feedback.
-
But that's exactly the point I was trying to explain you earlier. Some default values can be stateful. PRIMARY KEY AUTOINCREMENT is simplest example of such stateful value (I know, it doesn't use DEFAULT clause, but it behaves similarly). Why is this problem? Well, to display value of such function you need to |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Thanx! It works! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Details
I have created table with default values in some columns
In data tab, i want to add new row. I cannot see any default values.
Still the same after commit changes to database and refresh.
Operating system
Windows 10, 64bit
SQLiteStudio version
3.2.1
Beta Was this translation helpful? Give feedback.
All reactions