fluiddb 0.0.17 → 0.0.18
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/FluidDb/TinyTds.rb +97 -0
- metadata +3 -2
@@ -0,0 +1,97 @@
|
|
1
|
+
require "FluidDb"
|
2
|
+
require "tiny_tds"
|
3
|
+
|
4
|
+
module FluidDb
|
5
|
+
|
6
|
+
class TinyTds<Base
|
7
|
+
|
8
|
+
# Connect to Db.
|
9
|
+
#
|
10
|
+
# @param [String] uri a location for the resource to which we will attach, eg tinytds://user:pass@127.0.0.1
|
11
|
+
def connect()
|
12
|
+
uri = @uri
|
13
|
+
raise "Unsupported uri. Please update freetds.conf and use format tinytds://<user>:<pass>@<dataserver>" unless uri.path == ""
|
14
|
+
|
15
|
+
dataserver = uri.host
|
16
|
+
username = uri.user
|
17
|
+
password = uri.password
|
18
|
+
|
19
|
+
puts "#{username}, #{password}, #{dataserver}"
|
20
|
+
|
21
|
+
@connection = ::TinyTds::Client.new( :username => username, :password => password, :dataserver => dataserver )
|
22
|
+
end
|
23
|
+
|
24
|
+
def close
|
25
|
+
@connection.close
|
26
|
+
end
|
27
|
+
|
28
|
+
def queryForArray( sql, params )
|
29
|
+
sql = self.format_to_sql( sql, params )
|
30
|
+
results = @connection.exec(sql)
|
31
|
+
|
32
|
+
count = 0
|
33
|
+
tuple = ""
|
34
|
+
results.each do |row|
|
35
|
+
count = count + 1
|
36
|
+
raise FluidDb::TooManyRowsError.new if count > 1
|
37
|
+
|
38
|
+
tuple = row
|
39
|
+
end
|
40
|
+
|
41
|
+
raise FluidDb::NoDataFoundError.new if count == 0
|
42
|
+
|
43
|
+
return tuple
|
44
|
+
end
|
45
|
+
|
46
|
+
def queryForValue( sql, params )
|
47
|
+
sql = self.format_to_sql( sql, params )
|
48
|
+
results = @connection.exec(sql)
|
49
|
+
|
50
|
+
count = 0
|
51
|
+
value = ""
|
52
|
+
results.each do |row|
|
53
|
+
count = count + 1
|
54
|
+
raise FluidDb::TooManyRowsError.new if count > 1
|
55
|
+
|
56
|
+
value = row[results.fields[0]]
|
57
|
+
end
|
58
|
+
|
59
|
+
raise FluidDb::NoDataFoundError.new if count == 0
|
60
|
+
|
61
|
+
return value
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
def queryForResultset( sql, params )
|
66
|
+
sql = self.format_to_sql( sql, params )
|
67
|
+
results = @connection.exec(sql)
|
68
|
+
|
69
|
+
list = Array.new
|
70
|
+
results.each do |row|
|
71
|
+
list << row
|
72
|
+
end
|
73
|
+
|
74
|
+
return list
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
def execute( sql, params, expected_affected_rows=nil )
|
79
|
+
sql = self.format_to_sql( sql, params )
|
80
|
+
r = @connection.execute( sql );
|
81
|
+
r.each
|
82
|
+
|
83
|
+
if !expected_affected_rows.nil? and
|
84
|
+
r.affected_rows != expected_affected_rows then
|
85
|
+
raise ExpectedAffectedRowsError.new( "Expected affected rows, #{expected_affected_rows}, Actual affected rows, #{r.affected_rows}")
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def insert( sql, params )
|
90
|
+
raise "Pgsql uses SEQUENCES, so possibly easier to use 2 executes"
|
91
|
+
# self.execute( sql, params )
|
92
|
+
#return @connection.last_id
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluiddb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.18
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-25 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A semantic layer for db interaction
|
15
15
|
email: guy@guyirvine.com
|
@@ -22,6 +22,7 @@ files:
|
|
22
22
|
- lib/FluidDb/Mysql.rb
|
23
23
|
- lib/FluidDb/Mysql2.rb
|
24
24
|
- lib/FluidDb/Pgsql.rb
|
25
|
+
- lib/FluidDb/TinyTds.rb
|
25
26
|
- lib/FluidDb.rb
|
26
27
|
- README.md
|
27
28
|
homepage: http://rubygems.org/gems/fluiddb
|