Skip to content

Commit

Permalink
Version 1.10
Browse files Browse the repository at this point in the history
This new version includes the command Yprint to create DDL files
for most of the objects in the database.
  • Loading branch information
Robert Kaltenthaler authored and vim-scripts committed Jan 29, 2014
1 parent 5def625 commit bc0c395
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 21 deletions.
23 changes: 23 additions & 0 deletions doc/orawb.txt
Expand Up @@ -154,6 +154,12 @@ Key mapping: Yw


Open a new SQL worksheet. Open a new SQL worksheet.


:Yp[rint] *Yprint*

Key mapping: Yp

The command prints the DDL for the selected object in the tree.

=============================================================================== ===============================================================================
5. The Object Tree *tree* 5. The Object Tree *tree*


Expand Down Expand Up @@ -223,6 +229,23 @@ The following commands can be used in the tree:


Yu[pdate] update the content of the tree Yu[pdate] update the content of the tree


:Yi[nvalid] list all invalid objects

:Yp[rint] print the DDL for the selected object of the following type:
TABLE
INDEX
CONSTRAINT
TRIGGER
VIEW
SEQUENCE
FUNCTION
PROCEDURE
PACKAGE
PACKAGE BODY
SYNONYM
TYPE
TYPE BODY

=============================================================================== ===============================================================================
6. The SQL Worksheet *worksheet* 6. The SQL Worksheet *worksheet*


Expand Down
84 changes: 63 additions & 21 deletions plugin/orawb.vim
@@ -1,8 +1,8 @@
" Purpose: Workbench for Oracle Databases " Purpose: Workbench for Oracle Databases
" Version: 1.9 " Version: 1.10
" Author: rkaltenthaler@yahoooooo.com " Author: rkaltenthaler@yahoooooo.com
" Last Modified: $Date: 2013-04-09 10:10:38 +0200 (Tue, 09 Apr 2013) $ " Last Modified: $Date: 2013-12-24 02:53:14 +0100 (Tue, 24 Dec 2013) $
" Id : $Id: orawb.vim 325 2013-04-09 08:10:38Z nikita $ " Id : $Id: orawb.vim 486M 2013-12-24 01:53:14Z (local) $
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" "
" Description: " Description:
Expand Down Expand Up @@ -46,6 +46,7 @@ if exists("loaded_sqlrc")
delfunction WBKeyMappingGeneral delfunction WBKeyMappingGeneral
delfunction WBKeyMappingCompiler delfunction WBKeyMappingCompiler
delfunction WBSqlPlus delfunction WBSqlPlus
delfunction WBDdlForObject
delfunction CreateTmpBuffer delfunction CreateTmpBuffer
delfunction CheckModified delfunction CheckModified
delfunction CheckConnection delfunction CheckConnection
Expand Down Expand Up @@ -82,6 +83,7 @@ if exists("loaded_sqlrc")
delfunction ChangeConnection delfunction ChangeConnection
delfunction ChangeConnection2 delfunction ChangeConnection2
delfunction CreateSourceForSynonym delfunction CreateSourceForSynonym
delfunction DdlForNamedObject
" finish " finish
endif endif


Expand Down Expand Up @@ -350,7 +352,6 @@ function WBOpenObject()
let fktdir["TRIGGER"]=function("GetSourceForObject") let fktdir["TRIGGER"]=function("GetSourceForObject")
let fktdir["SCHEMA"]=function("WBChangeConnection2") let fktdir["SCHEMA"]=function("WBChangeConnection2")
let fktdir["SYNONYM"]=function("CreateSourceForSynonym") let fktdir["SYNONYM"]=function("CreateSourceForSynonym")
let fktdir["DATABASE LINK"]=function("DisplayDBLink")


" check if a function exits " check if a function exits
if has_key(fktdir,ObjInfo.type) if has_key(fktdir,ObjInfo.type)
Expand All @@ -371,12 +372,11 @@ function! WBLoad()
return return
endif endif


" remove current content " revmove current content
:1,$d :1,$d


" generate load-script and call SqlPlus to execute it " generate load-script and call SqlPlus to execute it
call WBLoadObjectType() call WBLoadObjectType()
" return


" inform the user: we are loading... " inform the user: we are loading...
echo "loading..." echo "loading..."
Expand Down Expand Up @@ -621,14 +621,16 @@ function WBShow(...)
call WBKeyMappingGeneral() call WBKeyMappingGeneral()


" show the statusline with USER@HOST " show the statusline with USER@HOST
execute "setlocal statusline=[Yd][Ym][Yo][Yu]" " execute "setlocal statusline=[Yd][Ym][Yo][Yu]"
execute "setlocal statusline=Y[d][i][m][o][p][u]"


" load commands for the tree-buffer " load commands for the tree-buffer
command!-buffer Ymake call WBCompileObject() command!-buffer Ymake call WBCompileObject()
command!-buffer Ydescribe call WBDescribeObject() command!-buffer Ydescribe call WBDescribeObject()
command!-buffer Yopen call WBOpenObject() command!-buffer Yopen call WBOpenObject()
command!-buffer Yinvalid call ListInvalidObjects() command!-buffer Yinvalid call ListInvalidObjects()
command!-buffer Yupdate call WBLoad() command!-buffer Yupdate call WBLoad()
command!-buffer Yprint call WBDdlForObject()


