I'd like to insert NaN values into SQLite database.
I have Ent table with Id, StringColumn and DoubleColumn (not nullable) and I try use the following SQL statement:
INSERT INTO Ent (Id, StringColumn, DoubleColumn) VALUES (1, 'NaN test', ????)
I don't know what to put in place of '????' to have NaN stored.
I'm accessing the database using System.Data.SQLite - maybe this also matters?
I've asked guys of SQLite how to deal with the problem: http://system.data.sqlite.org/index.html/tktview/e06c4caff3c433c80616ae5c6df63fc830825e59.
They've added a new connection flag: "GetAllAsText" and now it is possible to store NaN, along with the others (Infinity, -Infinity).
SQLite is rather... lax... about data types. Feel free to put "NaN" into a column defined as "double". Or "infinity". Or "double", for that matter. SQLite doesn't care.
SQLite does not have a textual representation of NaN values.
In SQL, the special NULL behaves similarly in computations, and can serve the same purpose.
The trick that I currently employ is to store -Infinity on Real columns when null won't suffice or is not allowed (since you have "not null" on that column).
Related
I don't know what is the difference between SQLite NVARCHAR and NVARCHAR2 column.
I know that NVARCHAR is a Unicode-only text column, but what about NVARCHAR2?
There is a difference. In a way...
HereĀ“s the thing:
As Lasse V. Karlsen says, SQLite does not act on the types you mentioned nor does it restrict the length by an argument passed in like in NVARCHAR(24) (but you could do check constraints to restrict length).
So why are these available in SQLite Expert (and other tools)?
This info will be saved in the database schema (please check https://www.sqlite.org/datatype3.html#affinity and http://www.sqlite.org/pragma.html#pragma_table_info) So should you bother to set these when creating a SQLite db as it will not be used by SQLite?
Yes if you will be using any tool to generate code from the schema! Maybe somebody will ask you to transfer the db to MSSQL, then there are some great tools that will use the schema and will map your SQLite to MSSQL in a blink. Or maybe you will use some .NET tool to map the tables into POCO classes, and these can also use the schema to map to the correct type and they will also use the restrictions and transfer these into data annotations on the properties that the columns map to. And EntityFramework 7 will have support built in for SQLite and their code generation will surely make use of the schema.
There is no difference.
SQLite does not operate with strict data types like that, it has "storage classes".
If you check the official documentation you'll find this rule, one of five used to determine which storage class to assign to a column from the data type you specify:
If the declared type of the column contains any of the strings "CHAR", "CLOB", or "TEXT" then that column has TEXT affinity. Notice that the type VARCHAR contains the string "CHAR" and is thus assigned TEXT affinity.
There are 5 rules in total but rule 2 covers NVARCHAR and NVARCHAR2 and both will assign the storage class TEXT to the column.
I'm using LinqPad and IQ driver for SQLite. I have connection with this file. Look:
"Okreslone rzutowanie jest nieprawidlowe" - it can be simple translate to "invalid cast", but Zbiors.Count() return value 8.
When i'm trying do it in SQL query:
select * from zbior
Then all's ok. How can i get same result by "C#", not by SQL query?
Most likely, the types are incorrect. SQLite has a horrible "feature" whereby you can put strings into integer columns and vice versa. The column types are merely suggestion and are not enforced. So what looks like integers in your data might actually be strings, causing in InvalidCastException when the IQ driver tries to read them.
I have a log table, using System.Data.Sqlite (C# on .NET 4.5) to write to a single table with 12 columns. Some of the columns might be written for a row, some might not. Is there a way to have a single parameterized Insert statement, only specifying n parameters, and let the rest automatically set to null?
I am thinking of the equivalent of a MS SQL Server stored procedure where multiple input parameters can be specified as null, and then a single insert statement within the sproc would insert nulls as needed.
Thanks.
Use null or DBNull.Value; see
NULL values and SQLiteParameters.
I have a MySQL DB which stores data into a column of type 'binary' in this way:
INSERT INTO t VALUES(0x00000000000000000000000000000001)
I want to do the same in SQLite, so I need to figure out two things:
What is the 'binary' type equivalent in sqlite? There is a blob, but that might behave differently.
How can bin data be represented while inputting using INSERT statements. In MySQL for example, the above format of 0xbin works. But what about SQLite?
Found the answers, here they are for posterity.
There is a 'binary' type in sqlite3 but it doesn't seem to behave any differently from the 'blob' type, which is unusual.
Binary is inserted as such
create table t (b blob);
insert into t values (X'00000000000000000000000000000002');
Is there a way to further restrict the lookup performed by a database lookup functoid to include another column?
I have a table containing four columns.
Id (identity not important for this)
MapId int
Ident1 varchar
Ident2 varchar
I'm trying to get Ident2 for a match on Ident1 but wish it to only lookup where MapId = 1.
The functoid only allows the four inputs any ideas?
UPDATE
It appears there is a technique if you are interested in searching across columns that are string data types. For those interested I found this out here...
Google Books: BizTalk 2006 Recipes
Seeing as I wish to restrict on a numberic column this doesn't work for me. If anyone has any ideas I'd appreciate it. Otherwwise I may need to think about my MapId column becoming a string.
I changed the MapId to MapCode of type char(3) and used the technique described in the book I linked to in the update to the original question.
The only issue I faced was that my column collations where not in line so I was getting an error from the SQL when they where concatenated in the statement generated by the map.
exec sp_executesql N'SELECT * FROM IdentMap WHERE MapCode+Ident1= #P1',N'#P1 nvarchar(17)',N'<MapCode><Ident2>'
Sniffed this using the SQL Profiler