SQLite数据类型 [英] SQLite data types

查看:102
本文介绍了SQLite数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过 SQLite .com / sqlitejdbcrel =noreferrer> Zentus 。在这种情况下,我需要在我的数据库中保存和查询Java long 值。来自其他RDBMS我创建了以下表来存储长值:

I am using SQLite in a Java application through Zentus. In this context I need to save and query Java long values in my database. Coming from other RDBMS I created the table as following to store long values:

CREATE TABLE myTable (id INTEGER PRIMARY_KEY, longValue LONG)

此解决方案产生例外行为但在阅读关于数据类型的SQLite文档我知道我的 LONG 类型与使用<$相同的效果c $ c> TEXT => longValue 以文本形式存储。

This solution produces the excepted behavior but after reading the SQLite documentation on data types I understood that my LONG type has the same effect than using TEXT => longValue is stored as text.

然后我决定将此更改为 INTEGER (该长度是可变的,并且可以存储多达64位的整数,这是Java long的长度),以便拥有更清晰的代码,并且可能是保存一些磁盘空间并提高性能,因为我的longValues被插入并查询为 long

I then decided to change this to INTEGER (which length is variable and can store up to 64 bit integers which is the length of Java long) in order to have cleaner code and may be to save some disk space and to increase performances because my longValues are inserted and queried as long.

比较性能后和创建的数据库的大小我无法看到之间的任何区别:

After comparing the performances and the size of the created databases I am not able to see any difference between:

CREATE TABLE myTable (id INTEGER PRIMARY_KEY, longValue LONG)

CREATE TABLE myTable (id INTEGER PRIMARY_KEY, longValue INTEGER)

关于这个主题的任何评论,经验或感受?

Any comments, experiences or feelings on the subject?

推荐答案

在SQLite中,数据类型是值,而不是每列。因此,当您插入整数时,无论列类型如何,它们都将存储为整数。

In SQLite, data types are per-value, not per-column. So when you insert integers, they're stored as integers regardless of the column type.

这篇关于SQLite数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