Ricky

链接

RSS

RSS Link

Excel中访问DB2 for z/OS

2013年9月27日 09:27 | Comments(0) | Category:Other | Tags:

安装一个DB2客户端,比如Data Server或者Toad for DB2

这样就可以创建ODBC数据源

通过ODBC访问并插入工作表:

Sub GetData()
    'Define SQL query string to get the CategoryName field from
    'the Category table.
    sqlstring = "SELECT * From ..."
    'Define connection string and reference File DSN.
    connstring = "ODBC;DSN=DSNName"
    'Create QueryTable in worksheet beginning with cell A1.
    With ActiveSheet.QueryTables.Add(Connection:=connstring, _
        Destination:=Range("A1"), Sql:=sqlstring)
        .Refresh BackgroundQuery := False
    End With

End Sub

 

.Refresh BackgroundQuery := False将会等待查询完成再继续操作,否则在后台完成查询

 

另一种方式:

执行查询并将结果返回到数组,要用到RecordSet对象:


    'define connection and reference file DSN.
    strCon = "Driver={IBM DB2 ODBC DRIVER};Database=DBName;Hostname=" & serverAddress & ";Port=1234;Protocol=TCPIP;Uid=xxx;Pwd=xxx;"

    Set dbCon = CreateObject("ADODB.Connection")
    dbCon.Open strCon

    'define sql stmt
    strSql = "SELECT NAME From SYSIBM.SYSCOLUMNS WHERE TBNAME = '" & tabName & "' AND TBCREATOR = '" & schemaName & "' ORDER BY COLNO;"

    Set rstRecordset = CreateObject("ADODB.Recordset")
    rstRecordset.Open strSql, dbCon, 0, 1, 1

    ' Get records into array
    vArray = rstRecordset.GetRows
    Set rstRecordset = Nothing

    For i = LBound(vArray, 2) To UBound(vArray, 2)
        Msbbox vArray(0,i)
    Next i


    ' Clean up
    Erase vArray  

 

z/OS的ftp命令控制文件格式为Unix

2013年9月23日 12:22 | Comments(0) | Category:Other | Tags:

如果需要ftp下载的文件为LF结尾,而不是CRLF则用这个命令

 

单字节编码:

quote site SBSENDEOL=X

 

多字节编码:

quote site MBSENDEOL=X

 

X可是是LF,CRLF,NONE等

不过GNU ftp不能正确使用这个subcommand,反而Windows上的ftp可以正确执行,很奇怪的问题

z/OS中REXX调用USS

2013年9月11日 16:12 | Comments(1) | Category:Other | Tags:

配合syscalls,可以很灵活的调用USS(Unix System Services)命令:

比如打开一个文件并获取文件描述符,写入关闭文件:


tabval="/path/to/file"

/*open tabval file*/
call syscalls 'ON'
address syscall
'open' tabval,
    O_rdwr+O_creat+O_trunc,
    660
if retval=-1 then
do
    say 'E03: Validation file not opened, err code ' errno errnojr
    return
end
/*get fd*/
fd=retval

rec="Hello World!"
'write' fd 'rec' length(rec)

'close' fd

call syscalls "OFF"

 

调用Unix命令:

cmd = "ls -l"

call bpxwunix cmd,,,cperr.
say cperr.1

bpxwunix有四个参数,分别是执行的命令,标准输入 ,标准输出,标准出错

EBCDIC含有双字节字符转换编码的问题

2013年9月11日 15:40 | Comments(0) | Category:Other | Tags:

主机上的EBCDIC编码还有双字节字符(DBCS)时,比如IBM-1388中文扩展码,通过iconv或者ftp的quote type b 9转换成cp936编码

由于输入中文时,默认会在中文字符开始前加上x'0E',结尾加上x'0F',如果0E和0F不匹配则会转换出错,

比如缺少0F,则转换程序认为从0E开始,直到下一个0F之间的所有内容都是中文

可以用REXX脚本查找不匹配的0E或者0F,并纠正问题即可正常转换了:

pos('0E'x,in.recid,startcol)

Vim中匹配中文

2013年8月30日 17:56 | Comments(0) | Category:Other | Tags:

先记录下来,简单的匹配: [^\x00-\xff],也就是除ASCII字符外的字符

 

当然不够精确,以后找到更好的办法再更新.

配置Cygwin的cron

2013年8月01日 13:11 | Comments(0) | Category:Other | Tags:

$ cron-config
Do you want to install the cron daemon as a service? (yes/no) yes
Enter the value of CYGWIN for the daemon: [ ] ntsec
Do you want the cron daemon to run as yourself? (yes/no) yes
Please enter the password for user 'Administrator':键入密码
Reenter:再次键入密码

配置完成后

安装Cron服务
cygrunsrv -I Cron -p /usr/sbin/cron -a -n
cygrunsrv -I Cygserver -p /usr/sbin/cygserver -e "CYGWIN=server"
安装cygwserver使不运行Cygwin也能在后台定时执行
cron中定义的脚本或者命令

启动cron:
cygrunsrv -S Cron

cygrunsrv -S Cygserver

卸载服务

cygrunsrv -R Cron
本中涉及文件路径时写全局路径
脚本执行要用到java或其他环境变量时,通过source命令引入环境变量

主机模拟终端中粘贴后自动移动光标到粘贴内容结尾

2013年8月01日 11:03 | Comments(2) | Category:Other | Tags:

Aviva:


Sub Main()
 
Dim RowColObj as RowCol
Set RoWColObj = PS.GetCursorLocation
Row% = RoWColObj.Row
Column% = RoWColObj.Column
 