" load the short-cuts for the tree-buffer " load the short-cuts for the tree-buffer
nmap <buffer> Ys Y:call WBShow() <C-M> nmap <buffer> Ys Y:call WBShow() <C-M>
Expand All @@ -639,6 +641,7 @@ function WBShow(...)
nmap <buffer> Yu Y:call WBLoad() <C-M> nmap <buffer> Yu Y:call WBLoad() <C-M>
nmap <buffer> Ym Y:call WBCompileObject() <C-M> nmap <buffer> Ym Y:call WBCompileObject() <C-M>
nmap <buffer> Yi Y:call ListInvalidObjects() <C-M> nmap <buffer> Yi Y:call ListInvalidObjects() <C-M>
nmap <buffer> Yp Y:call WBDdlForObject() <C-M>
nmap <buffer> + zo nmap <buffer> + zo
nmap <buffer> - zc nmap <buffer> - zc
endif endif
Expand Down Expand Up @@ -748,7 +751,8 @@ function WBChangeConnection2(NewUser,ObjType)
call WBLoad() call WBLoad()


" show the statusline with USER@HOST " show the statusline with USER@HOST
call SetupStatusLine("[Yd][Ym][Yo][Yu]") " call SetupStatusLine("[Yd][Ym][Yo][Yu]")
call SetupStatusLine("Y[d][i][m][o][p][u]")
endif endif


endfunction endfunction
Expand Down Expand Up @@ -801,7 +805,7 @@ function! WBInitWorksheet()
setlocal ignorecase setlocal ignorecase


" show the statusline with USER@HOST " show the statusline with USER@HOST
call SetupStatusLine("[Yd][Ym]") call SetupStatusLine("Y[d][m]")




" add commands " add commands
Expand Down Expand Up @@ -906,7 +910,7 @@ function! WBLoadObjectType()
call append("$","SELECT concat(' ','------') from dual;") call append("$","SELECT concat(' ','------') from dual;")


" load all types " load all types
let objlist = [ "VIEW","SEQUENCE","QUEUE","FUNCTION","PROCEDURE","PACKAGE","PACKAGE BODY","SYNONYM","TYPE", "TYPE BODY","DATABASE LINK"] let objlist = [ "VIEW","SEQUENCE","QUEUE","FUNCTION","PROCEDURE","PACKAGE","PACKAGE BODY","SYNONYM","TYPE", "TYPE BODY"]
for item in objlist for item in objlist
call append("$","PROMPT [".item."]") call append("$","PROMPT [".item."]")
call append("$","SELECT concat(' ',concat(decode(STATUS,'VALID','','(!)'),OBJECT_NAME)) DDNAME") call append("$","SELECT concat(' ',concat(decode(STATUS,'VALID','','(!)'),OBJECT_NAME)) DDNAME")
Expand Down Expand Up @@ -1242,6 +1246,18 @@ function! SwitchToDesc()
return currentBuffer return currentBuffer
endfunction endfunction


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Generate DDL for the tree selection
"
" The function call DBMS_METADATA.get_ddl
"
function! WBDdlForObject ()
" Get information about the object
let ObjInfo=WBGetObjectInfoFromTree()
call DdlForNamedObject(ObjInfo.name,ObjInfo.type)
endfunction


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Describe the object under the cursor in the tree window " Describe the object under the cursor in the tree window
" "
Expand Down Expand Up @@ -1292,6 +1308,43 @@ function! DescribeObject()
call DescribeNamedObject(l:object,"") call DescribeNamedObject(l:object,"")
endfunction endfunction


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Generate DDL for the given object
"
" Parameter: [in] Object Name
" [in] Object Type
"
" The function calls DBMS_METADATA.get_ddl
"
function! DdlForNamedObject(ObjectName,ObjectType)
if CheckConnection () != 0
return
endif

" remember the number of the current activ buffer
let currentBuffer=SwitchToDesc()


" create the SQL statements for describe and execute
call append(0,"set heading off pages 9999 lines 100 trimspool on longchunksize 100")
call append(1,"set long 200000")
call append(2,"set VERIFY OFF")
call append(3,"set FEEDBACK OFF")
call append(4,"execute DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.session_transform,'SEGMENT_ATTRIBUTES',false);")
call append(5,"execute DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.session_transform,'SQLTERMINATOR',true);")
call append(6,"execute DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.session_transform,'FORCE',false);")
call append(7,"select DBMS_METADATA.GET_DDL('".a:ObjectType."','".a:ObjectName."') from dual;")

1,$call SqlPlus()

"delete the SQL> prompts
" normal dW+df
setlocal ts=8 nomodified

" go back to original window
execute bufwinnr(currentBuffer) . 'wincmd w'
endfunction

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Describe the given object " Describe the given object
" "
Expand Down Expand Up @@ -1799,17 +1852,6 @@ function! DisplayIndex(ObjectName,ObjectType)
setlocal nomodified setlocal nomodified
endfunction endfunction
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Display a Database Link
"
" Do the following:
" - call DisplaySingleRecord to display the line
" describing the queue with the name ObjectName from
" the view USER_DB_LINKS
"
function! DisplayDBLink(ObjectName,ObjectType)
call DisplaySingleRecord("Database Link " . a:ObjectName,"USER_DB_LINKS","DB_LINK='".a:ObjectName . "'")
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Display a Sequence " Display a Sequence
" "
" Do the following: " Do the following:
Expand Down

0 comments on commit bc0c395

Please sign in to comment.