mtxr / SublimeText-SQLTools

SQLTools for Sublime Text 3
https://code.mteixeira.dev/SublimeText-SQLTools/
GNU General Public License v3.0
177 stars 40 forks source link

SQLTools unable to execute #123

Closed markljackson closed 7 years ago

markljackson commented 7 years ago

Issue Type

Prerequisites (For bugfixes)

Description

No matter how I try to activate SQLTools database commands, I get nothing. When I checked the console I found this:

Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 797, in run_
    return self.run()
  File "/Users/-USERNAME-/Library/Application Support/Sublime Text 3/Packages/SQLTools/SQLTools.py", line 469, in run
    ST.selectConnection(tablesCallback=lambda: Window().run_command('st_execute'))
  File "/Users/-USERNAME-/Library/Application Support/Sublime Text 3/Packages/SQLTools/SQLTools.py", line 269, in selectConnection
    ST.connectionList = getConnections()
  File "/Users/-USERNAME-/Library/Application Support/Sublime Text 3/Packages/SQLTools/SQLTools.py", line 79, in getConnections
    startPlugin()
  File "/Users/-USERNAME-/Library/Application Support/Sublime Text 3/Packages/SQLTools/SQLTools.py", line 62, in startPlugin
    connections = Settings(CONNECTIONS_FILENAME, default=CONNECTIONS_FILENAME_DEFAULT)
  File "/Users/-USERNAME-/Library/Application Support/Sublime Text 3/Packages/SQLTools/SQLToolsAPI/Storage.py", line 18, in __init__
    self.all()
  File "/Users/-USERNAME-/Library/Application Support/Sublime Text 3/Packages/SQLTools/SQLToolsAPI/Storage.py", line 21, in all
    self.items = U.parseJson(self.getFilename())
  File "/Users/-USERNAME-/Library/Application Support/Sublime Text 3/Packages/SQLTools/SQLToolsAPI/Utils.py", line 47, in parseJson
    return json.loads(content, encoding='utf-8')
  File "./python3.3/json/__init__.py", line 316, in loads
  File "./python3.3/json/decoder.py", line 351, in decode
  File "./python3.3/json/decoder.py", line 367, in raw_decode
ValueError: Expecting object: line 19 column 2 (char 261)

I am able to bring up the settings panels, but not able to connect to the database, or run a query..

NOTE: I was able to set up SQLExec, and that works fine.

Steps to Reproduce (For bugfixes)

  1. open COMMAND PALETTE
  2. type in ST:
  3. try to execute any database command

Expected behavior: [What you expected to happen]

I expected to be able to connect to mysql, and run a query.

Actual behavior: [What actually happened]

Nothing. I had to look in the console to see what was happening.

Versions

tkopets commented 7 years ago

Most probably you have some kind of problem in SQLToolsConnections.sublime-settings, could be invalid json ?

Can you post your entire connections json file?

markljackson commented 7 years ago

I've redacted the password. It has a "0", and "!" in it; the rest are letters, two caps.

I've also tried "default": null, and "default": "bank"

{
  "connections": {
    "bank": {
      "type"    : "mysql",
      "host"    : "127.0.0.1",
      "port"    :  3306,
      "database": "bank",
      "username": "lrnsql",
      // use of password for MySQL is not recommended (use "defaults-extra-file" or "login-path")
      "password": "redacted",  // you will get a security warning in the output
      // "defaults-extra-file": "/path/to/defaults_file_with_password",  // use [client] or [mysql] section
      // "login-path": "your_login_path",  
      // login path in your ".mylogin.cnf"
      "encoding": "utf-8"
  },
  // "default": "bank"
 "default" : null
}
tkopets commented 7 years ago

You have missing one closing } bracket (3 open curly brackets and only 2 closing).

tkopets commented 7 years ago
{
  "connections": {
    "bank": {
      "type"    : "mysql",
      "host"    : "127.0.0.1",
      "port"    :  3306,
      "database": "bank",
      "username": "lrnsql",
      // use of password for MySQL is not recommended (use "defaults-extra-file" or "login-path")
      "password": "redacted",  // you will get a security warning in the output
      // "defaults-extra-file": "/path/to/defaults_file_with_password",  // use [client] or [mysql] section
      // "login-path": "your_login_path",  
      // login path in your ".mylogin.cnf"
      "encoding": "utf-8"
  },
  // "default": "bank"
 "default" : null
}
}
markljackson commented 7 years ago

Ok, I set that up correctly, but now I'm getting this:

Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 797, in run_
    return self.run()
  File "/Users/-USERNAME-/Library/Application Support/Sublime Text 3/Packages/SQLTools/SQLTools.py", line 469, in run
    ST.selectConnection(tablesCallback=lambda: Window().run_command('st_execute'))
  File "/Users/-USERNAME-/Library/Application Support/Sublime Text 3/Packages/SQLTools/SQLTools.py", line 269, in selectConnection
    ST.connectionList = getConnections()
  File "/Users/-USERNAME-/Library/Application Support/Sublime Text 3/Packages/SQLTools/SQLTools.py", line 84, in getConnections
    connectionsObj[name] = createConnection(name, config, settings=settings.all())
  File "/Users/-USERNAME-/Library/Application Support/Sublime Text 3/Packages/SQLTools/SQLTools.py", line 101, in createConnection
    newConnection = Connection(name, config, settings=settings)
  File "/Users/-USERNAME-/Library/Application Support/Sublime Text 3/Packages/SQLTools/SQLToolsAPI/Connection.py", line 48, in __init__
    self.type       = options.get('type', None)
AttributeError: 'NoneType' object has no attribute 'get'

Do I need to specify the path to MYSQL? Or am I missing something else?

I tested again in SQLExec, and it's finding MYSQL, and running queries.

tkopets commented 7 years ago

Mark, I was on mobile and couldn't test my suggestion. I made a mistake and put the brace in wrong place. I've double checked and this one should work for you:

{
  "connections": {
    "bank": {
      "type"    : "mysql",
      "host"    : "127.0.0.1",
      "port"    :  3306,
      "database": "bank",
      "username": "lrnsql",
      // use of password for MySQL is not recommended (use "defaults-extra-file" or "login-path")
      "password": "redacted",  // you will get a security warning in the output
      // "defaults-extra-file": "/path/to/defaults_file_with_password",  // use [client] or [mysql] section
      // "login-path": "your_login_path",  
      // login path in your ".mylogin.cnf"
      "encoding": "utf-8"
    }
  },
  "default" : null
}

Here is the same content, but more indented version, so you can see the structure more clearly.

{
    "connections": {
        "bank": {
            "type"    : "mysql",
            "host"    : "127.0.0.1",
            "port"    :  3306,
            "database": "bank",
            "username": "lrnsql",
            // use of password for MySQL is not recommended (use "defaults-extra-file" or "login-path")
            "password": "redacted",  // you will get a security warning in the output
            // "defaults-extra-file": "/path/to/defaults_file_with_password",  // use [client] or [mysql] section
            // "login-path": "your_login_path",  
            // login path in your ".mylogin.cnf"
            "encoding": "utf-8"
        }
    },
    "default" : null
}
markljackson commented 7 years ago

That worked, thanks.

When I put in the new version, the color coding "looked right." I tried to modify the first version, and made it worse. lol.

Sublime Text is not my usual editor, and I'm not all that familiar with setting up it's plugins, or anything else for that matter.

Again, thanks for the help.