-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed SQL Server tables helpers #26
Conversation
Fixed SQL Server table helpers for foreign keys and references.
I've sorted it out now. Even though sql server uses the information schema it does not match that of Postgress as first thought. I noticed the References query was not pulling in all of the table references so I've updated that to. |
It works now, thanks! |
@pnetherwood I added support for schemas and jumping to foreign key from the results buffer. I would appreciate if you would test it with your big databases just to make sure everything works fine. |
I've just tried it and it worked fine on sql server. |
All of these issues are on mysql? |
I found an issue, and fixed it. Please do another test if possible. |
That's fixed the password issue. |
I got this when I tried the foreign key jump in sqlserver:
Also, when I do a Refresh (R) tables the tree does not change to reflect the addition and deletion of tables. |
I think i fixed both issues. Now schema is appended to the queries where applicable, and i introduced two variables, |
On the foreign key jump I get:
I was wondering if my foreign key query is returning the results in the form you are expecting. Also the the refresh is still not updating the tree. |
I'm using your query, just limiting results to 1 and getting two columns only. SELECT TOP 1
c2.table_name as foreign_table_name,
kcu2.column_name as foreign_column_name
from information_schema.table_constraints c
inner join information_schema.key_column_usage kcu
on c.constraint_schema = kcu.constraint_schema
and c.constraint_name = kcu.constraint_name
inner join information_schema.referential_constraints rc
on c.constraint_schema = rc.constraint_schema
and c.constraint_name = rc.constraint_name
inner join information_schema.table_constraints c2
on rc.unique_constraint_schema = c2.constraint_schema
and rc.unique_constraint_name = c2.constraint_name
inner join information_schema.key_column_usage kcu2
on c2.constraint_schema = kcu2.constraint_schema
and c2.constraint_name = kcu2.constraint_name
and kcu.ordinal_position = kcu2.ordinal_position
where c.constraint_type = 'FOREIGN KEY'
and kcu.column_name = '{column_name}'" Just add your |
I had to modify the query to include the table name and schema:
but then when I did I got a two column result. |
Why you had to include those? |
Because without it it was not unique. It was returning all of the foreign
keys in the database with a column of that name. I ran out without the TOP
1 to check.
…On Fri, 1 May 2020, 18:15 Kristijan Husak, ***@***.***> wrote:
Why you had to include those?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#26 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC2VNB3SXSEJZWJHIVXVF33RPL7TDANCNFSM4MWUB54Q>
.
|
I don't really know which schema and table is used in dbout buffer, that's why I rely only on column name. I don't expect it to return unique data, that's why I use |
Top 1 is not going to work unless the foreign key column name is unique across the whole database which is unlikely. |
Ah, I see how it works now. I was bringing up the foreign key constraint list and then trying to jump to the referenced table from the foreign key constraint. When I go to a table and jump from the from the row/column item it works great. Very nice. Apologies. I thought it was to jump from relationships not cells which explains why I was confused about the query. The gif really helped. Nice work. Did you have chance to look at the refresh? |
Yeah it's a bit hard to explain how it exactly works. This is how it's done in DBeaver, so i tried to simulate that. What's exactly wrong with refresh? What is not updating? |
Found it and fixed it. Should be good now. |
I can't open the database from the tree. After the last update I'm getting:
when I try to connect to the database. A normal dadbod DB command works fine with the same URL. My URL is in the form: sqlserver://user:password@host/db |
I pushed a fix, but i'm confused how it happens.
Do you have some results where table_schema or table_name is empty? |
I did few changes, hopefully there won't be any more issues. Let me know if you have any. |
It logs on now and populates the schemas but the schemas are not populated with tables. The above query correctly returns the schemas and tables with no missing entries. |
Ok. I've figured out what it is. With sqlcmd you can specify an ini file by exporting en env var SQLCMDINI=. (The ini file is quite handy as you cannot specify any additional parameters to sqlcmd in dadbod). In the file I had changed the separator to be a vertical line and I had specified mine as a unicode vertical line character. When I replaced it with a normal bar character it worked fine. So disregard the last message. It all works well now. Many thanks. |
The refresh also all works fine too now. Thanks. |
In latest commit I introduced using custom separator (pipe) for easier parsing, so maybe now it should work for you even with custom ini file. Not sure which one has precedence, sqlcmd argument or the ini file. |
The ini file appears to have precedence and I have set it to the pipe character too.
But now that messes with your foreign query jump functionality because you are expecting a space delimiter on the column name in dbout s:get_cell_range. Any suggestions? I could remove the separator in the ini file but I rather like it. Could you rely on naming conventions instead of a delimiter? |
I changed the way i'm getting the range. As long as delimiter is not set to |
Nice. That works great. |
Fixed SQL Server table helpers for foreign keys and references.