11" dbext.vim - Commn Database Utility
22" Copyright (C) 2002-7, Peter Bagyinszki, David Fishburn
33" ---------------------------------------------------------------
4- " Version: 6.20
4+ " Version: 7.00
55" Maintainer: David Fishburn <dfishburn dot vim at gmail dot com>
66" Authors: Peter Bagyinszki <petike1 at dpg dot hu>
77" David Fishburn <dfishburn dot vim at gmail dot com>
8- " Last Modified: 2008 Aug 09
8+ " Last Modified: 2008 Sep 16
99" Based On: sqlplus.vim (author: Jamis Buck)
1010" Created: 2002-05-24
1111" Homepage: http://vim.sourceforge.net/script.php?script_id=356
@@ -37,7 +37,7 @@ if v:version < 700
3737 echomsg " dbext: Version 4.00 or higher requires Vim7. Version 3.50 can stil be used with Vim6."
3838 finish
3939endif
40- let g: loaded_dbext_auto = 620
40+ let g: loaded_dbext_auto = 700
4141
4242" call confirm("Loaded dbext autoload", "&Ok")
4343" Script variable defaults, these are used internal and are never displayed
@@ -3468,7 +3468,7 @@ function! s:DB_DBI_getListColumn(table_name)
34683468
34693469 perl db_results_variable ()
34703470
3471- let col_names = matchstr (g: dbext_dbi_result ,' DBI:\zsTABLE_CAT.\{-}\ze\n' )
3471+ let col_names = matchstr (g: dbext_dbi_result ,' DBI:.\{-} \zsTABLE_CAT.\{-}\ze\n' )
34723472 let col_values = matchstr (g: dbext_dbi_result ,' \n-[ -]*\zs\n.*' )
34733473 " Strip off query statistics
34743474 let col_values = substitute ( col_values, ' (\d\+ rows\_.*' , ' ' , ' ' )
@@ -3646,7 +3646,7 @@ function! s:DB_DBI_getDictionaryTable() "{{{
36463646 return -1
36473647 endif
36483648
3649- let col_names = matchstr (g: dbext_dbi_result ,' DBI:\zsTABLE_CAT.\{-}\ze\n' )
3649+ let col_names = matchstr (g: dbext_dbi_result ,' DBI:.\{-} \zsTABLE_CAT.\{-}\ze\n' )
36503650 let col_values = matchstr (g: dbext_dbi_result ,' \n-[ -]*\zs\n.*' )
36513651 " Strip off query statistics
36523652 let col_values = substitute ( col_values, ' (\d\+ rows\_.*' , ' ' , ' ' )
@@ -3782,7 +3782,7 @@ function! s:DB_DBI_getDictionaryView() "{{{
37823782 " Populate the results variable
37833783 perl db_results_variable ()
37843784
3785- let col_names = matchstr (g: dbext_dbi_result ,' DBI:\zsTABLE_CAT.\{-}\ze\n' )
3785+ let col_names = matchstr (g: dbext_dbi_result ,' DBI:.\{-} \zsTABLE_CAT.\{-}\ze\n' )
37863786 let col_values = matchstr (g: dbext_dbi_result ,' \n-[ -]*\zs\n.*' )
37873787 " Strip off query statistics
37883788 let col_values = substitute ( col_values, ' (\d\+ rows\_.*' , ' ' , ' ' )
@@ -4035,7 +4035,7 @@ function! s:DB_ODBC_getListColumn(table_name)
40354035
40364036 perl db_results_variable ()
40374037
4038- let col_names = matchstr (g: dbext_dbi_result ,' DBI:\zsTABLE_CAT.\{-}\ze\n' )
4038+ let col_names = matchstr (g: dbext_dbi_result ,' DBI:.\{-} \zsTABLE_CAT.\{-}\ze\n' )
40394039 let col_values = matchstr (g: dbext_dbi_result ,' \n-[ -]*\zs\n.*' )
40404040 " Strip off query statistics
40414041 let col_values = substitute ( col_values, ' (\d\+ rows\_.*' , ' ' , ' ' )
@@ -4222,7 +4222,7 @@ function! s:DB_ODBC_getDictionaryTable() "{{{
42224222
42234223 perl db_results_variable ()
42244224
4225- let col_names = matchstr (g: dbext_dbi_result ,' DBI:\zsTABLE_CAT.\{-}\ze\n' )
4225+ let col_names = matchstr (g: dbext_dbi_result ,' DBI:.\{-} \zsTABLE_CAT.\{-}\ze\n' )
42264226 let col_values = matchstr (g: dbext_dbi_result ,' \n-[ -]*\zs\n.*' )
42274227 " Strip off query statistics
42284228 let col_values = substitute ( col_values, ' (\d\+ rows\_.*' , ' ' , ' ' )
@@ -4375,7 +4375,7 @@ function! s:DB_ODBC_getDictionaryView() "{{{
43754375
43764376 perl db_results_variable ()
43774377
4378- let col_names = matchstr (g: dbext_dbi_result ,' DBI:\zsTABLE_CAT.\{-}\ze\n' )
4378+ let col_names = matchstr (g: dbext_dbi_result ,' DBI:.\{-} \zsTABLE_CAT.\{-}\ze\n' )
43794379 let col_values = matchstr (g: dbext_dbi_result ,' \n-[ -]*\zs\n.*' )
43804380 " Strip off query statistics
43814381 let col_values = substitute ( col_values, ' (\d\+ rows\_.*' , ' ' , ' ' )
@@ -4486,6 +4486,11 @@ function! dbext#DB_execSql(query)
44864486
44874487 if query != " "
44884488 return dbext#DB_execFuncTypeWCheck (' execSql' , query)
4489+ else
4490+ " If the query was cancelled, close the history
4491+ " window which was opened when we added the
4492+ " query above.
4493+ call dbext#DB_windowClose (s: DB_resBufName ())
44894494 endif
44904495endfunction
44914496
@@ -6894,10 +6899,13 @@ function! dbext#DB_connect()
68946899 endif
68956900 let cmd = " perl db_connect('" .driver." ', '" .conn_parms." ', '" .user ." ', '" .passwd." ')"
68966901 exec cmd
6897- if g: dbext_dbi_result == -1
6902+ if g: dbext_dbi_result == -1
68986903 call s: DB_runCmd (" perl " .driver, cmd, g: dbext_dbi_msg )
68996904 return -1
69006905 endif
6906+ if g: dbext_dbi_msg != ' '
6907+ call s: DB_runCmd (" perl " .driver, cmd, g: dbext_dbi_msg )
6908+ endif
69016909
69026910 let parmlist = split (driver_parms, ' ;' )
69036911
@@ -6924,119 +6932,6 @@ function! dbext#DB_connect()
69246932 return 0
69256933endfunction
69266934
6927- function ! dbext#DB_connectOld ()
6928- " Only valid for DBI and ODBC (perl)
6929- let type = s: DB_get (' type' )
6930- if (type !~ ' \<DBI\>\|\<ODBC\>' )
6931- call s: DB_warningMsg (
6932- \ " dbext:Connect and Disconnect functionality only available " .
6933- \ " when using the DBI or ODBC interfaces"
6934- \ )
6935- return -1
6936- endif
6937-
6938- if (type = ~ ' \<ODBC\>' )
6939- let driver = ' ODBC'
6940- let conn_parms = s: DB_get (" dsnname" )
6941- else
6942- let driver = s: DB_get (' driver' )
6943- let conn_parms = s: DB_get (" conn_parms" )
6944- endif
6945- " Ensure the dbext_dbi plugin is loaded
6946- if s: DB_DBI_Autoload () == -1
6947- return -1
6948- endif
6949-
6950- let cmd = " perl db_is_connected()"
6951- exec cmd
6952- if g: dbext_dbi_result == -1
6953- call s: DB_runCmd (" perl " .driver, cmd, g: dbext_dbi_msg )
6954- return -1
6955- endif
6956-
6957- " Each time we issue a connect, set the max rows, this
6958- " will ensure it is updated each time the user
6959- " interacts with this layer.
6960- let g: dbext_dbi_max_rows = s: DB_get (' DBI_max_rows' )
6961-
6962- if g: dbext_dbi_result == 1
6963- " call s:DB_warningMsg("DB_Connected: already connected")
6964- return 0
6965- endif
6966-
6967- let user = s: DB_get (" user" )
6968- let passwd = s: DB_get (" passwd" )
6969- let driver_parms = s: DB_get (" driver_parms" )
6970- if (type = ~ ' \<ODBC\>' )
6971- let driver = ' ODBC'
6972- let conn_parms = s: DB_get (" dsnname" )
6973- else
6974- let driver = s: DB_get (' driver' )
6975- let conn_parms = s: DB_get (" conn_parms" )
6976- endif
6977- let cmd = " perl db_connect('" .driver." ', '" .conn_parms." ', '" .user ." ', '" .passwd." ')"
6978- exec cmd
6979- if g: dbext_dbi_result == -1
6980- call s: DB_runCmd (" perl " .driver, cmd, g: dbext_dbi_msg )
6981- return -1
6982- endif
6983-
6984- " The driver parameters can be user defined.
6985- " They must be semi-colon separated in this format:
6986- " AutoCommit=1;PrintError=0
6987- let str = driver_parms
6988- let exp_find_str = ' ;'
6989- if str != " "
6990- " Find the string index position of the first match
6991- let index = match (str, exp_find_str)
6992- while index > -1
6993- " First loop through pulling each item prior to
6994- " a semi-colon off and then set the option.
6995- " (var, value) = substitute ('Autocommit=1;p=2', '^\(\w\+\)\s*=\s*\(\w\+\).*', '\1\2', '')
6996- " Retrieve the name of what we found
6997- let var = matchstr (str, ' ^\w\+\ze\s*=.*\%' .(index + 1 ).' c' )
6998- let value = matchstr (str, ' ^\w\+\s*=\s*\zs.*\%' .(index + 1 ).' c' )
6999-
7000- if var == " "
7001- call s: DB_warningMsg (" Invalid driver parameters, format expected is:AutoCommit=1;PrintWarn=0" )
7002- return -1
7003- endif
7004-
7005- let cmd = " perl db_set_connection_option('" .var ." ', '" .value." ')"
7006- exec cmd
7007- if g: dbext_dbi_result == -1
7008- call s: DB_runCmd (" perl " .driver, cmd, g: dbext_dbi_msg )
7009- return -1
7010- endif
7011-
7012- let str = strpart (str, index + 1 )
7013- let index = match (str, exp_find_str)
7014- endwhile
7015-
7016- " Next deal with the remainder of the string that does not
7017- " end in a semi-colon.
7018- if str != " "
7019- " Retrieve the name of what we found
7020- let var = matchstr (str, ' ^\w\+\ze\s*=' )
7021- let value = matchstr (str, ' ^\w\+\s*=\s*\zs.*' )
7022-
7023- if var == " "
7024- call s: DB_warningMsg (" Invalid driver parameters, format expected is:AutoCommit=1;PrintWarn=0" )
7025- return -1
7026- endif
7027-
7028- let cmd = " perl db_set_connection_option('" .var ." ', '" .value." ')"
7029- exec cmd
7030- if g: dbext_dbi_result == -1
7031- call s: DB_runCmd (" perl " .driver, cmd, g: dbext_dbi_msg )
7032- return -1
7033- endif
7034- endif
7035- endif
7036-
7037- return 0
7038- endfunction
7039-
70406935function ! dbext#DB_disconnect ()
70416936 " Only valid for DBI and ODBC (perl)
70426937 let driver = s: DB_get (' type' )
@@ -7070,10 +6965,6 @@ function! dbext#DB_disconnect()
70706965 endif
70716966
70726967 perl db_disconnect ()
7073- if g: dbext_dbi_result == -1
7074- call s: DB_runCmd (" perl " .driver, " DISCONNECT" , g: dbext_dbi_msg )
7075- return -1
7076- endif
70776968
70786969 return 0
70796970endfunction
0 commit comments