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

SQL Server Table and columns auto complete #223

Closed GnRSlash closed 4 years ago

GnRSlash commented 5 years ago

Issue Type

Feature Request

Description

When I start typing the sql query, the plugin does not bring the tables or columns, but I noticed that it works or not according to SQL Server version: SQL Server Version: 11.0.7001.0 -> It Works SQL Server Version: 10.50.6000.34 -> Doesn't Work

Version

Expected behavior: [What you expected to happen] Bring the tables names and columns names

Actual behavior: [What actually happened] Doesn't show

GnRSlash commented 4 years ago

I discovered that the problem is not about SQL Version but Collation in use! If Collation is binary, sqltools can't read tables and columns If Collation is case insensitive, sqltools works!

Is there a way to solve this because I can't change collation of the database =[

tkopets commented 4 years ago

Unfortunately, I don't have SQL Server installed and cannot help you test out this issue.

A few things that might help to troubleshoot.

  1. Setting debug: true in ST: Settings and restart Sublime Text.
  2. Look for errors in the console View -> Show Console
  3. Try running the same queries as SQLTools runs in different collations to see if the output is different (see them below).

Tables

set nocount on; select concat(table_schema, '.', table_name) as obj from information_schema.tables order by table_schema, table_name;

Columns

set nocount on; select distinct concat(table_name, '.', column_name) as obj from information_schema.columns;
GnRSlash commented 4 years ago

Ok, problem solved! FIX: edit the SQLTools.sublime-settings -- User and put this: NOTE: I just change: incofmation_schema.tables, information_schema.columns and information_schema.routines to ALLCAPS texts and now I can press Ctrl+e, Ctrl+d and it lists all tables and columns from binary and non binary databases!!!

"cli_options": {
    "mssql": {
        "options": [],
        "before": [],
        "after": ["go", "quit"],
        "args": "-d \"{database}\"",
        "args_optional": ["-S \"{host},{port}\"", "-S \"{host}\\{instance}\"", "-U \"{username}\"", "-P \"{password}\""],
        "queries": {
            "execute": {
                "options": ["-k"]
            },
            "show records": {
                "query": "select top {1} * from {0};",
                "options": []
            },
            "desc table": {
                "query": "exec sp_help N'{0}';",
                "options": ["-y30", "-Y30"]
            },
            "desc function": {
                "query": "exec sp_helptext N'{0}';",
                "options": ["-h-1"]
            },
            "explain plan": {
                "query": "{0};",
                "options": ["-k"],
                "before": [
                    "SET STATISTICS PROFILE ON",
                    "SET STATISTICS IO ON",
                    "SET STATISTICS TIME ON"
                ]
            },
            "desc": {
                "query": "set nocount on; select concat(table_schema, '.', table_name) as obj from INFORMATION_SCHEMA.TABLES order by table_schema, table_name;",
                "options": ["-h-1", "-r1"]
            },
            "columns": {
                "query": "set nocount on; select distinct concat(table_name, '.', column_name) as obj from INFORMATION_SCHEMA.COLUMNS;",
                "options": ["-h-1", "-r1"]
            },
            "functions": {
                "query": "set nocount on; select concat(routine_schema, '.', routine_name) as obj from INFORMATION_SCHEMA.ROUTINES order by routine_schema, routine_name;",
                "options": ["-h-1", "-r1"]
            }
        }
    },
},

Thank you for your help!