Skip to content

Commit 00c467a

Browse files
authored
Merge branch 'master' into emptypass
2 parents a35ed9d + 69e9fc2 commit 00c467a

File tree

13 files changed

+109
-31
lines changed

13 files changed

+109
-31
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ $ sudo apt-get install mycli # Only on debian or ubuntu
9696
--local-infile BOOLEAN Enable/disable LOAD DATA LOCAL INFILE.
9797
--login-path TEXT Read this path from the login file.
9898
-e, --execute TEXT Execute command and quit.
99+
--init-command TEXT SQL statement to execute after connecting.
99100
--help Show this message and exit.
100101

101102
Features

changelog.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
TBD
22
===
33

4+
Features:
5+
---------
6+
7+
* Add an option `--init-command` to execute SQL after connecting (Thanks: [KITAGAWA Yasutaka]).
8+
9+
1.22.2
10+
======
11+
12+
Bug Fixes:
13+
----------
14+
15+
* Make the `pwd` module optional.
16+
17+
1.22.1
18+
======
19+
20+
Bug Fixes:
21+
----------
22+
* Fix the breaking change introduced in PyMySQL 0.10.0. (Thanks: [Amjith]).
23+
424
Features:
525
---------
626
* Add an option `--ssh-config-host` to read ssh configuration from OpenSSH configuration file.
@@ -22,6 +42,7 @@ Bug Fixes:
2242

2343
* Fix broken auto-completion for favorite queries (Thanks: [Amjith]).
2444
* Fix undefined variable exception when running with --no-warn (Thanks: [Georgy Frolov])
45+
* Support setting color for null value (Thanks: [laixintao])
2546

2647
1.21.0
2748
======
@@ -763,3 +784,4 @@ Bug Fixes:
763784
[Frederic Aoustin]: https://github.com/fraoustin
764785
[Georgy Frolov]: https://github.com/pasenor
765786
[Zach DeCook]: https://zachdecook.com
787+
[laixintao]: https://github.com/laixintao

mycli/AUTHORS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ Contributors:
7373
* Takeshi D. Itoh
7474
* laixintao
7575
* Zach DeCook
76+
* kevinhwang91
77+
* KITAGAWA Yasutaka
7678

7779
Creator:
7880
--------

mycli/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.21.1'
1+
__version__ = '1.22.2'

mycli/clistyle.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
Token.Output.Header: 'output.header',
3535
Token.Output.OddRow: 'output.odd-row',
3636
Token.Output.EvenRow: 'output.even-row',
37+
Token.Output.Null: 'output.null',
3738
Token.Prompt: 'prompt',
3839
Token.Continuation: 'continuation',
3940
}

mycli/main.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
import re
77
import fileinput
88
from collections import namedtuple
9-
from pwd import getpwuid
9+
try:
10+
from pwd import getpwuid
11+
except ImportError:
12+
pass
1013
from time import time
1114
from datetime import datetime
1215
from random import choice
@@ -95,7 +98,7 @@ class MyCli(object):
9598
xdg_config_home = "~/.config"
9699
system_config_files = [
97100
'/etc/myclirc',
98-
os.path.join(xdg_config_home, "mycli", "myclirc")
101+
os.path.join(os.path.expanduser(xdg_config_home), "mycli", "myclirc")
99102
]
100103

101104
default_config_file = os.path.join(PACKAGE_ROOT, 'myclirc')
@@ -360,7 +363,7 @@ def merge_ssl_with_cnf(self, ssl, cnf):
360363
def connect(self, database='', user='', passwd='', host='', port='',
361364
socket='', charset='', local_infile='', ssl='',
362365
ssh_user='', ssh_host='', ssh_port='',
363-
ssh_password='', ssh_key_filename=''):
366+
ssh_password='', ssh_key_filename='', init_command=''):
364367

365368
cnf = {'database': None,
366369
'user': None,
@@ -417,7 +420,7 @@ def _connect():
417420
self.sqlexecute = SQLExecute(
418421
database, user, passwd, host, port, socket, charset,
419422
local_infile, ssl, ssh_user, ssh_host, ssh_port,
420-
ssh_password, ssh_key_filename
423+
ssh_password, ssh_key_filename, init_command
421424
)
422425
except OperationalError as e:
423426
if ('Access denied for user' in e.args[1]):
@@ -426,7 +429,7 @@ def _connect():
426429
self.sqlexecute = SQLExecute(
427430
database, user, new_passwd, host, port, socket,
428431
charset, local_infile, ssl, ssh_user, ssh_host,
429-
ssh_port, ssh_password, ssh_key_filename
432+
ssh_port, ssh_password, ssh_key_filename, init_command
430433
)
431434
else:
432435
raise e
@@ -1048,14 +1051,17 @@ def get_last_query(self):
10481051
help='Read this path from the login file.')
10491052
@click.option('-e', '--execute', type=str,
10501053
help='Execute command and quit.')
1054+
@click.option('--init-command', type=str,
1055+
help='SQL statement to execute after connecting.')
10511056
@click.argument('database', default='', nargs=1)
10521057
def cli(database, user, host, port, socket, password, dbname,
10531058
version, verbose, prompt, logfile, defaults_group_suffix,
10541059
defaults_file, login_path, auto_vertical_output, local_infile,
10551060
ssl_ca, ssl_capath, ssl_cert, ssl_key, ssl_cipher,
10561061
ssl_verify_server_cert, table, csv, warn, execute, myclirc, dsn,
10571062
list_dsn, ssh_user, ssh_host, ssh_port, ssh_password,
1058-
ssh_key_filename, list_ssh_config, ssh_config_path, ssh_config_host):
1063+
ssh_key_filename, list_ssh_config, ssh_config_path, ssh_config_host,
1064+
init_command):
10591065
"""A MySQL terminal client with auto-completion and syntax highlighting.
10601066
10611067
\b
@@ -1179,7 +1185,8 @@ def cli(database, user, host, port, socket, password, dbname,
11791185
ssh_host=ssh_host,
11801186
ssh_port=ssh_port,
11811187
ssh_password=ssh_password,
1182-
ssh_key_filename=ssh_key_filename
1188+
ssh_key_filename=ssh_key_filename,
1189+
init_command=init_command
11831190
)
11841191

11851192
mycli.logger.debug('Launch Params: \n'

mycli/myclirc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ bottom-toolbar.transaction.failed = 'bg:#222222 #ff005f bold'
111111
output.header = "#00ff5f bold"
112112
output.odd-row = ""
113113
output.even-row = ""
114+
output.null = "#808080"
114115

115116
# Favorite queries.
116117
[favorite_queries]

mycli/sqlexecute.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sqlparse
44
from .packages import special
55
from pymysql.constants import FIELD_TYPE
6-
from pymysql.converters import (convert_mysql_timestamp, convert_datetime,
6+
from pymysql.converters import (convert_datetime,
77
convert_timedelta, convert_date, conversions,
88
decoders)
99
try:
@@ -42,7 +42,7 @@ class SQLExecute(object):
4242

4343
def __init__(self, database, user, password, host, port, socket, charset,
4444
local_infile, ssl, ssh_user, ssh_host, ssh_port, ssh_password,
45-
ssh_key_filename):
45+
ssh_key_filename, init_command=None):
4646
self.dbname = database
4747
self.user = user
4848
self.password = password
@@ -59,12 +59,13 @@ def __init__(self, database, user, password, host, port, socket, charset,
5959
self.ssh_port = ssh_port
6060
self.ssh_password = ssh_password
6161
self.ssh_key_filename = ssh_key_filename
62+
self.init_command = init_command
6263
self.connect()
6364

6465
def connect(self, database=None, user=None, password=None, host=None,
6566
port=None, socket=None, charset=None, local_infile=None,
6667
ssl=None, ssh_host=None, ssh_port=None, ssh_user=None,
67-
ssh_password=None, ssh_key_filename=None):
68+
ssh_password=None, ssh_key_filename=None, init_command=None):
6869
db = (database or self.dbname)
6970
user = (user or self.user)
7071
password = (password or self.password)
@@ -79,6 +80,7 @@ def connect(self, database=None, user=None, password=None, host=None,
7980
ssh_port = (ssh_port or self.ssh_port)
8081
ssh_password = (ssh_password or self.ssh_password)
8182
ssh_key_filename = (ssh_key_filename or self.ssh_key_filename)
83+
init_command = (init_command or self.init_command)
8284
_logger.debug(
8385
'Connection DB Params: \n'
8486
'\tdatabase: %r'
@@ -93,13 +95,15 @@ def connect(self, database=None, user=None, password=None, host=None,
9395
'\tssh_host: %r'
9496
'\tssh_port: %r'
9597
'\tssh_password: %r'
96-
'\tssh_key_filename: %r',
98+
'\tssh_key_filename: %r'
99+
'\tinit_command: %r',
97100
db, user, host, port, socket, charset, local_infile, ssl,
98-
ssh_user, ssh_host, ssh_port, ssh_password, ssh_key_filename
101+
ssh_user, ssh_host, ssh_port, ssh_password, ssh_key_filename,
102+
init_command
99103
)
100104
conv = conversions.copy()
101105
conv.update({
102-
FIELD_TYPE.TIMESTAMP: lambda obj: (convert_mysql_timestamp(obj) or obj),
106+
FIELD_TYPE.TIMESTAMP: lambda obj: (convert_datetime(obj) or obj),
103107
FIELD_TYPE.DATETIME: lambda obj: (convert_datetime(obj) or obj),
104108
FIELD_TYPE.TIME: lambda obj: (convert_timedelta(obj) or obj),
105109
FIELD_TYPE.DATE: lambda obj: (convert_date(obj) or obj),
@@ -110,12 +114,16 @@ def connect(self, database=None, user=None, password=None, host=None,
110114
if ssh_host:
111115
defer_connect = True
112116

117+
client_flag = pymysql.constants.CLIENT.INTERACTIVE
118+
if init_command and len(list(special.split_queries(init_command))) > 1:
119+
client_flag |= pymysql.constants.CLIENT.MULTI_STATEMENTS
120+
113121
conn = pymysql.connect(
114122
database=db, user=user, password=password, host=host, port=port,
115123
unix_socket=socket, use_unicode=True, charset=charset,
116-
autocommit=True, client_flag=pymysql.constants.CLIENT.INTERACTIVE,
124+
autocommit=True, client_flag=client_flag,
117125
local_infile=local_infile, conv=conv, ssl=ssl, program_name="mycli",
118-
defer_connect=defer_connect
126+
defer_connect=defer_connect, init_command=init_command
119127
)
120128

121129
if ssh_host:
@@ -146,6 +154,7 @@ def connect(self, database=None, user=None, password=None, host=None,
146154
self.socket = socket
147155
self.charset = charset
148156
self.ssl = ssl
157+
self.init_command = init_command
149158
# retrieve connection id
150159
self.reset_connection_id()
151160

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
'sqlparse>=0.3.0,<0.4.0',
2525
'configobj >= 5.0.5',
2626
'cryptography >= 1.0.0',
27-
'cli_helpers[styles] > 1.1.0',
27+
'cli_helpers[styles] >= 2.0.1',
2828
]
2929

3030

test/features/steps/auto_vertical.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ def step_see_large_results(context):
4141
'***************************\r\n' +
4242
'{}\r\n'.format('\r\n'.join(rows) + '\r\n'))
4343

44-
wrappers.expect_pager(context, expected, timeout=5)
44+
wrappers.expect_pager(context, expected, timeout=10)
4545
wrappers.expect_exact(context, '1 row in set', timeout=2)

0 commit comments

Comments
 (0)