sql_server 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.textile CHANGED
@@ -1,3 +1,7 @@
1
+ h1. 0.1.1 - 2010-10-13
2
+
3
+ * BUGFIX - Commands now set the timeout that was passed into the connection too.
4
+
1
5
  h1. 0.1.0 - 2010-10-04
2
6
 
3
7
  * Added the ability to execute SQL Server Command Statements.
data/lib/SqlServer.rb CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby -wKU
1
+ #!/usr/bin/env ruby
2
2
  require 'win32ole'
3
3
 
4
4
  class << Hash
@@ -10,13 +10,21 @@ end
10
10
  class SqlServer
11
11
  attr_accessor :connection
12
12
 
13
+ # Creates a Sql Server Connection
14
+ # * :host => The server name or IP.
15
+ # * :user_name => SQL user.
16
+ # * :password => The password for user_name.
17
+ # * :database => Database to connect to on the host.
18
+ # * :timeout => The seconds to wait for a query/commant to run.
13
19
  def initialize(params = {})
14
20
  # Set the connection parameters
15
21
  params = { :host => nil, :user_name => nil, :password => nil,
16
22
  :database => nil, :timeout => nil }.merge!(params)
23
+ @timeout = params[:timeout]
17
24
  @connection = open(params)
18
25
  end
19
-
26
+
27
+ # Executes the sepecified query and returns the results in a hash.
20
28
  def query(sql)
21
29
  # Create an instance of an ADO Recordset
22
30
  recordset = WIN32OLE.new('ADODB.Recordset')
@@ -29,13 +37,13 @@ class SqlServer
29
37
  fields = []
30
38
  data = []
31
39
  recordset.Fields.each do |field|
32
- fields << field.Name
40
+ fields << field.Name
33
41
  end
34
42
 
35
43
  begin
36
44
  # Move to the first record/row, if any exist
37
45
  recordset.MoveFirst
38
-
46
+
39
47
  # Grab all records
40
48
  data = recordset.GetRows
41
49
  rescue Exception => e
@@ -54,6 +62,7 @@ class SqlServer
54
62
  return result_set
55
63
  end
56
64
 
65
+ # Executes the specfied SQL command.
57
66
  def execute_command(sql_statement)
58
67
  # Create an instance of an ADO COmmand
59
68
  command = WIN32OLE.new('ADODB.Command')
@@ -61,16 +70,18 @@ class SqlServer
61
70
  # Execute the SQL statement using the existing ADO connection
62
71
  command.ActiveConnection = @connection
63
72
  command.CommandText=sql_statement
73
+ command.CommandTimeout = @timeout unless @timeout.nil?
64
74
  command.Execute
65
75
  end
66
-
76
+
77
+ # Closes the connection to the SQL Server.
67
78
  def close
68
79
  @connection.Close
69
80
  end
70
81
 
71
82
  private
72
83
 
73
- def open(params)
84
+ def open(params)
74
85
  connection_string = "Provider=SQLNCLI;"
75
86
  connection_string << "Server=#{params[:host]};"
76
87
  connection_string << "Uid=#{params[:user_name]};"
@@ -79,7 +90,7 @@ class SqlServer
79
90
 
80
91
  connection = WIN32OLE.new('ADODB.Connection')
81
92
  connection.Open(connection_string)
82
- connection.CommandTimeout = params[:timeout] unless params[:timeout].nil?
93
+ connection.CommandTimeout = @timeout unless @timeout.nil?
83
94
 
84
95
  return connection
85
96
  end
@@ -1,3 +1,3 @@
1
1
  module SqlServer
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sql_server
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ed Botzum
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-04 00:00:00 -04:00
18
+ date: 2010-10-13 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency