首页 > 解决方案 > 无法将 sql 转换为 sqlite

问题描述

此查询是针对 php 5.7 脚本进行的,不再起作用,我的提供商是 one.com,这就是他们使用的:PHP Versie:7.1.30 MySQL versie:10.3.14-MariaDB-1:10.3.14+maria ~仿生

已经在这里多次寻求答案,通常我会修复它,但这个让我头疼!尝试过 DB Fiddle,他们总是遇到同样的错误:

查询错误:错误:SQLITE_ERROR:靠近“KEY”:语法错误,并且,查询错误:错误:SQLITE_ERROR:靠近“unsigned”:语法错误

CREATE TABLE IF NOT EXISTS `bo_hourly` (
  `time` int(15) NOT NULL,
  `strikes` int(6) NOT NULL,
  `st_strikes` int(8) NOT NULL,
  UNIQUE KEY `time` (`time`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

CREATE TABLE IF NOT EXISTS `bo_stat` (
  `date` date NOT NULL,
  `strikes` mediumint(11) unsigned NOT NULL DEFAULT '0',
  `maxdist` int(6) NOT NULL DEFAULT '0',
  `mindist` int(6) NOT NULL DEFAULT '999999',
  `maxstrikes` mediumint(11) unsigned NOT NULL DEFAULT '0',
  `maxtime` int(15) unsigned NOT NULL DEFAULT '0',
  `maxusers` int(6) NOT NULL DEFAULT '0',
  `st_strikes` int(8) NOT NULL,
  `st_mindist` int(6) NOT NULL DEFAULT '999999',
  `st_maxdist` int(6) NOT NULL DEFAULT '0',
  `st_max` int(6) NOT NULL,
  `st_maxtime` int(15) NOT NULL,
  KEY `time` (`date`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

我知道它一定很简单,但“key”和“unsigned”附近的东西似乎是错误的,如果有人能在路上帮助我,也许我搜索得太牵强了......

标签: mysqlsqlite

解决方案


一个有效的 SQLite 代码如下所示,它与您的 MySQL 代码匹配。

注意 MySQL 中的int(6)andint(8)仍然存储相同的(最大)信息,因为这取决于zerofill ...

int(6)不存储999999您在查看默认值时可能会考虑的最大值。如果您想要或需要限制最大值,我建议您查看CREATE TABLE ... 语法CHECK Constraint中也解释过的最大值

CREATE TABLE IF NOT EXISTS bo_hourly (
  time int NOT NULL,
  strikes int NOT NULL,
  st_strikes int NOT NULL,
  UNIQUE (time)
);

CREATE TABLE IF NOT EXISTS bo_stat (
  date date NOT NULL,
  strikes int NOT NULL DEFAULT '0',
  maxdist int NOT NULL DEFAULT '0',
  mindist int NOT NULL DEFAULT '999999',
  maxstrikes int NOT NULL DEFAULT '0',
  maxtime int NOT NULL DEFAULT '0',
  maxusers int NOT NULL DEFAULT '0',
  st_strikes int NOT NULL,
  st_mindist int NOT NULL DEFAULT '999999',
  st_maxdist int NOT NULL DEFAULT '0',
  st_max int NOT NULL,
  st_maxtime int NOT NULL
);

# There is no column time in the bo_stat table
# CREATE INDEX IF NOT EXISTS time ON bo_stat(time); 

演示


推荐阅读