sam / do fork watch download tarball
public
Rubygem
Description: DataObjects
Homepage: http://rubyforge.org/projects/dorb
Clone URL: git://github.com/sam/do.git
Search Repo:
Moving the quoting to it's own module, finished up the Command spec I 
think.
sam (author)
Tue Feb 12 16:50:16 -0800 2008
commit  dd155f0a1685e53a62f1b4bf1107eb9fee18b5d3
tree    b73fdde51cfb95d4806804110672ebc635530239
parent  55f27ccccda0d415e9362eddb484c23255730ade
...
1
2
3
4
 
5
6
7
...
9
10
11
12
 
13
14
15
16
 
17
18
19
20
 
 
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
...
1
2
3
 
4
5
6
7
...
9
10
11
 
12
13
14
15
 
16
17
18
 
 
19
20
21
22
23
24
25
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
30
0
@@ -1,7 +1,7 @@
0
 module DataObjects
0
   class Command
0
     
0
- attr_reader :text, :timeout, :connection
0
+ attr_reader :connection
0
     
0
     # initialize creates a new Command object
0
     def initialize(connection, text)
0
@@ -9,125 +9,21 @@ module DataObjects
0
     end
0
     
0
     def execute_non_query(*args)
0
- raise LostConnectionError, "the connection to the database has been lost" if @connection.closed?
0
+ raise NotImplementedError.new
0
     end
0
     
0
     def execute_reader(*args)
0
- raise LostConnectionError, "the connection to the database has been lost" if @connection.closed?
0
+ raise NotImplementedError.new
0
     end
0
     
0
- def prepare
0
- raise NotImplementedError
0
+ def set_types(column_types)
0
+ raise NotImplementedError.new
0
     end
0
     
0
     def to_s
0
       @text
0
     end
0
     
0
- # Escape a string of SQL with a set of arguments.
0
- # The first argument is assumed to be the SQL to escape,
0
- # the remaining arguments (if any) are assumed to be
0
- # values to escape and interpolate.
0
- #
0
- # ==== Examples
0
- # escape_sql("SELECT * FROM zoos")
0
- # # => "SELECT * FROM zoos"
0
- #
0
- # escape_sql("SELECT * FROM zoos WHERE name = ?", "Dallas")
0
- # # => "SELECT * FROM zoos WHERE name = `Dallas`"
0
- #
0
- # escape_sql("SELECT * FROM zoos WHERE name = ? AND acreage > ?", "Dallas", 40)
0
- # # => "SELECT * FROM zoos WHERE name = `Dallas` AND acreage > 40"
0
- #
0
- # ==== Warning
0
- # This method is meant mostly for adapters that don't support
0
- # bind-parameters.
0
- def escape_sql(args)
0
- sql = text.dup
0
-
0
- unless args.empty?
0
- sql.gsub!(/\?/) do |x|
0
- quote_value(args.shift)
0
- end
0
- end
0
-
0
- sql
0
- end
0
-
0
- def quote_value(value)
0
- return 'NULL' if value.nil?
0
-
0
- case value
0
- when Numeric then quote_numeric(value)
0
- when String then quote_string(value)
0
- when Class then quote_class(value)
0
- when Time then quote_time(value)
0
- when DateTime then quote_datetime(value)
0
- when Date then quote_date(value)
0
- when TrueClass, FalseClass then quote_boolean(value)
0
- when Array then quote_array(value)
0
- when Symbol then quote_symbol(value)
0
- else
0
- if value.respond_to?(:to_sql)
0
- value.to_sql
0
- else
0
- raise "Don't know how to quote #{value.inspect}"
0
- end
0
- end
0
- end
0
-
0
- def quote_symbol(value)
0
- quote_string(value.to_s)
0
- end
0
-
0
- def quote_numeric(value)
0
- value.to_s
0
- end
0
-
0
- def quote_string(value)
0
- "'#{value.gsub("'", "''")}'"
0
- end
0
-
0
- def quote_class(value)
0
- "'#{value.name}'"
0
- end
0
-
0
- def quote_time(value)
0
- "'#{value.xmlschema}'"
0
- end
0
-
0
- def quote_datetime(value)
0
- "'#{value.dup}'"
0
- end
0
-
0
- def quote_date(value)
0
- "'#{value.strftime("%Y-%m-%d")}'"
0
- end
0
-
0
- def quote_boolean(value)
0
- value.to_s.upcase
0
- end
0
-
0
- def quote_array(value)
0
- "(#{value.map { |entry| quote_value(entry) }.join(', ')})"
0
- end
0
-
0
   end
0
   
0
- class NotImplementedError < StandardError; end
0
-
0
- class ConnectionFailed < StandardError; end
0
-
0
- class ReaderClosed < StandardError; end
0
-
0
- class ReaderError < StandardError; end
0
-
0
- class QueryError < StandardError; end
0
-
0
- class NoInsertError < StandardError; end
0
-
0
- class LostConnectionError < StandardError; end
0
-
0
- class UnknownError < StandardError; end
0
-
0
 end
0
\ No newline at end of file
...
2
3
4
5
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
...
2
3
4
 
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
0
@@ -2,4 +2,22 @@ require File.dirname(__FILE__) + "/connection"
0
 require File.dirname(__FILE__) + "/transaction"
0
 require File.dirname(__FILE__) + "/command"
0
 require File.dirname(__FILE__) + "/result_data"
0
-require File.dirname(__FILE__) + "/reader"
0
\ No newline at end of file
0
+require File.dirname(__FILE__) + "/reader"
0
+
0
+
0
+
0
+# class NotImplementedError < StandardError; end
0
+#
0
+# class ConnectionFailed < StandardError; end
0
+#
0
+# class ReaderClosed < StandardError; end
0
+#
0
+# class ReaderError < StandardError; end
0
+#
0
+# class QueryError < StandardError; end
0
+#
0
+# class NoInsertError < StandardError; end
0
+#
0
+# class LostConnectionError < StandardError; end
0
+#
0
+# class UnknownError < StandardError; end
0
\ No newline at end of file
...
6
7
8
9
 
 
10
11
12
13
14
15
16
 
17
18
19
...
6
7
8
 
9
10
11
12
13
14
15
16
 
17
18
19
20
0
@@ -6,14 +6,15 @@ describe DataObjects::Command do
0
     connection = DataObjects::Connection.new('mock://localhost')
0
     
0
     command = connection.create_command("SELECT * FROM example")
0
-
0
+
0
+ command.should respond_to(:connection)
0
     command.should respond_to(:to_s)
0
     
0
     command.should respond_to(:execute_non_query)
0
     command.should respond_to(:execute_reader)
0
     
0
     command.should respond_to(:set_types)
0
- p command.class
0
+
0
     connection.close
0
   end
0
   

Comments

    No one has commented yet.