Skip to content

Commit 35f4572

Browse files
committed
Added PGSQL getListType function
1 parent 14f3d53 commit 35f4572

File tree

2 files changed

+51
-20
lines changed

2 files changed

+51
-20
lines changed

autoload/dbext.vim

+32-2
Original file line numberDiff line numberDiff line change
@@ -1996,9 +1996,9 @@ function! s:DB_ASA_stripHeaderFooter(result)
19961996
" table_name table_id
19971997
" ---------------------------
19981998
" ZTSAAP_C_OPKEY 867
1999-
"
1999+
"
20002000
" (1 rows)
2001-
"
2001+
"
20022002
" Execution time: 0.025 seconds
20032003

20042004
" Strip off column headers ending with a newline
@@ -3782,6 +3782,19 @@ function! s:DB_PGSQL_getListProcedure(proc_prefix)
37823782
return s:DB_PGSQL_execSql(query)
37833783
endfunction
37843784

3785+
function! s:DB_PGSQL_getListType(type_prefix)
3786+
let owner = s:DB_getObjectOwner(a:type_prefix)
3787+
let object = s:DB_getObjectName(a:type_prefix)
3788+
let query = " SELECT t.typname AS type, e.enumlabel AS value, pg_get_userbyid(u.usesysid) AS owner " .
3789+
\ " FROM pg_user u, pg_type t JOIN pg_enum e ON e.enumtypid = t.oid " .
3790+
\ " WHERE t.typowner = u.usesysid " .
3791+
\ " AND u.usename like '" . owner . "%' " .
3792+
\ " AND p.proname like '" . object . "%' " .
3793+
\ " ORDER BY t.typname"
3794+
3795+
return s:DB_PGSQL_execSql(query)
3796+
endfunction
3797+
37853798
function! s:DB_PGSQL_getListView(view_prefix)
37863799
let owner = s:DB_getObjectOwner(a:view_prefix)
37873800
let view_name = s:DB_getObjectName(a:view_prefix)
@@ -6295,6 +6308,23 @@ function! dbext#DB_getListProcedure(...)
62956308
return dbext#DB_execFuncTypeWCheck('getListProcedure', proc_prefix)
62966309
endfunction
62976310

6311+
function! dbext#DB_getListType(...)
6312+
if(a:0 > 0)
6313+
" Strip any leading or trailing spaces
6314+
let type_prefix = substitute(a:1,'\s*\(\w*\)\s*','\1','')
6315+
else
6316+
let type_prefix = s:DB_getInput(
6317+
\ "Enter type prefix: ",
6318+
\ '',
6319+
\ "dbext_cancel"
6320+
\ )
6321+
if type_prefix == "dbext_cancel"
6322+
return ""
6323+
endif
6324+
endif
6325+
return dbext#DB_execFuncTypeWCheck('getListType', type_prefix)
6326+
endfunction
6327+
62986328
function! dbext#DB_getListView(...)
62996329
if(a:0 > 0)
63006330
" Strip any leading or trailing spaces

doc/dbext.txt

+19-18
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,14 @@ Version 23.00 (Dec 30, 2015)
125125
- CRATE native database type and Crate via DBI are supported
126126
- Updated the DBI SQLAnywhere procedure list to respect the option of whether
127127
to include the object owner names
128-
- Added a new public function, DB_DictionaryDelete, to be used by the
128+
- Added a new public function, DB_DictionaryDelete, to be used by the
129129
OMNI SQL Completion plugin (autoload/sqlcomplete.vim, which is part of Vim)
130130

