Question

I'm having trouble executing a query from C# to the SQLite DB, I use the following query and it gives me the error that something is wrong at: "max".

create table ClockMessages (ID int identity(1, 1) primary key, InsertDateTime DateTime not null, SendDateTime DateTime, Data nvarchar(max));

Can't I use the nvarchar format, and should I use TEXT instead?

Was it helpful?

Solution 4

Use TEXT! you can read here more about sqlite datatypes

TEXT=>The value is a text string, stored using the database encoding (UTF-8, UTF-16BE or UTF-16LE).

SQLite uses a more general dynamic type system. In SQLite, the datatype of a value is associated with the value itself, not with its container. The dynamic type system of SQLite is backwards compatible with the more common static type systems of other database engines in the sense that SQL statement that work on statically typed databases should work the same way in SQLite. However, the dynamic typing in SQLite allows it to do things which are not possible in traditional rigidly typed databases.

That noted:

SQLite does not impose any length restrictions (other than the large global SQLITE_MAX_LENGTH limit) on the length of strings, BLOBs or numeric values.

Finally:

Maximum length of a string or BLOB

The maximum number of bytes in a string or BLOB in SQLite is defined by the preprocessor macro SQLITE_MAX_LENGTH. The default value of this macro is 1 billion (1 thousand million or 1,000,000,000). You can raise or lower this value at compile-time using a command-line option like this:

-DSQLITE_MAX_LENGTH=123456789 The current implementation will only support a string or BLOB length up to 231-1 or 2147483647. And some built-in functions such as hex() might fail well before that point. In security-sensitive applications it is best not to try to increase the maximum string and blob length. In fact, you might do well to lower the maximum string and blob length to something more in the range of a few million if that is possible.

During part of SQLite's INSERT and SELECT processing, the complete content of each row in the database is encoded as a single BLOB. So the SQLITE_MAX_LENGTH parameter also determines the maximum number of bytes in a row.

The maximum string or BLOB length can be lowered at run-time using the sqlite3_limit(db,SQLITE_LIMIT_LENGTH,size) interface.

OTHER TIPS

use TEXT.

According to the manual,

TEXT - The value is a text string, stored using the database encoding (UTF-8, UTF-16BE or UTF-16LE).

SQLite doesn't use sizes when declaring the varchar type.

From FAQ

(9) What is the maximum size of a VARCHAR in SQLite?

SQLite doesn't enforce the length of a VARCHAR. You can declare a VARCHAR(10) and SQLite will be happy to let you put 500 characters in it. And it will keep all 500 characters intact - it never truncates.

You can use TEXT type instead of. Check out from here.

TEXT. The value is a text string, stored using the database encoding (UTF-8, UTF-16BE or UTF-16LE).

There are only 5 datatypes in SQLite.

when you use some of these

CHARACTER(20)
VARCHAR(255)
VARYING CHARACTER(255)
NCHAR(55)
NATIVE CHARACTER(70)
NVARCHAR(100)
TEXT
CLOB

in create table statement, SQLite transforms it to Text

also

Note that numeric arguments in parentheses that following the type name (ex: "VARCHAR(255)") are ignored by SQLite - SQLite does not impose any length restrictions (other than the large global SQLITE_MAX_LENGTH limit) on the length of strings, BLOBs or numeric values.

SQLite data types

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top