Re: [sqlite] column types and constraints

2018-06-30 Thread Keith Medcalf
Message- >From: sqlite-users [mailto:sqlite-users- >boun...@mailinglists.sqlite.org] On Behalf Of Warren Young >Sent: Saturday, 30 June, 2018 18:09 >To: SQLite mailing list >Subject: Re: [sqlite] column types and constraints > >On Jun 29, 2018, at 10:17 PM, Keith Medcalf &

Re: [sqlite] column types and constraints

2018-06-30 Thread Warren Young
On Jun 29, 2018, at 10:17 PM, Keith Medcalf wrote: > > So what you really want is (a) to be able to error-out on SQL operations that > do not use proper affinity words (ie, only accept INTEGER, DOUBLE, TEXT and > BLOB), and; (b) to crash or return an error instead of converting the data >

Re: [sqlite] column types and constraints

2018-06-30 Thread Igor Korot
sqlite> > > --- > The fact that there's a Highway to Hell but only a Stairway to Heaven says a > lot about anticipated traffic volume. > > >>-Original Message- >>From: sqlite-users [mailto:sqlite-users- >>boun...@mailinglists.sqlite.org] On Behalf Of Thomas Kurz >

Re: [sqlite] column types and constraints

2018-06-30 Thread Simon Slavin
On 30 Jun 2018, at 8:58pm, Wout Mertens wrote: > Hmm, very odd. I'll need to check what happened again. Pay a lot of attention to the type you supplied when you created the table. The post you're responding to has this line: > sqlite> create table x(x primary key); This does not supply a

Re: [sqlite] column types and constraints

2018-06-30 Thread Keith Medcalf
e fact that there's a Highway to Hell but only a Stairway to Heaven says a lot about anticipated traffic volume. >-Original Message- >From: sqlite-users [mailto:sqlite-users- >boun...@mailinglists.sqlite.org] On Behalf Of Thomas Kurz >Sent: Saturday, 30 June, 2018 14:10 >To:

Re: [sqlite] column types and constraints

2018-06-30 Thread Thomas Kurz
> when in fact it was the third-party interface wrapper. The examples I provided were all taken from the current sqlite3.exe cli with 3.24.0 library. It is not a third-party issue. ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org

Re: [sqlite] column types and constraints

2018-06-30 Thread Wout Mertens
lot about anticipated traffic volume. > > > >-----Original Message----- > >From: sqlite-users [mailto:sqlite-users- > >boun...@mailinglists.sqlite.org] On Behalf Of Wout Mertens > >Sent: Saturday, 30 June, 2018 11:44 > >To: SQLite mailing list > >Subject:

Re: [sqlite] column types and constraints

2018-06-30 Thread Keith Medcalf
t: Saturday, 30 June, 2018 11:44 >To: SQLite mailing list >Subject: Re: [sqlite] column types and constraints > >story time: > >I was storing rows with text id's and never bothered setting a type, >it was >"id PRIMARY KEY" and I always assumed that it gave me b

Re: [sqlite] column types and constraints

