Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

对bigint数据类型支持好像有问题 #2

Open
HotKin opened this issue Aug 19, 2023 · 7 comments
Open

对bigint数据类型支持好像有问题 #2

HotKin opened this issue Aug 19, 2023 · 7 comments

Comments

@HotKin
Copy link

HotKin commented Aug 19, 2023

bigint类型数据做ddl里是正常能解析出来的,但是在数据里bigint类型数据都是None,而且主键字段好像也没有生成ddl标识,可以优化吗

@ddcw
Copy link
Owner

ddcw commented Aug 20, 2023

bigint类型数据做ddl里是正常能解析出来的,但是在数据里bigint类型数据都是None,而且主键字段好像也没有生成ddl标识,可以优化吗

  1. 对于bigint的支持, 目前未解析bigint的数据(忘了, tinyint倒是解析了...), 对于未解析的数据, 都是返回None,
    bigint和其它数据类型(不含LOB和JSON)将在下一个版本支持.
    若现在需要的话, 可以编辑 innodb_type.py 文件, 在第77行处添加如下代码即可
    	if dtype == 'bigint':
		_t = struct.unpack('>Q',bdata[:8])[0]
		return (_t&((1<<63)-1)) if _t&(1<<63) else -(_t&((1<<63)-1))
  1. 目前是支持主键(在最后一行)的, 如下为使用例子:
(venv) 09:46:47 [root@ddcw21 innodb_parse]#python main.py --ddl --sql /data/mysql_3314/mysqldata/db1/t20230820.ibd 

 CREATE Table  db1.t20230820(
id int NOT NULL  ,
aa bigint NULL  ,
PRIMARY KEY(id)) ENGINE=InnoDB ; 

insert into db1.t20230820 values("1","1");
insert into db1.t20230820 values("111111111","11111111111111");
(venv) 09:47:36 [root@ddcw21 innodb_parse]#

@HotKin
Copy link
Author

HotKin commented Aug 20, 2023

感谢🙏

@HotKin
Copy link
Author

HotKin commented Aug 21, 2023

请问下能字段备注和表备注,默认值这些能处理吗?现在的 sql不是很标准,有这些属性的话

@HotKin
Copy link
Author

HotKin commented Aug 21, 2023

我今天发现tinyint类型数据解析的数据有问题,tinyint类型数据 0,解析后是 字符串128

@ddcw
Copy link
Owner

ddcw commented Aug 21, 2023

我今天发现tinyint类型数据解析的数据有问题,tinyint类型数据 0,解析后是 字符串128

  1. tinyint的数据我没验证过, 如果不符合要求,请自己修改相关代码, 也可以等下一个版本更新(时间不确定, 最近有点忙), 目前验证过的数据类型为varchar,char, date, int, time,timestamp,datetime

  2. DDL的属性目前只解析了是否为空(is_nullable),是否有默认值(default_value_utf8),注释(comment), 但是注释未加关键词comment和引号.... (未解析符号等其它属性)
    就像下面这样

(venv) 18:57:56 [root@ddcw21 innodb_parse]#python main.py --ddl /data/mysql_3314/mysqldata/db1/t20230821_2.ibd 

 CREATE Table  db1.t20230821_2(
id int NOT NULL  ,
id2 tinyint NULL  test tiny int,
id3 year NULL  ,
PRIMARY KEY(id)) ENGINE=InnoDB test ibd2sql;

@HotKin
Copy link
Author

HotKin commented Aug 21, 2023

好的,了解😀

@ddcw
Copy link
Owner

ddcw commented Aug 25, 2023

我今天发现tinyint类型数据解析的数据有问题,tinyint类型数据 0,解析后是 字符串128

我刚试了下, tinyint的数据 未做符号判断,(其它的也没做符号判断, 但都是当作有符号来解析的,), 下一个版本再做符号判断吧...
临时解决办法, 编辑innodb_type.py文件的第77行处添加如下代码即可(和bigint一样处理方法...)

        if dtype == 'tinyint':
                tdata = struct.unpack('>B',bdata)[0]
                return -(128-tdata) if tdata < 128 else tdata -128

效果:

(venv) 17:32:18 [root@ddcw21 innodb_parse]#python main.py --sql /data/mysql_3314/mysqldata/db1/t20230825.ibd
insert into db1.t20230825 values("1","-2");
insert into db1.t20230825 values("2","-1");
insert into db1.t20230825 values("3","0");
insert into db1.t20230825 values("4","1");
insert into db1.t20230825 values("5","2");
(venv) 17:32:19 [root@ddcw21 innodb_parse]#

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants