设为首页 加入收藏

TOP

SQLite3中存储类型和数据类型结合文档解析(三)
2015-08-31 19:59:22 来源: 作者: 【 】 浏览:56
Tags:SQLite3 存储 类型 数据 结合 文档 解析
CT d < 40,? d < 60,? d < 600 FROM t1;
0|0|1


-- No affinity conversions occur.? INTEGER values on the left are
-- always less than TEXT values on the right.
SELECT d < '40', d < '60', d < '600' FROM t1;
1|1|1


  同样是文档给的源码。。。


所有例子中的结果是相同的不变,如果把表达式替换--表达式的形式“a<40”被重写为”40>a”.


4.0 操作符


所有的数学操作符(+, -,*, /, %, <<, >>, &, |),在被执行前,都会将两个操作数都转换为数值存储类型(INTEGER和REAL)。即使这个转换是有损和不可逆的,转换仍然会执行。一个数学操作符上的NULL操作数将产生NULL结果。一个数学操作符上的操作数,如果以任何方式看都不像数字,并且又不为空的话,将被转换为0或0.0。


5排序,分组和复合选择


当查询结果由ORDER BY子句排序,存储类NULL是第一位的,其次是INTEGER和REAL值穿插在数字顺序中,其次是TEXT值在整理 顺序,最后是BLOB在memcmp()中顺序。在分类之前没有存储类的转换发生。


When groupingvalues with the GROUP BY clause values with different storage classes areconsidered distinct, except for INTEGER and REAL values which are consideredequal if they are numerically equal. No affinities are applied to any values asthe result of a GROUP by clause.


The compoundSELECT operators UNION, INTERSECT and EXCEPT perform implicit comparisonsbetween values. No affinity is applied to comparison operands for the implicitcomparisons associated with UNION, INTERSECT, or EXCEPT - the values arecompared as is.


6.0排序序列


当SQLite比较两个String,它使用一个排序序列或排序函数(对同一事物的两种字)来确定哪一个String更好或者两个String一样。SQLite3内置的排序类型: BINARY,NOCASE, and RTRIM.。
?BINARY -比较字符串数据使用memcmp(),忽视文本编码。
?NOCASE - The same as binary, except the 26 upper case characters of ASCII are folded to their lower case equivalents before the comparison is performed. Note that only ASCII characters are case folded. SQLite does not attempt to do full UTF case folding due to the size of the tables required.
?。
?RTRIM -和BINARY一样,除了尾部的空格字符被忽略。


应用程序可以注册其他功能的使用 整理sqlite3_create_collation()接口


6.1 AssigningCollating Sequences from SQL


Every column of every table has an associated collating function.If no collating function is explicitly defined, then the collating functiondefaults to BINARY. The COLLATE clause of the column definition is used to define alternativecollating functions for a column.


The rules for determining which collating function to use for abinary comparison operator (=, <, >, <=, >=, !=, IS, and IS NOT)are as follows and in the order shown:


1.? If either operand has an explicit collating function assignmentusing the postfix COLLATEoperator, then the explicit collating function is used forcomparison, with precedence to the collating function of the left operand.


2.? If either operand is a column, then the collating function of thatcolumn is used with precedence to the left operand. For the purposes of theprevious sentence, a column name preceded by one or more unary "+"operators is still considered a column name.


3.? Otherwise, the BINARY collating function is used for comparison.


The expression "x BETWEEN y and z" is logicallyequivalent to two comparisons "x >= y AND x <= z" and workswith respect to collating functions as if it were two separate comparisons. Theexpression "x IN (SELECT y ...)" is handled in the same way as theexpression "x = y" for the purposes of determining the collatingsequence. The collating sequence used for expressions of the form "x IN(y, z, ...)" is the collating sequence of x.


Terms of the ORDER BY clause that is part of a SELECT statement may be assigned a collatingsequence using the COLLATEoperator, in which case the specified collating function is used forsorting. Otherwise, if the expression sorted by an ORDER BY clause is a column,then the collating sequence of the column is used to determine sort order. Ifthe expression is not a column and has no COLLATE clause, then the BINARYcollating sequence is used.


6.2排序序列的例子


CREATE TABLE t1(
? ? x INTEGER PRIMARY KEY,
? ? a,? ? ? ? ? ? ? ? /* collating sequence BINARY */
? ? b COLLATE BINARY,? /* collating sequence BINARY */
? ? c COLLATE RTRIM,? /* collating sequence RTRIM? */
? ? d COLLATE NOCASE? /* collating sequence NOCASE */
);
? ? ? ? ? ? ? ? ? /* x? a? ? b? ? c? ? ? d */
INSERT INTO t1 VALUES(1,'abc','abc', 'abc? ','abc');
INSERT INTO t1 VALUES(2,'abc','abc', 'abc',? 'ABC');
INSERT INTO t1 VALUES(3,'abc','abc', 'abc ', 'Abc');
INSERT INTO t1 VALUES(4,'abc','abc ','ABC',? 'abc');
?
/* Text comparison a=b is performed using the BINARY collating sequence. */
SELECT x FROM t1 WHERE a = b ORDER BY x;
--result 1 2 3


/* Text comparison a=b is performed using the RTRIM collating sequence. */
SELECT x FROM t1 WHERE a = b COLLATE RTRIM ORDER BY x;
--result 1 2 3 4


/* Text comparison d=a is performed using the NOCASE collating sequence. */
SELECT x FROM t1 WHERE d = a ORDER BY x;
--result 1 2 3 4


/* Text comparison a=d is performed using the BINARY collating sequence. */
SELECT x FROM t1 WHERE a = d ORDER BY x;
--result 1 4


/* Text comparison 'abc'=c is performed using the RTRIM collating sequence. */
SELECT x FROM t1 WHERE 'abc' = c ORDER BY x;
--result 1 2 3


/* Text comparison c='abc' is performed using the RTRIM collating sequence. */
SELECT x FROM t1 WHERE c = 'abc' ORDER BY x;
--result 1 2 3


/* Grouping is performed using the NOCASE collating sequence (Values
** 'abc', 'ABC', and 'Abc' are placed in the same group). */
SELECT count(*) FROM t1 GROUP BY d ORDER BY 1;
--result 4


/* Grouping is performed using the BINARY collating sequence.? 'abc' and
** 'ABC' and 'Abc' form different groups */
SELECT count(*) FROM t1 GROUP BY (d || '') ORDER BY 1;
--result 1 1 2


/* Sorting or column c is performed using the RTRIM collating sequence. */
SELECT x FROM t1 ORDER BY c, x;
--result 4 1 2 3


/* Sorting of (c||'') is performed using the BINARY collating sequence. */
SELECT x FROM t1 ORDER BY (c||''), x;
--result 4 2 3 1


/* Sorting of column c is performed using the NOCASE collating sequence. */
SELECT x FROM t1 ORDER BY c COLLATE NOCASE, x;
--result 2 4 3 1


总算能完啦,虽然不完善,但是够我用啦,以后遇到再慢慢补充。


首页 上一页 1 2 3 下一页 尾页 3/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Oracle闪回技术flashback 下一篇Linux下MySQL 5.6.24的编译安装与..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·如何在 C 语言中管理 (2025-12-25 03:20:14)
·C语言和内存管理有什 (2025-12-25 03:20:11)
·为什么C语言从不被淘 (2025-12-25 03:20:08)
·常用meta整理 | 菜鸟 (2025-12-25 01:21:52)
·SQL HAVING 子句:深 (2025-12-25 01:21:47)