Bug #82768 mysqlsh fails if multiple options are given in hashbang
Submitted: 28 Aug 2016 18:32 Modified: 11 May 18:42
Reporter: Daniël van Eeden (OCA) Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Document Store: MySQL Shell Severity:S3 (Non-critical)
Version:1.0.4 OS:Any
Assigned to: CPU Architecture:Any

[28 Aug 2016 18:32] Daniël van Eeden
Description:
This works:
#!/usr/bin/mysqlsh --file

This doesn't:
#!/usr/bin/mysqlsh --py --file

The result is that only javascript scripts work with the hashbang.

Related:
https://dev.mysql.com/doc/refman/5.7/en/mysql-shell-batch-code-execution.html

How to repeat:
[dvaneeden@dve-mac tmp]$ ./test.py 
/usr/bin/mysqlsh: unknown option --py --file
[dvaneeden@dve-mac tmp]$ head -1 test.py
#!/usr/bin/mysqlsh --py --file
[dvaneeden@dve-mac tmp]$ /usr/bin/mysqlsh --py --file test.py
{"_id": "765fb4974c6de611b67bac87a3027d34", "foo2": "bar2"}
{"_id": "aa3516904c6de611b67bac87a3027d34", "foo": "bar"}
[dvaneeden@dve-mac tmp]$ cat test.py
#!/usr/bin/mysqlsh --py --file
import mysqlx
mysession = mysqlx.getSession('msandbox:msandbox@127.0.0.1:33060')
mytest = mysession.getSchema('test')
result = mytest.t1.find().execute()
while True:
    record = result.fetchOne()
    if record is None:
        break
    print(record)
[28 Aug 2016 18:36] Daniël van Eeden
To create the test data:

mysql-py> \use test
Schema `test` accessible through db.
mysql-py> db.createCollection("t1")
<Collection:t1>
mysql-py> db.t1.add({'foo': 'bar'})
Query OK, 1 item affected (0.02 sec)

mysql-py> db.t1.add({'foo2': 'bar2'})
Query OK, 1 item affected (0.02 sec)
[28 Aug 2016 18:40] Umesh Shastry
Hello Daniël,

Thank you for the report.

Thanks,
Umesh
[11 May 18:42] Hema Sridharan
From Development:
*Not a bug (anymore)*
 
Fedora 24x64
 
MySQL Server 5.7.17
 
21082704.mysql-shell-1.0.6-0.1.fc24.x86_64
 
After a couple of changes to the "test.py" file I made it work without
problems:
 
First, create the collection "t1":
 
mysql-py> db.createCollection("t1")
 
<Collection:t1>
 
mysql-py> db.t1.add({'foo': 'bar'})
 
Query OK, 1 item affected (0.02 sec)
 
mysql-py> db.t1.add({'foo2': 'bar2'})
 
 
 
*test.py*
 
{noformat}
 
#!/usr/bin/mysqlsh --py --file
 
from mysqlsh import mysqlx
 
mysession = mysqlx.get_node_session('root:guidev!@127.0.0.1:33060')
 
mytest = mysession.get_schema('test')
 
result = mytest.t1.find().execute()
 
while True:
 
    record = result.fetch_one()
 
    if record is None:
 
        break
 
print(record)
 
{noformat}
 
 
 
*Result:*
 
$ mysqlsh --py --file test.py
 
None