On Tue, Nov 11, 2008 at 7:37 PM, YC <[EMAIL PROTECTED]> wrote:
>
> Hello All,
>
> When using dbext module to run an sql statement, the result is in a
> 'Result' buffer. I'd like to capture the first 10 lines from the
> result buffer and append them to a file. Here is what I tried, It runs
> with no error but returns empty result:
>
> function! DBextPostResult(db_type, buf_nr)
> "--Desc: Append top 10 lines in dbext result window into a file
>
> "--get top 10 lines from result window. THIS RETURNS EMPTY!
Hello Ying.
I just tried this.
Note, when DBextPostResult is called you are in the result buffer (I
believe this will always be true).
You can issue some things to confirm:
echo getline(1)
echo getline(5)
When I tried using your code:
>echo getbufline(a:buf_nr,1,5)
[]
>echo getbufline(a:buf_nr+0,1,5)
['Connection: T(DBI) I(SQLAnywhere) P(AutoCommit=1;PrintError=0)
U(dba) at 22:52', 'TABLE_CAT TABLE_SCH
EM TABLE_NAME TABLE_TYPE REMARKS
Maybe someone else on this list can explain why we need to do some
arithmetic to convert the parameter a:buf_nr into an integer so that
getbufline() will work correctly.
But at least you have what you need.
By the way, when you do this:
let topLines = getbufline(a:buf_nr,1,min([10,line("$")]))
topLines is a List.
You are doing this:
redir >> c:\temp\dbext.result | silent echo join(topLines,"\n") |
Which could be replaced with:
let rc = writefile(topLines, 'c:\temp\dbext.result')
That will overwrite it, but you can also use readfile() to get the
contents of it.
HTH,
Dave
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---