From 3c4f30be412c92137480f68c250132242c70bf8a Mon Sep 17 00:00:00 2001 From: Stefan Litsche Date: Fri, 2 Oct 2015 10:31:59 +0200 Subject: [PATCH 1/3] Change the table description and table complete because the object resolution in Postgres relies on schema in search_path. --- autoload/dbext.vim | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/autoload/dbext.vim b/autoload/dbext.vim index 3e3315c..dfa1d18 100644 --- a/autoload/dbext.vim +++ b/autoload/dbext.vim @@ -3556,10 +3556,10 @@ endfunction function! s:DB_PGSQL_getListTable(table_prefix) let owner = s:DB_getObjectOwner(a:table_prefix) let table_name = s:DB_getObjectName(a:table_prefix) - let query = "select tablename, tableowner " . + let query = "select tablename, schemaname " . \ " from pg_tables " . - \ "where tableowner != 'pg_catalog' " . - \ " and tableowner like '" . owner . "%' " . + \ "where schemaname != 'pg_catalog' " . + \ " and schemaname like '" . owner . "%' " . \ " and tablename like '" . table_name . "%' " . \ "order by tablename" return s:DB_PGSQL_execSql(query) @@ -3622,10 +3622,10 @@ endfunction function! s:DB_PGSQL_getDictionaryTable() let result = s:DB_PGSQL_execSql( - \ "select ".(s:DB_get('dict_show_owner')==1?"tableowner||'.'||":'')."tablename " . + \ "select ".(s:DB_get('dict_show_owner')==1?"schemaname||'.'||":'')."tablename " . \ " from pg_tables " . - \ "where tableowner != 'pg_catalog' " . - \ "order by ".(s:DB_get('dict_show_owner')==1?"tableowner, ":'')."tablename" + \ "where schemaname != 'pg_catalog' " . + \ "order by ".(s:DB_get('dict_show_owner')==1?"schemaname, ":'')."tablename" \ ) return s:DB_PGSQL_stripHeaderFooter(result) endfunction From a86548e455bfad7cd5291bf84740498db1b16d41 Mon Sep 17 00:00:00 2001 From: Stefan Litsche Date: Thu, 5 Nov 2015 22:04:29 +0100 Subject: [PATCH 2/3] Fix duplicate helptag. As it is done in pull request 3 already --- doc/dbext.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/dbext.txt b/doc/dbext.txt index 367faff..91c0bee 100644 --- a/doc/dbext.txt +++ b/doc/dbext.txt @@ -3745,13 +3745,13 @@ To specify the type of database you connect to most often, you can place the dbext's current variable_def_regex for this buffer. This |autocmd| can be added to your |.vimrc|: > autocmd BufRead */MyProjectDir/* DBSetOption variable_def_regex=\<\(p_\|lv_\)\w\+\> - autocmd BufRead */MyProjectDir/* if exists('g:loaded_dbext') | exec 'DBSetOption variable_def_regex=\<\(p_\|lv_\)\w\+\>' | endif + autocmd BufRead /MyProjectDir/ if exists('g:loaded_dbext') | exec 'DBSetOption variable_def_regex=\<\(p_\|lv_\)\w\+\>' | endif < Or if you simply wanted to extended the existing defaults, you can retrieve the existing setting using dbext's DB_listOption function and concatenate the new regex separated by a comma: > autocmd BufRead */MyProjectDir2/* DBSetOption variable_def_regex=,\<\(p_\|lv_\)\w\+\> - autocmd BufRead */MyProjectDir2/* if exists('g:loaded_dbext') | exec 'DBSetOption variable_def_regex=,\<\(p_\|lv_\)\w\+\>' | endif + autocmd BufRead /MyProjectDir2/ if exists('g:loaded_dbext') | exec 'DBSetOption variable_def_regex=,\<\(p_\|lv_\)\w\+\>' | endif < Prompt screens and options. From 8110a61119d7ed9560b004a0f7530e26daab9bad Mon Sep 17 00:00:00 2001 From: Stefan Litsche Date: Tue, 9 Feb 2016 11:07:58 +0100 Subject: [PATCH 3/3] Fix problem with 'operator does not exist: oidvector = oid' for DBDescribeProcedure. Also adjusted DBListColumn to use schema name instead of owner. --- autoload/dbext.vim | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/autoload/dbext.vim b/autoload/dbext.vim index dfa1d18..a6ce628 100644 --- a/autoload/dbext.vim +++ b/autoload/dbext.vim @@ -3530,26 +3530,28 @@ function! s:DB_PGSQL_describeTable(table_name) endfunction function! s:DB_PGSQL_describeProcedure(procedure_name) - let owner = s:DB_getObjectOwner(a:procedure_name) + let schema = s:DB_getObjectOwner(a:procedure_name) let proc_name = s:DB_getObjectName(a:procedure_name) - let query = "SELECT p.* ". - \ " FROM pg_proc p, pg_type t, pg_language l " . - \ " WHERE p.proargtypes = t.oid " . - \ " AND p.prolang = t.oid " . - \ " AND p.proname = '" . proc_name . "'" - " let query = "SELECT t.typname, t.typdefault, t.typinput " . - " \ " , t.typoutput, l.lanname " . - " \ " FROM pg_proc p, pg_type t, pg_language l " . - " \ " WHERE p.proargtypes = t.oid " . - " \ " AND p.prolang = t.oid " . - " \ " AND p.proname = '" . proc_name . "'" - - if strlen(owner) > 0 + let query = "SELECT n.nspname as \"Schema\", " . + \ " p.proname as \"Name\", " . + \ " pg_catalog.pg_get_function_result(p.oid) as \"Result data type\", " . + \ " pg_catalog.pg_get_function_arguments(p.oid) as \"Argument data types\", " . + \ " CASE " . + \ " WHEN p.proisagg THEN 'agg' " . + \ " WHEN p.proiswindow THEN 'window' " . + \ " WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN 'trigger' " . + \ " ELSE 'normal' " . + \ " END as \"Type\" " . + \ " FROM pg_catalog.pg_proc p " . + \ " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace " . + \ " WHERE p.proname ~ '^(" . proc_name . ".*)$' " + + if strlen(schema) > 0 let query = query . - \ " AND pg_get_userbyid(p.proowner) = '".owner."' " + \ " AND n.nspname ~ '^(" . schema .")$' " endif let query = query . - \ " ORDER BY p.pronargs; " + \ "ORDER BY 1, 2, 4;" return s:DB_PGSQL_execSql( query ) endfunction @@ -3592,15 +3594,16 @@ endfunction function! s:DB_PGSQL_getListColumn(table_name) let owner = s:DB_getObjectOwner(a:table_name) let table_name = s:DB_getObjectName(a:table_name) - let query = "SELECT a.attname " . - \ " FROM pg_class c, pg_attribute a " . - \ " WHERE c.oid = a.attrelid " . - \ " AND a.attnum > 0 " . + let query = "SELECT a.attname " . + \ " FROM pg_class c" . + \ " JOIN pg_attribute a ON c.oid = a.attrelid " . + \ " JOIN pg_namespace n ON c.relnamespace = n.oid " . + \ " WHERE a.attnum > 0" . \ " AND c.relname = '" . table_name . "'" if strlen(owner) > 0 let query = query . - \ " AND pg_get_userbyid(c.relowner) = '".owner."' " + \ " AND n.nspname = '".owner."' " endif let query = query . \ " ORDER BY a.attnum; "