2018-06-30 Thread Thomas Kurz
> H2, HSQL Both are Java crap. SQLite is unfortunately the only embedded DBMS that gets along with a single file for both the library and the database files. (At least it's the only I know after scaning various systems.) ___ sqlite-users mailing list

Re: [sqlite] column types and constraints

2018-06-30 Thread Wout Mertens
story time: I was storing rows with text id's and never bothered setting a type, it was "id PRIMARY KEY" and I always assumed that it gave me back what I stored in it via the nodejs binding. One day I was storing a string of numbers which happened to fit in a 64 bit int, and so sqlite stored

Re: [sqlite] column types and constraints

2018-06-30 Thread danap
> Bob wrote: > Affinity is only a hint and not an assurance of anything. > I solve the problem by bloating the schema with checks like this: > > foo integer default 1234 > check (typeof(foo) == 'integer'), > > This enforces that someone can't put "Hello world" where an integer > belongs.

Re: [sqlite] column types and constraints

2018-06-30 Thread Thomas Kurz
> And yes, you might think (like me) that this is silly and they should > just fix it, warning people about the new way for a good few versions, > and then just roll it out. But, that would mean there will exist schemas Hmmm... but what kind of compatibility issues would you see if SQLite

Re: [sqlite] column types and constraints

2018-06-30 Thread Olivier Mascia
> Le 30 juin 2018 à 13:30, R Smith a écrit : > > PS: Anyone here that takes web servers and the like through upgrades to > different Apache, or PHP versions, or different MySQL/MariaDB versions will > know the effort of re-engineering your work from years ago to fit the new > upgrade. SQLite

Re: [sqlite] column types and constraints

2018-06-30 Thread R Smith
On 2018/06/30 9:04 AM, Thomas Kurz wrote: COLUMN xy VARCHAR(50) COLUMN xy MEDIUMTEXT COLUMN xy BIT COLUMN xy DECIMAL(5,2) Should those raise errors? Because to SQLite those are the exact same gibberish as: I would appreciate if SQLite raised an error each time the declaration mismatches the

Re: [sqlite] column types and constraints

2018-06-30 Thread Olivier Mascia
> Le 30 juin 2018 à 09:04, Thomas Kurz a écrit : > > CREATE TABLE a (col1 STRING); > INSERT INTO a (col1) VALUES ("3.0"); > SELECT * from a; > ---> 3// this should never happen!! SQLite type affinity rules clearly do not recognise STRING as TEXT: it does so only when the type contains the

Re: [sqlite] column types and constraints

2018-06-30 Thread Olivier Mascia
> Le 30 juin 2018 à 09:04, Thomas Kurz a écrit : > >> a) COLUMN xy VARCHAR(50) >> b) COLUMN xy MEDIUMTEXT >> c) COLUMN xy BIT >> d) COLUMN xy DECIMAL(5,2) >> Should those raise errors? Because to SQLite those are the exact same >> gibberish as: > > I would appreciate if SQLite raised an error

Re: [sqlite] column types and constraints

2018-06-30 Thread Simon Slavin
On 30 Jun 2018, at 8:35am, Keith Medcalf wrote: > You "put" a ieee754 floating point double. Keith, Are you referring to this ? On 30 Jun 2018, at 8:04am, Thomas Kurz wrote: > CREATE TABLE a (col1 STRING); > INSERT INTO a (col1) VALUES ("3.0"); > SELECT * from a; > ---> 3// this should

Re: [sqlite] column types and constraints

2018-06-30 Thread Thomas Kurz
> You "put" a ieee754 floating point double. No I don't, I put a string ;-) I am not complaining that I can put anything anywhere. But the data type that I provide should be kept. When providing a string, it should be stored as such to have the possibility to get back the original value. When

Re: [sqlite] column types and constraints

2018-06-30 Thread Keith Medcalf
s a dodo and *meant* to use single-quotes but was typing in all-caps at the time and put in the wrong character ... --- The fact that there's a Highway to Hell but only a Stairway to Heaven says a lot about anticipated traffic volume. >-Original Message- >From: sqlite-users [m

Re: [sqlite] column types and constraints

2018-06-30 Thread Thomas Kurz
> I don't disagree, but this means we lose sight of the important point >that, if you distill the problem to just "INTEGER", then sure, it looks > silly, and sure, you can fix it with internal auto-CHECKing, but in > SQLite the type affinity INTEGER stands father to LONGINT, MEDIUMINT, Ok, I

Re: [sqlite] column types and constraints

2018-06-29 Thread Keith Medcalf
>-Original Message- >From: sqlite-users [mailto:sqlite-users- >boun...@mailinglists.sqlite.org] On Behalf Of Warren Young >Sent: Friday, 29 June, 2018 19:35 >To: SQLite mailing list >Subject: Re: [sqlite] column types and constraints > >On Jun 29, 2018, at 4:36 PM,

Re: [sqlite] column types and constraints

2018-06-29 Thread Warren Young
On Jun 29, 2018, at 4:36 PM, Keith Medcalf wrote: > > All of the issues raised are "application" problems, not database problems. Computers are here to aid humans, not the other way around. > Clearly if you retrieved a value from the database and want to use it as an > index you have to do

Re: [sqlite] column types and constraints

2018-06-29 Thread Keith Medcalf
00 >To: SQLite mailing list >Subject: Re: [sqlite] column types and constraints > >On Jun 29, 2018, at 11:46 AM, Richard Hipp wrote: >> >> On 6/29/18, Bob Friesenhahn wrote: >>> >>> Without adding all the necessary safe-guards to ensure that only >valid

Re: [sqlite] column types and constraints

2018-06-29 Thread R Smith
On 2018/06/30 12:05 AM, Thomas Kurz wrote: Indeed, but that option does exist, it's called CHECK constraints You're clearly right, but from my point of view, it's redundant to say COLUMN xy INTEGER CHECK type=integer, because "COLUMN INTEGER" already implies that the column is integer. And,

Re: [sqlite] column types and constraints

2018-06-29 Thread Thomas Kurz
> Indeed, but that option does exist, it's called CHECK constraints You're clearly right, but from my point of view, it's redundant to say COLUMN xy INTEGER CHECK type=integer, because "COLUMN INTEGER" already implies that the column is integer. And, btw, as CHECK already exists, it shouldn't

Re: [sqlite] column types and constraints

2018-06-29 Thread R Smith
On 2018/06/29 10:23 PM, Thomas Kurz wrote: b) I think that noone wants type affinity to be actually removed. I'd just like an option to make SQLite behave like any other DBMS and - respect the data type declared for a column - reject column definitions with invalid types (e.g. "STRING")

Re: [sqlite] column types and constraints

2018-06-29 Thread Simon Slavin
On 29 Jun 2018, at 9:23pm, Thomas Kurz wrote: > a) Why would I put strings in an integer column? If I need to do so, I have a > concept error in my database schema. > > b) I think that noone wants type affinity to be actually removed. I'd just > like an option to make SQLite behave like any

Re: [sqlite] column types and constraints

2018-06-29 Thread Bob Friesenhahn
On Fri, 29 Jun 2018, Richard Hipp wrote: On 6/29/18, Bob Friesenhahn wrote: Without adding all the necessary safe-guards to ensure that only valid data goes into the database, sqlite puts the using application at risk (security and stability) with its wishy-washy ways. Can you provide an

Re: [sqlite] column types and constraints

2018-06-29 Thread Bob Friesenhahn
On Fri, 29 Jun 2018, R Smith wrote: Type-constraining here would merely protect the programmer against him/herself. I know this is not entirely without merit, but a feature I would happily forego when weighed against even just one of the points made in the previous paragraph. The 'lite' in

Re: [sqlite] column types and constraints

2018-06-29 Thread Abroży Nieprzełoży
SQLite returns what has been saved in the database, the application should control what it writes to the database. If the database can be edited by an untrusted entity, the application should treat the content of the database as untrusted. Even if SQLite enforced data types, someone who can edit

Re: [sqlite] column types and constraints

2018-06-29 Thread R Smith
On 2018/06/29 9:00 PM, Warren Young wrote: The following is an answer to your challenge, not a feature request// 4. The application uses the value as an index into an array. If the application passes int* to sqlite3_column_int() to avoid compiler complaints, they’ll get a negative

Re: [sqlite] column types and constraints

2018-06-29 Thread Thomas Kurz
> At least, enough-so in my mind to defend David's assessment of "an > excellent decision". Sorry, I cannot follow the point. a) Why would I put strings in an integer column? If I need to do so, I have a concept error in my database schema. b) I think that noone wants type affinity to be

