U
    4Je                  4   @   s  d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl	m
Z
 ddlmZmZ ddlmZ dd	lmZmZmZ e ejd
dejddddddejddeeddejdddddejdddddejddddddejdd dd!ddejd"d#dd$ed%d&ejd'dd(d)ejd*d+d,d-d)ejd.d/ed0d1d2ejd3d4dd5dejd6d7ejed$d8d9d:d2ejd;d<dd=dejd>d?d@d)ejdAdBdCd)ejdDejed$d8dEdFd2ejdGdEejee d$d8dHddIdJejdKdEejdLdM e D d$d8ddNdOejdPdQddRdejdSddTdejdUdVeddWd2ejdXdYe dZd[ejd\d]dd^dejd_dd`dejee dadbgdcdddeejedff ejej e  e!e!ee!eeeee!ee!eeeeee!e!eejedff e!e!ddgdhdiZ"dS )jz-The command line interface of SQLite3toMySQL.    N)CharacterSet)tabulate   )SQLite3toMySQL)OptionEatAllprompt_password)info)MYSQL_INSERT_METHODMYSQL_TEXT_COLUMN_TYPESmysql_supported_character_setsz-fz--sqlite-fileT)existszSQLite3 database file)typedefaulthelprequiredz-tz--sqlite-tableszTransfer only these specific tables (space separated table names). Implies --without-foreign-keys which inhibits the transfer of foreign keys.)r   clsr   z-Xz--without-foreign-keyszDo not transfer foreign keys.)is_flagr   z-Wz--ignore-duplicate-keyszIgnore duplicate keys. The default behavior is to create new ones with a numerical suffix, e.g. 'exising_key' -> 'existing_key_1'z-dz--mysql-databasezMySQL database name)r   r   r   z-uz--mysql-userz
MySQL userz-pz--prompt-mysql-passwordFzPrompt for MySQL password)r   r   callbackr   z--mysql-passwordzMySQL password)r   r   z-hz--mysql-host	localhostz"MySQL host. Defaults to localhost.z-Pz--mysql-porti  zMySQL port. Defaults to 3306.)r   r   r   z-Sz
--skip-sslz$Disable MySQL connection encryption.z-iz--mysql-insert-method)Zcase_sensitiveZIGNOREzMySQL insert method. DEFAULT will throw errors when encountering duplicate records; UPDATE will update existing rows; IGNORE will ignore insert errors. Defaults to IGNORE.z-Ez--mysql-truncate-tablesz0Truncates existing tables before inserting data.z--mysql-integer-typezINT(11)z6MySQL default integer field type. Defaults to INT(11).z--mysql-string-typezVARCHAR(255)z:MySQL default string field type. Defaults to VARCHAR(255).z--mysql-text-typeZTEXTz0MySQL default text field type. Defaults to TEXT.z--mysql-charsetutf8mb4z&MySQL database and table character set)metavarr   r   Zshow_defaultr   z--mysql-collationc                 C   s   g | ]
}|j qS  Z	collation).0charsetr   r   8/tmp/pip-unpacked-wheel-6qcj4cmz/sqlite3_to_mysql/cli.py
<listcomp>a   s     r   z"MySQL database and table collation)r   r   r   r   z-Tz--use-fulltextzyUse FULLTEXT indexes on TEXT columns. Will throw an error if your MySQL version does not support InnoDB FULLTEXT indexes!z--with-rowidzTransfer rowid columns.z-cz--chunkz!Chunk reading/writing SQL recordsz-lz
--log-filezLog file)r   r   z-qz--quietzQuiet. Display only errors.z--debugz"Debug mode. Will throw exceptions.ZsoftwareversionZgithub)headersZtablefmt)messagezos.PathLike[t.Any])sqlite_filesqlite_tableswithout_foreign_keysignore_duplicate_keys
mysql_userprompt_mysql_passwordmysql_passwordmysql_database
mysql_host
mysql_portskip_sslmysql_insert_methodmysql_truncate_tablesmysql_integer_typemysql_string_typemysql_text_typemysql_charsetmysql_collationuse_fulltext
with_rowidchunklog_filequietdebugreturnc                 C   s:  z|rXt dd t| D }|t|krXtd| d| ddd| d  dt| |pdt  |pz|d	k	ozt|d
k||p||||	|
||||||r| nd|r| nd	||||||d	  W nl t
k
r   |rނ td td Y n@ tk
r4 } z |r t| td W 5 d	}~X Y nX d	S )z8Transfer SQLite to MySQL using the provided CLI options.c                 s   s   | ]}|j V  qd S )Nr   )r   csr   r   r   	<genexpr>   s    zcli.<locals>.<genexpr>z3Error: Invalid value for '--collation' of charset 'z': 'z' is not one of 'z', '.Nr   r   )r    r!   r"   r$   r&   r'   r(   r)   Zmysql_ssl_disabledr+   r,   r-   r.   r/   r0   r1   r#   r2   r3   r4   r5   r6   z 
Process interrupted. Exiting...r   )tupler   lowersetclickZClickExceptionjoinr   lenZtransferKeyboardInterruptZechosysexit	Exception)r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   Zcharset_collationserrr   r   r   cli   sV    
$

rH   )#__doc__osrD   typingtr@   Zmysql.connectorr   r    r   Zclick_utilsr   r   Z
debug_infor   Zmysql_utilsr	   r
   r   commandoptionPathr=   intZChoicelistget_supportedZversion_optionUnionstrOptionalSequenceboolrH   r   r   r   r   <module>   s  

