圆月山庄资源网 Design By www.vgjia.com
require 'win32ole' class SqlServer # This class manages database connection and queries attr_accessor :connection, :data, :fields def initialize @connection = nil @data = nil end def open # Open ADO connection to the SQL Server database connection_string = "Provider=SQLOLEDB.1;" connection_string << "Persist Security Info=False;" connection_string << "User ID=USER_ID;" connection_string << "password=PASSWORD;" connection_string << "Initial Catalog=DATABASE;" connection_string << "Data Source=IP_ADDRESS;" connection_string << "Network Library=dbmssocn" @connection = WIN32OLE.new('ADODB.Connection') @connection.Open(connection_string) end def query(sql) # Create an instance of an ADO Recordset recordset = WIN32OLE.new('ADODB.Recordset') # Open the recordset, using an SQL statement and the # existing ADO connection recordset.Open(sql, @connection) # Create and populate an array of field names @fields = [] recordset.Fields.each do |field| @fields << field.Name end begin # Move to the first record/row, if any exist recordset.MoveFirst # Grab all records @data = recordset.GetRows rescue @data = [] end recordset.Close # An ADO Recordset's GetRows method returns an array # of columns, so we'll use the transpose method to # convert it to an array of rows @data = @data.transpose end def close @connection.Close end end
测试代码如下:
db = SqlServer.new db.open db.query("SELECT PLAYER FROM PLAYERS WHERE TEAM = 'REDS';") field_names = db.fields players = db.data db.close
db = SqlServer.new('localhost', 'sa', 'SOMEPASSWORD') db.open('Northwind') db.query("SELECT * from Customers;") puts field_names = db.fields cust = db.data puts cust.size puts cust[0].inspect db.close
抄到的别人版本的:
MSSQL require "dbi" require "win32ole" WIN32OLE.codepage = WIN32OLE::CP_UTF8 require 'iconv' Re_cn=/[\x7f-\xff]/ class MssqlDb attr_accessor :mdb, :connection, :data, :fields def initialize(host,mdb,user,pass) @host= host @mdb=@database= mdb @username= user @password= pass @connection = nil @data = nil @fields = nil end def open connection_string = "Provider=SQLOLEDB.1;User ID=@username;password=@password;Data Source=@host,1433;Initial Catalog=@mdb" @connection = WIN32OLE.new('ADODB.Connection') @connection.Open(connection_string) @password='' end def query(sql) recordset = WIN32OLE.new('ADODB.Recordset') recordset.Open(sql, @connection) @fields = [] recordset.Fields.each do |field| @fields << field.Name end begin @data = recordset.GetRows.transpose rescue @data = [] end recordset.Close end def queryGB(sql) if sql=~ Re_cn sql = utf8_to_gb(sql) end recordset = WIN32OLE.new('ADODB.Recordset') recordset.Open(sql, @connection) @fields = [] recordset.Fields.each do |field| @fields << field.Name end begin @data = recordset.GetRows.transpose rescue @data = [] end recordset.Close end def execute(sql) @connection.Execute(sql) end def executeGB(sql) if sql=~ Re_cn sql = utf8_to_gb(sql) end @connection.Execute(sql) end def close @connection.Close end def utf8_to_gb(s) p 'conv to gb18030' Iconv.conv("GB18030//IGNORE","UTF-8//IGNORE",s) end def gb_to_utf8(s) p 'conv to utf8' Iconv.conv("UTF-8//IGNORE","GB18030//IGNORE",s) end end ACCESS require "win32ole" class AccessDb attr_accessor :mdb, :connection, :data, :fields def initialize(mdb=nil) @mdb = mdb @connection = nil @data = nil @fields = nil end def open connection_string = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' connection_string << @mdb @connection = WIN32OLE.new('ADODB.Connection') @connection.Open(connection_string) p 'access open ok.' end def query(sql) recordset = WIN32OLE.new('ADODB.Recordset') recordset.Open(sql, @connection) @fields = [] recordset.Fields.each do |field| @fields << field.Name end begin @data = recordset.GetRows.transpose rescue @data = [] end recordset.Close end def execute(sql) @connection.Execute(sql) end def close @connection.Close end end
圆月山庄资源网 Design By www.vgjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
圆月山庄资源网 Design By www.vgjia.com
暂无评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
2024年11月09日
2024年11月09日
- 雨林唱片《赏》新曲+精选集SACD版[ISO][2.3G]
- 罗大佑与OK男女合唱团.1995-再会吧!素兰【音乐工厂】【WAV+CUE】
- 草蜢.1993-宝贝对不起(国)【宝丽金】【WAV+CUE】
- 杨培安.2009-抒·情(EP)【擎天娱乐】【WAV+CUE】
- 周慧敏《EndlessDream》[WAV+CUE]
- 彭芳《纯色角3》2007[WAV+CUE]
- 江志丰2008-今生为你[豪记][WAV+CUE]
- 罗大佑1994《恋曲2000》音乐工厂[WAV+CUE][1G]
- 群星《一首歌一个故事》赵英俊某些作品重唱企划[FLAC分轨][1G]
- 群星《网易云英文歌曲播放量TOP100》[MP3][1G]
- 方大同.2024-梦想家TheDreamer【赋音乐】【FLAC分轨】
- 李慧珍.2007-爱死了【华谊兄弟】【WAV+CUE】
- 王大文.2019-国际太空站【环球】【FLAC分轨】
- 群星《2022超好听的十倍音质网络歌曲(163)》U盘音乐[WAV分轨][1.1G]
- 童丽《啼笑姻缘》头版限量编号24K金碟[低速原抓WAV+CUE][1.1G]