Re: [sqlite] column types and constraints

2018-06-29 Thread Warren Young
On Jun 29, 2018, at 11:46 AM, Richard Hipp wrote: > > On 6/29/18, Bob Friesenhahn wrote: >> >> Without adding all the necessary safe-guards to ensure that only valid >> data goes into the database, sqlite puts the using application at risk >> (security and stability) with its wishy-washy ways.

Re: [sqlite] column types and constraints

2018-06-29 Thread R Smith
On 2018/06/29 6:25 PM, Bob Friesenhahn wrote: On Fri, 29 Jun 2018, David Burgess wrote: "This flexible type-name arrangement works because SQLite is very forgiving about you putting non-proscribed values//... This is an important feature of SQLite.  In hindsight, an excellent decision. It

Re: [sqlite] column types and constraints

2018-06-29 Thread Richard Hipp
On 6/29/18, Bob Friesenhahn wrote: > > Without adding all the necessary safe-guards to ensure that only valid > data goes into the database, sqlite puts the using application at risk > (security and stability) with its wishy-washy ways. > Can you provide an example of a security of stability

Re: [sqlite] column types and constraints

2018-06-29 Thread Tim Streater
On 29 Jun 2018, at 17:46, Bob Friesenhahn wrote: > On Fri, 29 Jun 2018, danap wrote: >> >> Unless your trying to create a generic user interface. >> >> I have spent the last month trying to solve affinity with the columns. >> The only way it seems to me to guarantee to solve the issue is to test

Re: [sqlite] column types and constraints

2018-06-29 Thread Bob Friesenhahn
On Fri, 29 Jun 2018, danap wrote: Unless your trying to create a generic user interface. I have spent the last month trying to solve affinity with the columns. The only way it seems to me to guarantee to solve the issue is to test every retrieved column value and test its affinity. Affinity

Re: [sqlite] column types and constraints

2018-06-29 Thread danap
"This flexible type-name arrangement works because SQLite is very forgiving about you putting non-proscribed values into columns - it tries to convert if it can do so without loss of information but if it cannot do a reversible type conversion it simply stores whatever you give it. Hence if you

Re: [sqlite] column types and constraints

2018-06-29 Thread Bob Friesenhahn
On Fri, 29 Jun 2018, David Burgess wrote: "This flexible type-name arrangement works because SQLite is very forgiving about you putting non-proscribed values into columns - it tries to convert if it can do so without loss of information but if it cannot do a reversible type conversion it simply

Re: [sqlite] column types and constraints

2018-06-28 Thread David Burgess
"This flexible type-name arrangement works because SQLite is very forgiving about you putting non-proscribed values into columns - it tries to convert if it can do so without loss of information but if it cannot do a reversible type conversion it simply stores whatever you give it. Hence if you

Re: [sqlite] column types and constraints

2018-06-28 Thread Thomas Kurz
I understand that you do not want to break compatibility. But couldn't a PRAGMA STRICT_SQL (or the like) be introduced that would force to a) reject CREATE statements with unknown declarations (I often use "STRING" for the datatype, leading to hard-to-find problems as SQLite uses a numeric type

Re: [sqlite] column types and constraints

2018-06-28 Thread Simon Slavin
On 28 Jun 2018, at 5:43am, Igor Tandetnik wrote: > It's not mentioned here though: > https://sqlite.org/syntax/column-constraint.html The syntax diagrams in the SQLite documentation are ... what's the term ? ... sufficient but not exhaustive. In other words you can use some forms which

Re: [sqlite] column types and constraints

2018-06-27 Thread Mark Wagner
Great explanation. Thanks. On Wed, Jun 27, 2018 at 7:43 PM Richard Hipp wrote: > On 6/27/18, Igor Tandetnik wrote: > > On 6/27/2018 9:14 PM, Richard Hipp wrote: > >> On 6/27/18, Mark Wagner wrote: > >>> Thanks for all the good background. FWIW this came up because someone > >>> had > >>>