ClipText$ = Clipboard.GetText(1)
TextLen$ = Len(ClipText$) Mod 80
Column% = Column% + TextLen$
Column% = Column% Mod 80
 
rc% = PS.SetCursorLocation(Row%,Column%)
 
End Sub

Personal Communicaton:

[PCOMM SCRIPT HEADER]
LANGUAGE=VBSCRIPT
DESCRIPTION=
[PCOMM SCRIPT SOURCE]
OPTION EXPLICIT
autECLSession.SetConnectionByName(ThisSessionName)

REM This line calls the macro subroutine
subSub1_

sub subSub1_()
   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLMacro "[edit-paste]"
   autECLMacro "[end field]"

end sub

Personal Communicaton版本可以参考Avivia做一些调整,达到更好的效果, 上面这段代码移动光标会移动到一个字段结尾: end filed.
下面这个版本则计算需要移动长度,调用setpos移动光标:



[PCOMM SCRIPT HEADER]
LANGUAGE=VBSCRIPT
DESCRIPTION=This macro call edit-paste and move cursor to end of paste context
'Author: Ricky Ng
'Version: 0.1
[PCOMM SCRIPT SOURCE]
OPTION EXPLICIT
autECLSession.SetConnectionByName(ThisSessionName)
Main

Sub Main()

    Dim strLen, i
    Dim objHTML, strCopy

    'get clipboard context length
    autECLSession.autECLOIA.WaitForAppAvailable
    Set objHTML = CreateObject("htmlfile")
    strCopy = objHTML.ParentWindow.ClipboardData.GetData("text")
    strLen = Len(strCopy)

    'paste and move cursor
    autECLMacro "[edit-paste]"
    'cal move count and set cursor postion like this:
    autECLSession.autECLPS.SetCursorPos x,x
    autECLSession.autECLPS.WaitForCursor x,x,10000
 
End Sub



Tag: Move cursor after paste automatically for TN 3270, mainframe terminal, ISPF, TSO

 

Http proxy设置时遇到密码中的特殊符号

2013年6月19日 15:42 | Comments(1) | Category:Other | Tags:

export http_proxy='http://<Americas\Username>:<Password>@proxy.foo.com'

当密码中有@符号时,需要用URL-encoding代替,比如@替换成%40,折腾了好久

 

设置Everything用TC或者FC打开文件夹

2013年6月17日 16:27 | Comments(0) | Category:Other | Tags:

Everything用来搜索文件或者文件夹比起资源管理器实在方便太多,如果能配合Total Commander或者Free Commander那就更强大了

修改everything.ini,加入两行:

TC:

open_folder_path_command=$exec("D:\Program Files\Total Commander\TOTALCMD.exe" "/O" "/T" "$parent(%1)")
open_folder_command=$exec("D:\Program Files\Total Commander\TOTALCMD.exe" "/O" "/T" "%1")
"/O" "/T"表示在新标签中打开,并且需要设置TC只运行一个实例.

 

FC:

open_folder_path_command=$exec("D:\Program Files\FreeCommander\FreeCommander.exe" "/C" "$parent(%1)")
open_folder_command=$exec("D:\Program Files\FreeCommander\FreeCommander.exe" "/C" "%1")

具体可以参看FC命令行帮助

另外还可以设置快捷键在TC中调用Everything来搜索文件: http://searun.iteye.com/blog/363722

SSIS中生成日期

2013年5月17日 14:22 | Comments(0) | Category:Other | Tags:

GetDate()返回带时间的日期格式,如果只需要日期部分则需要转换,这时候cast/convert则无法使用了,

可用如下办法生成系统时间前一天日期的整数形式:

DATEPART("yyyy",(DT_DBDATE)DATEADD("day",-1,GETDATE())) * 10000 +

DATEPART("mm",(DT_DBDATE)DATEADD("day",-1,GETDATE())) * 100 +

DATEPART("dd",(DT_DBDATE)DATEADD("day",-1,GETDATE()))

 

当然需要字符串格式则很简单了:

(DT_WSTR,30)(DT_DBDATE)(dateadd("d",-1,getdate()))

如果需要不同的形势,拼接就可以了:

(DT_STR,4,65001)DATEPART("yyyy", GetDate() ) +
RIGHT("0" + (DT_STR,4,65001)DATEPART("mm", GetDate() ), 2) +
RIGHT("0" + (DT_STR,4,65001)DATEPART("dd", GetDate() ), 2)
 

参考

http://www.w3school.com.cn/sql/func_convert.asp

SSIS导入平面文件到数据库的UTF-8编码问题

2013年5月16日 16:29 | Comments(0) | Category:Other | Tags:

平面文件是UTF-8编码,导入的时候遇到cannot convert between unicode and non-unicode问题

1. 目标表是VARCHAR, 则平面文件列类型为String [DT_STR], 并且设置AlwasyUseDefaultCodePage True, 默认编码用65001(UTF-8)

2. 目标表是NVARCHAR, 则平面文件列类型设置为Unicode_String [DT_WSTR]即可

lftp上传、下载整个目录

2013年3月19日 12:04 | Comments(0) | Category:Other | Tags:

lftp连接成功后:

mirror -R <local dir>

上传本地目录

 

mirror -R <remote dir><local dir>

下载整个远程目录

搬家了,这里就是的新家

2011年12月28日 15:52 | Comments(6) | Category:Other | Tags:

鉴于CSDN泄密,我也懒得找回密码,只好把以前的文章搬过来了.

懒得把以前的文章都搬过来了,尝试搬家也失败了,提供原文地址: CSDN