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
Zero Tables Shown when Connected to Oracle using TNS Alias #67
Comments
Looks like vim-dadbod doesn't have an implementation to fetch the tables for oracle. |
This is the Oracle equivalent of MySQL's -- show tables owned by the current user:
select table_name
from user_tables;
-- show all tables viewable by the current user (including system tables):
select table_name
from all_tables;
-- get all non-system tables:
select t.table_name
from all_tables t, all_users u
where t.owner = u.username
and u.common = 'NO';
I'm not sure which of those three fits our needs here the best, but both of those will generate table names from the Oracle database (tested on Oracle database 19c). Edit: To run a command and exit with echo 'select table_name from user_tables;' | sqlplus -L user_name/pass_word@service_name I'll get to work on drafting a working prototype. |
I've had some success with the following function: function! g:TestTables(url)
let l:names = split(system("echo 'set markup csv on;\nselect table_name from user_tables;' | " . db#adapter#oracle#interactive(a:url)), '\n')[12:-6]
for l:i in range(len(l:names))
let l:names[l:i] = l:names[l:i][1:-2]
endfor
return l:names
endfunction Here's what it does:
Edit: I just noticed |
I added the function to my dadbod fork https://github.com/kristijanhusak/vim-dadbod. I'd appreciate it if you would replace tpope's dadbod with my fork and give it a try. I tried setting up oracle myself on linux, but I'm having some issues, thus I can't test it. |
I tested the fork, and it looks like we're getting really close! All the tables are shown. Unfortunately, so is the table header ("TABLE_NAME"). There must be some extra step done for let l:names = split(system("echo 'set markup csv on;\nselect table_name from user_tables;' | " . db#adapter#oracle#interactive(a:url)), '\n')[12:-6] …to: let l:names = split(system("echo 'set markup csv on;\nselect table_name from user_tables;' | " . db#adapter#oracle#interactive(a:url)), '\n')[13:-6] …or re-implementing that special behavior for Finally, I see that tables now have completion available. However, each attribute of the table does not. I see that the Does this assist in the completion process? If so, I would be willing to write the queries to provide this information for Oracle if you can give me more information about how Thank you for all the help so far! I really appreciate it. You knew exactly where to look and how to solve the problem. |
Thanks. We can just remove the first row to remove the List item. This is where it's done for mysql https://github.com/kristijanhusak/vim-dadbod-ui/blob/master/autoload/db_ui/schemas.vim#L83. PostgreSQL, MySQL and MSSQL are better supported by vim-dadbod-ui/vim-dadbod-completion. Oracle falls back to dadbod's table function, like everything else that is not in the previously mentioned list. https://github.com/kristijanhusak/vim-dadbod-ui/blob/master/autoload/db_ui/schemas.vim Note that I'm not able to test this at the moment, but I hope I'll be able to set up oracle at some point. |
Wow, this is quite helpful! Thank you. I've gotten started with this plugin over here and quite a few things are working already. I'll file a PR draft here when it's closer. After that I'll get started on the As for this issue, I am inclined to close it since we're moving out of the initial problem I was having and into a bigger problem scope. I can file further issues later if need-be— thoughts? Before we close it though— there is one problem I am having: I got table helpers and schema settings configured, so now it can detect the schemas of the database: However, each schema shows as having zero tables. Which query is used to determine what tables each schema has?
Edit: Solved by formatting query results. Oracle is a real stickler about this one 🙄 |
We can leave it until your PR is closed. If you do full integration for oracle like it's done for psql, mysql and mssql, you will not have to use my fork to get the tables. It will be part of dadbod ui. Does oracle support schemas like postgres? |
Oracle does support schemas— although they're sort of blended together with users. Whereas Postres and MySQL allow for multiple databases which have multiple levels of access to them according to user groups, Oracle defines them together under one umbrella.
|
Ok, you can still print them out in a similar way like it's done for others, so should be pretty straightforward. Let me know if you need explanation around something. |
I'm happy to report that everything is working for the Here's what I've determined:
I've attached a sample
|
Great! What did you set for |
I set them to these values:
You can change the column delimiter from a space to anything if you use the After doing a little more digging, it looks like the |
Is the sample output you attached the default one, without any custom configuration? It looks like it has two tabs between columns, and for the cell line delimiter (2nd line), it is delimited only by a space. This inconsistency is causing the issue, because code tries to find the column name and value by the cell width, which is in this case bigger than any cell value. If we would have 1 space between columns like it is done for cell line delimiter, that would solve the issue. |
I've adjusted the query and result. Here is what I use for the query: -- Max length of a line.
SET linesize 4000;
-- Number of entries before next column header.
SET pagesize 4000;
-- Unfortunately, Oracle requires manually formatting columns.
-- You can use `set trim on` but that truncates the column name.
COLUMN TmCode FORMAT a6;
COLUMN TmLocCode FORMAT a9;
COLUMN TmName FORMAT a12;
COLUMN TmRegCode FORMAT a9;
COLUMN TmStatus FORMAT a8;
SELECT * FROM NF_Team_BR; The result is attached here. Based on this result, I've changed the When I use set colorcolumn=17,28 |
Let's not do any formatting. What's the dbout output when you just do the select query, without all the other settings? |
Here's the result without formatting. WIthout the Edit: Here's the query for reference. SELECT * FROM NF_Team_BR; And the columns selected when jumping from 'JPnw': set colorcolumn=10,39 Seems like it always grabs |
Wow, that's really messed up. You do this formatting every time for every query? Do you maybe have some test database that is publicly accessible which i can use for test? I managed to install the client (sqlplus), but not the server. |
I'll work on getting a public environment set up, and I'll initiate the PR. A potential workaround would be to use |
After the testing the completion pull this week, I haven't come across any more bugs since its last commit. Should we merge that one while continuing with the UI? |
I left you a review there. You just need to tweak one thing and it should be good to go. |
Closed by #68 |
Can we use this version to query table in Oracle. In production we often have table owned by a Team but queryable by the other. Say:
The current schema made the assumption that I owned tables that I want to query, which unfortunately show 0 table. |
I don't have enough knowledge of Oracle to give a strong opinion on this. If it would give the same result as you would have with the full permissions on the db, I guess it's ok. |
I can raise an PR, is that ok? |
Of course :) |
Thank you for this plugin! I've been using it on MariaDB databases to much success. Recently I started using an Oracle database for work (see tpope/vim-dadbod#75), but I'm having a recurring issue with the UI.
I first configure
vim-dadbod-ui
to connect to my oracle database by providing a configuration which looks like this:service_name
is an alias defined in thetnsnames.ora
located at$TNS_ADMIN
.Next, I connect to the database with
:DBUI
. When it establishes the connection, I see this:However, when I run this query:
…I get this output:
None of the tables seem to be reported. It also looks like
coc-db
andvim-dadbod-completion
are affected, as completions do not work when connected to the Oracle database. Should I create separate tickets for those?The text was updated successfully, but these errors were encountered: