简体   繁体   English

SQLite C#查询不起作用

[英]SQLite C# query doesn' t work

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". 我在执行从C#到SQLite DB的查询时遇到问题,我使用以下查询,它给出了错误:“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? 我不能使用nvarchar格式,我应该使用TEXT吗?

use TEXT . 使用TEXT

According to the manual, 根据手册,

TEXT - The value is a text string, stored using the database encoding (UTF-8, UTF-16BE or UTF-16LE). TEXT - 值是一个文本字符串,使用数据库编码(UTF-8,UTF-16BE或UTF-16LE)存储。

SQLite doesn't use sizes when declaring the varchar type. 声明varchar类型时, SQLite不使用大小。

From FAQ 来自FAQ

(9) What is the maximum size of a VARCHAR in SQLite? (9)SQLite中VARCHAR的最大大小是多少?

SQLite doesn't enforce the length of a VARCHAR. SQLite 不强制 VARCHAR 的长度 You can declare a VARCHAR(10) and SQLite will be happy to let you put 500 characters in it. 你可以声明一个VARCHAR(10) ,SQLite很乐意让你输入500个字符。 And it will keep all 500 characters intact - it never truncates . 并且它将保持所有500个字符完整 - 它永远不会截断

You can use TEXT type instead of. 您可以使用TEXT类型而不是。 Check out from here . 这里退房。

TEXT. 文本。 The value is a text string, stored using the database encoding (UTF-8, UTF-16BE or UTF-16LE). 该值是一个文本字符串,使用数据库编码(UTF-8,UTF-16BE或UTF-16LE)存储。

There are only 5 datatypes in SQLite. SQLite中只有5种数据类型。

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 在create table语句中,SQLite将其转换为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会忽略括号中的数字参数(例如:“VARCHAR(255)”) - SQLite不对字符串,BLOB或字符串的长度施加任何长度限制(除了大的全局SQLITE_MAX_LENGTH限制)数值。

SQLite data types SQLite数据类型

Use TEXT! 使用TEXT! you can read here more about sqlite datatypes 你可以在这里阅读更多关于sqlite数据类型的信息

TEXT =>The value is a text string, stored using the database encoding (UTF-8, UTF-16BE or UTF-16LE). TEXT =>该值是一个文本字符串,使用数据库编码(UTF-8,UTF-16BE或UTF-16LE)存储。

SQLite uses a more general dynamic type system. SQLite使用更通用的动态类型系统。 In SQLite, the datatype of a value is associated with the value itself, not with its container. 在SQLite中,值的数据类型与值本身相关联,而不是与其容器相关联。 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. SQLite的动态类型系统向后兼容其他数据库引擎的更常见的静态类型系统,因为在静态类型数据库上工作的SQL语句应该在SQLite中以相同的方式工作。 However, the dynamic typing in SQLite allows it to do things which are not possible in traditional rigidly typed databases. 但是,SQLite中的动态类型允许它执行传统的刚性类型数据库中无法实现的操作。

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. SQLite不对字符串,BLOB或数值的长度施加任何长度限制(除了大的全局SQLITE_MAX_LENGTH限制)。

Finally: 最后:

Maximum length of a string or BLOB 字符串或BLOB的最大长度

The maximum number of bytes in a string or BLOB in SQLite is defined by the preprocessor macro SQLITE_MAX_LENGTH. 字符串中的最大字节数或SQLite中的BLOB由预处理器宏SQLITE_MAX_LENGTH定义。 The default value of this macro is 1 billion (1 thousand million or 1,000,000,000). 此宏的默认值为10亿(十亿或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. -DSQLITE_MAX_LENGTH = 123456789当前实现仅支持长度为231-1或2147483647的字符串或BLOB长度。而在此之前,某些内置函数(如hex())可能会失败。 In security-sensitive applications it is best not to try to increase the maximum string and blob length. 在安全敏感的应用程序中,最好不要尝试增加最大字符串和blob长度。 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. 事实上,如果可能的话,你最好将最大字符串和blob长度降低到几百万的范围内。

During part of SQLite's INSERT and SELECT processing, the complete content of each row in the database is encoded as a single BLOB. 在SQLite的INSERT和SELECT处理过程中,数据库中每行的完整内容被编码为单个BLOB。 So the SQLITE_MAX_LENGTH parameter also determines the maximum number of bytes in a row. 因此,SQLITE_MAX_LENGTH参数还确定一行中的最大字节数。

The maximum string or BLOB length can be lowered at run-time using the sqlite3_limit(db,SQLITE_LIMIT_LENGTH,size) interface. 可以使用sqlite3_limit(db,SQLITE_LIMIT_LENGTH,size)接口在运行时降低最大字符串或BLOB长度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM