1
1
" dbext.vim - Commn Database Utility
2
2
" Copyright (C) 2002-7, Peter Bagyinszki, David Fishburn
3
3
" ---------------------------------------------------------------
4
- " Version: 6.20
4
+ " Version: 7.00
5
5
" Maintainer: David Fishburn <dfishburn dot vim at gmail dot com>
6
6
" Authors: Peter Bagyinszki <petike1 at dpg dot hu>
7
7
" David Fishburn <dfishburn dot vim at gmail dot com>
8
- " Last Modified: 2008 Aug 09
8
+ " Last Modified: 2008 Sep 16
9
9
" Based On: sqlplus.vim (author: Jamis Buck)
10
10
" Created: 2002-05-24
11
11
" Homepage: http://vim.sourceforge.net/script.php?script_id=356
@@ -37,7 +37,7 @@ if v:version < 700
37
37
echomsg " dbext: Version 4.00 or higher requires Vim7. Version 3.50 can stil be used with Vim6."
38
38
finish
39
39
endif
40
- let g: loaded_dbext_auto = 620
40
+ let g: loaded_dbext_auto = 700
41
41
42
42
" call confirm("Loaded dbext autoload", "&Ok")
43
43
" Script variable defaults, these are used internal and are never displayed
@@ -3468,7 +3468,7 @@ function! s:DB_DBI_getListColumn(table_name)
3468
3468
3469
3469
perl db_results_variable ()
3470
3470
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' )
3472
3472
let col_values = matchstr (g: dbext_dbi_result ,' \n-[ -]*\zs\n.*' )
3473
3473
" Strip off query statistics
3474
3474
let col_values = substitute ( col_values, ' (\d\+ rows\_.*' , ' ' , ' ' )
@@ -3646,7 +3646,7 @@ function! s:DB_DBI_getDictionaryTable() "{{{
3646
3646
return -1
3647
3647
endif
3648
3648
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' )
3650
3650
let col_values = matchstr (g: dbext_dbi_result ,' \n-[ -]*\zs\n.*' )
3651
3651
" Strip off query statistics
3652
3652
let col_values = substitute ( col_values, ' (\d\+ rows\_.*' , ' ' , ' ' )
@@ -3782,7 +3782,7 @@ function! s:DB_DBI_getDictionaryView() "{{{
3782
3782
" Populate the results variable
3783
3783
perl db_results_variable ()
3784
3784
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' )
3786
3786
let col_values = matchstr (g: dbext_dbi_result ,' \n-[ -]*\zs\n.*' )
3787
3787
" Strip off query statistics
3788
3788
let col_values = substitute ( col_values, ' (\d\+ rows\_.*' , ' ' , ' ' )
@@ -4035,7 +4035,7 @@ function! s:DB_ODBC_getListColumn(table_name)
4035
4035
4036
4036
perl db_results_variable ()
4037
4037
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' )
4039
4039
let col_values = matchstr (g: dbext_dbi_result ,' \n-[ -]*\zs\n.*' )
4040
4040
" Strip off query statistics
4041
4041
let col_values = substitute ( col_values, ' (\d\+ rows\_.*' , ' ' , ' ' )
@@ -4222,7 +4222,7 @@ function! s:DB_ODBC_getDictionaryTable() "{{{
4222
4222
4223
4223
perl db_results_variable ()
4224
4224
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' )
4226
4226
let col_values = matchstr (g: dbext_dbi_result ,' \n-[ -]*\zs\n.*' )
4227
4227
" Strip off query statistics
4228
4228
let col_values = substitute ( col_values, ' (\d\+ rows\_.*' , ' ' , ' ' )
@@ -4375,7 +4375,7 @@ function! s:DB_ODBC_getDictionaryView() "{{{
4375
4375
4376
4376
perl db_results_variable ()
4377
4377
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' )
4379
4379
let col_values = matchstr (g: dbext_dbi_result ,' \n-[ -]*\zs\n.*' )
4380
4380
" Strip off query statistics
4381
4381
let col_values = substitute ( col_values, ' (\d\+ rows\_.*' , ' ' , ' ' )
@@ -4486,6 +4486,11 @@ function! dbext#DB_execSql(query)
4486
4486
4487
4487
if query != " "
4488
4488
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 ())
4489
4494
endif
4490
4495
endfunction
4491
4496
@@ -6894,10 +6899,13 @@ function! dbext#DB_connect()
6894
6899
endif
6895
6900
let cmd = " perl db_connect('" .driver." ', '" .conn_parms." ', '" .user ." ', '" .passwd." ')"
6896
6901
exec cmd
6897
- if g: dbext_dbi_result == -1
6902
+ if g: dbext_dbi_result == -1
6898
6903
call s: DB_runCmd (" perl " .driver, cmd, g: dbext_dbi_msg )
6899
6904
return -1
6900
6905
endif
6906
+ if g: dbext_dbi_msg != ' '
6907
+ call s: DB_runCmd (" perl " .driver, cmd, g: dbext_dbi_msg )
6908
+ endif
6901
6909
6902
6910
let parmlist = split (driver_parms, ' ;' )
6903
6911
@@ -6924,119 +6932,6 @@ function! dbext#DB_connect()
6924
6932
return 0
6925
6933
endfunction
6926
6934
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
-
7040
6935
function ! dbext#DB_disconnect ()
7041
6936
" Only valid for DBI and ODBC (perl)
7042
6937
let driver = s: DB_get (' type' )
@@ -7070,10 +6965,6 @@ function! dbext#DB_disconnect()
7070
6965
endif
7071
6966
7072
6967
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
7077
6968
7078
6969
return 0
7079
6970
endfunction
0 commit comments