Thinkai's Blog

Autohotkey|Python|php|aardio|VOIP|IT 爱好者

在ado中使用ODBC的dsn连接Oracle、Mysql等数据库 Autohotkey 6128

作者为 发表

Autohotkey

ODBC驱动可以搜索“数据库类型 windows ODBC 插件”安装;DSN需要在开始菜单,Windows管理工具中找“ODBC 数据源(32 位)”,此处如果用32位的AHK则用32位的版本添加,不然无法访问。

a := new adodb
a.open("DSN=testdb;UID=thinkai;PWD=password;") ;到DSN里面配置了用户名密码则UID PWD不用配置。
ret := a.GetTable("select getdate()")
MsgBox % ret.1.1

class adodb
{
	;static conn

	__New() ;新建
	{
	this.conn:= ComObjCreate("ADODB.connection") ;初始化COM
	}

	open(connect_str) ;打开文件
	{
		try
			this.conn.Open(connect_str)
		catch e
			return e.Message
	}

	close() ;关闭文件
	{
		this.conn.Close()
	}

	GetTable(sql)
	{
		t := []
		query := this.conn.Execute(sql)
		if RegExMatch(sql,"i)^select*")
		{
			try
			{
				fetchedArray := query.GetRows() ;取出数据(二维数组)
				colSize := fetchedArray.MaxIndex(1) + 1 ;列最大值 tips:从0开始 所以要+1
				rowSize := fetchedArray.MaxIndex(2) + 1 ;行最大值 tips:从0开始 所以要+1
				loop, % rowSize
				{
					i := (y := A_index) - 1
					t[y] := []
					loop, % colSize
					{
						j := (x := A_index) - 1
						t[y][x] := fetchedArray[j,i] ;取出二维数组内值
					}
				}
			}
			query.Close()
			return t
		}
	}
}



评论给 匿名 4个评论




友情链接:Autohotkey中文帮助Autohotkey官网Autohotkey中文网联系作者免GooglePlay APK下载

 主题设计 • skyfrit.com  Thinkai's Blog | 保留所有权利

61 queries in 1.721 seconds |