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

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

报告相同问题?

悬赏问题

  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题