Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

ruby Á¬½Ó²Ù×÷ sql2005


The following is improved version of the code created by David Mullet, from
http://rubyonwindows.blogspot.com/2007/03/ruby-ado-and-sqlserver.html
require 'win32ole'
class SqlServer
# This class manages database connection and queries
attr_accessor :connection, :data, :fields
attr_writer :username, :password
def initialize(host, username = 'sa', password='')
@connection = nil
@data = nil
@host = host
@username = username
@password = password
end
def open(database)
# Open ADO connection to the SQL Server database
connection_string = "Provider=SQLOLEDB.1;"
connection_string << "Persist Security Info=False;"
connection_string << "User ID=#{@username};"
connection_string << "password=#{@password};"
connection_string << "Initial Catalog=#{database};"
connection_string << "Data Source=#{@host};"
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 = @dat


Ïà¹ØÎĵµ£º

SQL´¥·¢Æ÷ʵÀý½²½â

SQL´¥·¢Æ÷ʵÀý1
¶¨Ò壺 ºÎΪ´¥·¢Æ÷£¿ÔÚSQL ServerÀïÃæÒ²¾ÍÊǶÔijһ¸ö±íµÄÒ»¶¨µÄ²Ù×÷£¬´¥·¢Ä³ÖÖÌõ¼þ£¬´Ó¶øÖ´ÐеÄÒ»¶Î³ÌÐò¡£´¥·¢Æ÷ÊÇÒ»¸öÌØÊâµÄ´æ´¢¹ý³Ì¡£
      ³£¼ûµÄ´¥·¢Æ÷ÓÐÈýÖÖ£º·Ö±ðÓ¦ÓÃÓÚInsert , Update , Delete ʼþ¡£
      ÎÒΪʲôҪʹÓô¥·¢Æ÷£¿±ÈÈç£¬Õ ......

Sql Server 2000ÖØÖñêʶÁÐ

ÔÚSQL ServerÖÐ, ÎÒÃÇÓÐʱÐèÒªÔÚÇå¿ÕÊý¾Ý±íÖ®ºó£¬ÖØÐÂÌí¼Ó¼Ç¼ʱ£¬±êʶÁÐÖØÐ´Ó1¿ªÊ¼¼ÆÊý¡£
ÎÒÃÇÖ»ÐèÒªÔÚ²åÈë¼Ç¼֮ǰ£¬Ö´ÐÐÏÂÃæµÄÃüÁ
DBCC CHECKIDENT (±íÃû, RESEED, 0)
Èç¹ûÊÇÇå¿Õ±íÖÐÄÚÈÝÔÙÖØÖñêʶÁпÉÒÔÑ¡ÔñʹÓà Truncate Table ÃüÁ
Truncate Table tablename
TRUNCATE TABLE ÔÚ¹¦ÄÜÉÏÓë²»´ø WHERE ×Ó¾äµÄ ......

ÔÚXMLÀïдSQLÓï¾ä£¨°ÑSQLÓï¾äд½øXMLÀ

ÄãÖªµÀXMLÎļþ°É£¿£¨²»ÖªµÀµÄGOOGLEÈ¥£¡£©ÄÇÄãÌý˵¹ýÔÚXMLÀïÊéдSQLÓï¾äÂ𣿻»¾ä»°Ëµ£¬°ÑÄãµÄÏîÄ¿ÀïËùÓÐSQLÓï¾ä´æ´¢ÔÚXMLÎļþÀÄãÌý˵¹ýÂð£¿Äã×ö¹ýÂð£¿
ÎÒÍ·´ÎÌý˵ÊÇС°¬¸æËßÎҵģ¬ÎҸҿ϶¨ËûÊǸöÕâ·½ÃæµÄ¸ßÊÖ£¬ºÇºÇ£¨ÔÞÒ»¸ö£¬µ½´ËΪֹ£¡£©
ÄǸøÄãչʾһÏ£¬ÔÚXMLÀïÊéдSQLÓï¾ä°É
<commands>
  <comman ......

¹ØÓÚSQL SERVER 2005 ¿ª·¢°æ

ÓÉÓÚ¹¤×÷ºÍѧϰµÄÐèÒª£¬ÒªÔÚ±¾±¾Éϰ²×°SQL SERVER 2005 ¿ª·¢°æ(±¾±¾µÄ²Ù×÷ϵͳÊÇXP£¬ËùÒÔ²»Äܰ²×°Enterprise°æ±¾£¬¶øExpress°æ±¾µÄ¹¦ÄÜÓÖÊ®·ÖÓÐÏÞ)£¬È¥Î¢ÈíµÄ¹Ù·½ÍøÕ¾ËÑË÷ÁËÒ»ÏÂsql server 2005 developer£¬ÕÒµ½ÁËһЩ¹ØÓÚSql server¸÷ÖÖ°æ±¾µÄ½éÉÜ£¬Ê×ÏÈsql server 2005ÓÐÒÔϼ¸ÖÖ°æ±¾£º EE = SQL Server 2005 Enterprise ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