duankan8739 2014-12-18 14:32
浏览 235
已采纳

MySQL到SQLite的迁移。 我需要更新数据类型吗?

I migrated our application from MySQL to SQLite using mysql2sqlite.sh.

I updated our PDO connection string and it continues to work without issue for some weeks but whilst browsing the database using DB Browser for SQLite I came across something odd; it appears the script didn't update the data types to be SQLite compatible, but it continues to work. How is this?

Table

CREATE TABLE `events` (
    `id`    INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    `Forename`  varchar(255) NOT NULL,
    `Surname`   varchar(255) NOT NULL,
    `Site`  TEXT,
    `Badge` varchar(255) NOT NULL,
    `Start` datetime NOT NULL,
    `End`   datetime NOT NULL,
    `Created`   timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
);

How does it continue to work without issue whilst using MySQL data types?

According to SQLite documentation most of these data types don't exist in SQLite but it continues to work.

Should I alter the data types to TEXT or something else supported by SQLite?

Update

According to SQLite documentation, these are data types:

INTEGER
TEXT
BLOB
REAL
NUMERIC

but it continues to work without issue using:

varchar(255)
datetime
timestamp

How is this?

  • 写回答

2条回答 默认 最新

  • dppxp79175 2014-12-18 14:49
    关注

    From the docs -

    SQLite essentially supports what is called "type affinity". SQLite performs a conversion of things like varchar to text for storage purposes.

    A column with TEXT affinity stores all data using storage classes NULL, TEXT or BLOB. If numerical data is inserted into a column with TEXT affinity it is converted into text form before being stored.

    SQLite breaks up the affinity into groups (TEXT, NUMERIC, INTEGER, REAL, NONE) and each group honors standard SQL data types for conversion in those columns.

    You do not have to alter data types during your conversion as SQLite will recognize and convert as appropriate to its affinity types.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效