Re: [sqlite] column types and constraints

2018-06-27 Thread Igor Tandetnik
On 6/27/2018 10:43 PM, Richard Hipp wrote: On 6/27/18, Igor Tandetnik wrote: On 6/27/2018 9:14 PM, Richard Hipp wrote: On 6/27/18, Mark Wagner wrote: Thanks for all the good background. FWIW this came up because someone had created a row with something like: (column_name non null).

Re: [sqlite] column types and constraints

2018-06-27 Thread Richard Hipp
On 6/27/18, Igor Tandetnik wrote: > On 6/27/2018 9:14 PM, Richard Hipp wrote: >> On 6/27/18, Mark Wagner wrote: >>> Thanks for all the good background. FWIW this came up because someone >>> had >>> created a row with something like: (column_name non null). Needless to >>> say, this created a

Re: [sqlite] column types and constraints

2018-06-27 Thread Igor Tandetnik
On 6/27/2018 9:14 PM, Richard Hipp wrote: On 6/27/18, Mark Wagner wrote: Thanks for all the good background. FWIW this came up because someone had created a row with something like: (column_name non null). Needless to say, this created a column without a "not null" constraint. It should

Re: [sqlite] column types and constraints

2018-06-27 Thread Mark Wagner
Sorry, my typo (I had entered the corrected code). This: create table t1(x text non null); insert into t1(x) values(null); select * from t1; On Wed, Jun 27, 2018 at 6:14 PM Richard Hipp wrote: > On 6/27/18, Mark Wagner wrote: > > Thanks for all the good background. FWIW this came up

Re: [sqlite] column types and constraints

2018-06-27 Thread Richard Hipp
On 6/27/18, Mark Wagner wrote: > Thanks for all the good background. FWIW this came up because someone had > created a row with something like: (column_name non null). Needless to > say, this created a column without a "not null" constraint. It should have. I get an error when I type:

Re: [sqlite] column types and constraints

2018-06-27 Thread Mark Wagner
Thanks for all the good background. FWIW this came up because someone had created a row with something like: (column_name non null). Needless to say, this created a column without a "not null" constraint. On Wed, Jun 27, 2018 at 5:02 PM Richard Hipp wrote: > On 6/27/18, Mark Wagner wrote:

Re: [sqlite] column types and constraints

2018-06-27 Thread Richard Hipp
On 6/27/18, Mark Wagner wrote: > I recently pointed out that sqlite doesn't enforce type names and > constraints when creating tables but I was unable to explain/justify this > behavior. I'm sure this has come up before and there's a clear answer but > I didn't find it easily. > > For example

Re: [sqlite] column types and constraints

2018-06-27 Thread Igor Tandetnik
On 6/27/2018 6:56 PM, Mark Wagner wrote: I recently pointed out that sqlite doesn't enforce type names and constraints when creating tables but I was unable to explain/justify this behavior. https://sqlite.org/datatype3.html SQLite attempts to be maximally compatible with a wide variety of

Re: [sqlite] column types and constraints

2018-06-27 Thread Keith Medcalf
t; from x; 1 --- The fact that there's a Highway to Hell but only a Stairway to Heaven says a lot about anticipated traffic volume. >-Original Message- >From: sqlite-users [mailto:sqlite-users- >boun...@mailinglists.sqlite.org] On Behalf Of Simon Slavin >Sent: Wednesday, 27 Jun

Re: [sqlite] column types and constraints

2018-06-27 Thread Simon Slavin
On 27 Jun 2018, at 11:56pm, Mark Wagner wrote: > I recently pointed out that sqlite doesn't enforce type names and > constraints when creating tables but I was unable to explain/justify this > behavior. I'm sure this has come up before and there's a clear answer but > I didn't find it easily.