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条)

报告相同问题?

悬赏问题

  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退
  • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?