131131
Bug Fixes
132132
---------
133-
- helptags reported duplicate tag MyProjectDir, updated documentation as a
133+
- helptags reported duplicate tag MyProjectDir, updated documentation as a
134134
work around as there is no way to escape the real syntax (pull #3) (mexpolk)
135-
- For PGSQL, use the "schemaname" column rather than "tableowner" (pull #15)
135+
- For PGSQL, use the "schemaname" column rather than "tableowner" (pull #15)
136136
(Stefan Litsche)
137137

138138

@@ -162,12 +162,12 @@ Version 22.00 (August 2, 2015)
162162
setting. This can also be set / overridden using DBSetOption strip_into=1
163163
or as part of a dbext profile.
164164
- Added new option, "strip_at_variables", which is executing statements which
165-
have variable assignments in the SELECT list instead of the INTO clause.
165+
have variable assignments in the SELECT list instead of the INTO clause.
166166
To test these queries, you need to remove the assignments when they execute
167167
to see the result set returned. This was on for all databases, but for
168168
TransactSQL or TSQL databases like SQLSRV and ASE, stripping the variable
169-
assignments in the SELECT list is required. This can be controlled via this
170-
setting. This can also be set / overridden using
169+
assignments in the SELECT list is required. This can be controlled via this
170+
setting. This can also be set / overridden using
171171
DBSetOption strip_at_variables=1 or as part of a dbext profile.
172172

173173
Bug Fixes
@@ -1197,7 +1197,7 @@ Version 2.00 (Jul 11, 2004)
11971197
let dbext_default_query_statements = 'select,update';
11981198
dbext_default_passwd_use_secret
11991199
< - When entering a password, if the value should be masked. When using
1200-
a GUI version of Vim, the prompt is not displayed in a dialog unlike
1200+
a GUI version of Vim, the prompt is not displayed in a dialog unlike
12011201
the other parameters. This option is OFF (0) by default. >
12021202
dbext_default_parse_statements
12031203
< - Which statements are parsed for input parameters (See |dbext-newdb|) >
@@ -1337,7 +1337,7 @@ Version 2.00 (Jul 11, 2004)
13371337
the statement to a String.
13381338
>
13391339
dbext_default_strip_at_variables
1340-
< - A buffer local variable which is used when executing SELECT
1340+
< - A buffer local variable which is used when executing SELECT
13411341
statements. This setting is OFF by default and ON for SQLSRV and
13421342
ASE databases. Most databases support the INTO clause which is used
13431343
to store column values into locally declared
@@ -1350,19 +1350,19 @@ Version 2.00 (Jul 11, 2004)
13501350
BEGIN
13511351
DECLARE @fname VARCHAR(30);
13521352
DECLARE @lname VARCHAR(30);
1353-
1353+
13541354
-- TransactSQL syntax
13551355
SELECT @fname = FirstName, @lname = Surname
13561356
FROM Customer
13571357
WHERE ID = @p1
13581358
END;
13591359
<
13601360
- If you visually selected the SELECT statement in this procedure
1361-
to test it, you will get a syntax error indicating "@fname" is
1361+
to test it, you will get a syntax error indicating "@fname" is
13621362
not defined. When the procedure executes, the variable is defined
13631363
and will execute correctly.
13641364
- The "strip_at_variables" is enabled for all SQLSRV and ASE databases
1365-
which use TransactSQL syntax. When strip_at_variables = 1,
1365+
which use TransactSQL syntax. When strip_at_variables = 1,
13661366
and visually selecting the statement and executing, the variable
13671367
assignments are stripped so that the developer can see the result set
13681368
returned by the query (instead of a syntax error): >
@@ -1379,7 +1379,7 @@ Version 2.00 (Jul 11, 2004)
13791379
let g:dbext_default_profile_SQLSRV = 'type=SQLSRV:user=sa:passwd=Leader:strip_at_variables=0'
13801380
>
13811381
dbext_default_strip_into
1382-
< - A buffer local variable which is used when executing SELECT
1382+
< - A buffer local variable which is used when executing SELECT
13831383
statements. This setting is ON by default and OFF for SQLSRV and
13841384
ASE databases. Most databases support the INTO
13851385
clause which is used to store column values into locally declared
@@ -1388,32 +1388,32 @@ Version 2.00 (Jul 11, 2004)
13881388
BEGIN
13891389
DECLARE @fname VARCHAR(30);
13901390
DECLARE @lname VARCHAR(30);
1391-
1391+
13921392
SELECT FirstName, Surname
13931393
INTO @fname, @lname
13941394
FROM Customer
13951395
WHERE ID = @p1
13961396
END;
13971397
<
13981398
- If you visually selected the SELECT statement in this procedure
1399-
to test it, you will get a syntax error indicating "@fname" is
1399+
to test it, you will get a syntax error indicating "@fname" is
14001400
not defined. When the procedure executes, the variable is defined
14011401
and will execute correctly.
14021402
- The "strip_into" is enabled for all databases other than SQLSRV
1403-
and ASE which use TransactSQL syntax. When strip_into = 1,
1403+
and ASE which use TransactSQL syntax. When strip_into = 1,
14041404
and visually selecting the statement and executing, the INTO
14051405
clause is stripped so that the developer can see the result set
14061406
returned by the query (instead of a syntax error): >
14071407
SELECT FirstName, Surname
14081408
FROM Customer
14091409
WHERE ID = @p1
14101410
<
1411-
- For SQLSRV databases, the INTO clause is used to create a
1411+
- For SQLSRV databases, the INTO clause is used to create a
14121412
temporary table and return the results from it. So for this
14131413
database, we do not want to strip the INTO clause. Consider
14141414
this SQL statement: >
1415-
SELECT *
1416-
INTO dbo.Table_backup
1415+
SELECT *
1416+
INTO dbo.Table_backup
14171417
FROM dbo.Table;
14181418
<
14191419
- It may be necessary to toggle this setting on and off based
@@ -2438,6 +2438,7 @@ Version 2.00 (Jul 11, 2004)
24382438
DB_NEW_getDictionaryView
24392439
DB_NEW_getListColumn
24402440
DB_NEW_getListProcedure
2441+
DB_NEW_getListType
24412442
DB_NEW_getListTable
24422443
DB_NEW_getListView
24432444
DB_NEW_stripHeaderFooter

0 commit comments

Comments
 (0)