Class: TinyTds::Client
- Inherits:
-
Object
- Object
- TinyTds::Client
- Defined in:
- lib/tiny_tds/client.rb,
ext/tiny_tds/client.c
Constant Summary collapse
- TDS_VERSIONS_SETTERS =
{ 'unknown' => 0, '46' => 1, '100' => 2, '42' => 3, '70' => 4, '80' => 5, '90' => 6 # TODO: untested }.freeze
- TDS_VERSIONS_GETTERS =
{ 0 => {:name => 'DBTDS_UNKNOWN', :description => 'Unknown'}, 1 => {:name => 'DBTDS_2_0', :description => 'Pre 4.0 SQL Server'}, 2 => {:name => 'DBTDS_3_4', :description => 'Microsoft SQL Server (3.0)'}, 3 => {:name => 'DBTDS_4_0', :description => '4.0 SQL Server'}, 4 => {:name => 'DBTDS_4_2', :description => '4.2 SQL Server'}, 5 => {:name => 'DBTDS_4_6', :description => '2.0 OpenServer and 4.6 SQL Server.'}, 6 => {:name => 'DBTDS_4_9_5', :description => '4.9.5 (NCR) SQL Server'}, 7 => {:name => 'DBTDS_5_0', :description => '5.0 SQL Server'}, 8 => {:name => 'DBTDS_7_0', :description => 'Microsoft SQL Server 7.0'}, 9 => {:name => 'DBTDS_8_0', :description => 'Microsoft SQL Server 2000'}, 10 => {:name => 'DBTDS_9_0', :description => 'Microsoft SQL Server 2005'} }.freeze
- @@default_query_options =
{ :as => :hash, :symbolize_keys => false, :cache_rows => true, :timezone => :local }
Instance Attribute Summary collapse
-
#query_options ⇒ Object
readonly
Returns the value of attribute query_options.
Class Method Summary collapse
- .default_query_options ⇒ Object
-
.transpose_iconv_encoding(encoding) ⇒ Object
Most, if not all, iconv encoding names can be found by ruby.
Instance Method Summary collapse
- #active? ⇒ Boolean
- #canceled? ⇒ Boolean
- #charset ⇒ Object
- #close ⇒ Object
- #closed? ⇒ Boolean
- #dead? ⇒ Boolean
- #encoding ⇒ Object
- #escape(string) ⇒ Object
- #execute(sql) ⇒ Object
-
#initialize(opts = {}) ⇒ Client
constructor
A new instance of Client.
-
#return_code ⇒ Object
Duplicated in result.c.
- #sqlsent? ⇒ Boolean
-
#tds_version ⇒ Object
TinyTds::Client (public).
- #tds_version_info ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Client
Returns a new instance of Client.
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/tiny_tds/client.rb', line 49 def initialize(opts={}) raise ArgumentError, 'missing :username option' if opts[:username].to_s.empty? raise ArgumentError, 'missing :host option if no :dataserver given' if opts[:dataserver].to_s.empty? && opts[:host].to_s.empty? @query_options = @@default_query_options.dup opts[:appname] ||= 'TinyTds' opts[:tds_version] = TDS_VERSIONS_SETTERS[opts[:tds_version].to_s] || TDS_VERSIONS_SETTERS['80'] opts[:login_timeout] ||= 60 opts[:timeout] ||= 5 opts[:encoding] = (opts[:encoding].nil? || opts[:encoding].downcase == 'utf8') ? 'UTF-8' : opts[:encoding].upcase opts[:port] ||= 1433 opts[:dataserver] = "#{opts[:host]}:#{opts[:port]}" if opts[:dataserver].to_s.empty? connect(opts) end |
Instance Attribute Details
#query_options ⇒ Object (readonly)
Returns the value of attribute query_options.
35 36 37 |
# File 'lib/tiny_tds/client.rb', line 35 def @query_options end |
Class Method Details
.default_query_options ⇒ Object
37 38 39 |
# File 'lib/tiny_tds/client.rb', line 37 def self. @@default_query_options end |
.transpose_iconv_encoding(encoding) ⇒ Object
Most, if not all, iconv encoding names can be found by ruby. Just in case, you can overide this method to return a string name that Encoding.find would work with. Default is to return the passed encoding.
44 45 46 |
# File 'lib/tiny_tds/client.rb', line 44 def self.transpose_iconv_encoding(encoding) encoding end |
Instance Method Details
#active? ⇒ Boolean
68 69 70 |
# File 'lib/tiny_tds/client.rb', line 68 def active? !closed? && !dead? end |
#canceled? ⇒ Boolean
171 172 173 174 |
# File 'ext/tiny_tds/client.c', line 171
static VALUE rb_tinytds_canceled(VALUE self) {
GET_CLIENT_WRAPPER(self);
return cwrap->userdata->dbcancel_sent ? Qtrue : Qfalse;
}
|
#charset ⇒ Object
201 202 203 204 |
# File 'ext/tiny_tds/client.c', line 201
static VALUE rb_tinytds_charset(VALUE self) {
GET_CLIENT_WRAPPER(self);
return cwrap->charset;
}
|
#close ⇒ Object
151 152 153 154 155 156 157 158 159 |
# File 'ext/tiny_tds/client.c', line 151
static VALUE rb_tinytds_close(VALUE self) {
GET_CLIENT_WRAPPER(self);
if (cwrap->client && !cwrap->closed) {
dbclose(cwrap->client);
cwrap->closed = 1;
cwrap->userdata->closed = 1;
}
return Qtrue;
}
|
#closed? ⇒ Boolean
166 167 168 169 |
# File 'ext/tiny_tds/client.c', line 166
static VALUE rb_tinytds_closed(VALUE self) {
GET_CLIENT_WRAPPER(self);
return (cwrap->closed || cwrap->userdata->closed) ? Qtrue : Qfalse;
}
|
#dead? ⇒ Boolean
161 162 163 164 |
# File 'ext/tiny_tds/client.c', line 161
static VALUE rb_tinytds_dead(VALUE self) {
GET_CLIENT_WRAPPER(self);
return dbdead(cwrap->client) ? Qtrue : Qfalse;
}
|
#encoding ⇒ Object
206 207 208 209 210 211 212 213 |
# File 'ext/tiny_tds/client.c', line 206
static VALUE rb_tinytds_encoding(VALUE self) {
GET_CLIENT_WRAPPER(self);
#ifdef HAVE_RUBY_ENCODING_H
return rb_enc_from_encoding(cwrap->encoding);
#else
return Qnil;
#endif
}
|
#escape(string) ⇒ Object
215 216 217 218 219 220 221 222 223 |
# File 'ext/tiny_tds/client.c', line 215
static VALUE rb_tinytds_escape(VALUE self, VALUE string) {
Check_Type(string, T_STRING);
GET_CLIENT_WRAPPER(self);
VALUE new_string = rb_funcall(string, intern_gsub, 2, opt_escape_regex, opt_escape_dblquote);
#ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate(new_string, cwrap->encoding);
#endif
return new_string;
}
|
#execute(sql) ⇒ Object
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'ext/tiny_tds/client.c', line 181
static VALUE rb_tinytds_execute(VALUE self, VALUE sql) {
GET_CLIENT_WRAPPER(self);
rb_tinytds_client_reset_userdata(cwrap->userdata);
REQUIRE_OPEN_CLIENT(cwrap);
dbcmd(cwrap->client, StringValuePtr(sql));
if (dbsqlsend(cwrap->client) == FAIL) {
rb_warn("TinyTds: dbsqlsend() returned FAIL.\n");
return Qfalse;
}
cwrap->userdata->dbsql_sent = 1;
VALUE result = rb_tinytds_new_result_obj(cwrap->client);
rb_iv_set(result, "@query_options", rb_funcall(rb_iv_get(self, "@query_options"), intern_dup, 0));
GET_RESULT_WRAPPER(result);
rwrap->local_offset = rb_funcall(cTinyTdsClient, intern_local_offset, 0);
#ifdef HAVE_RUBY_ENCODING_H
rwrap->encoding = cwrap->encoding;
#endif
return result;
}
|
#return_code ⇒ Object
Duplicated in result.c
226 227 228 229 230 231 232 233 |
# File 'ext/tiny_tds/client.c', line 226
static VALUE rb_tinytds_return_code(VALUE self) {
GET_CLIENT_WRAPPER(self);
if (cwrap->client && dbhasretstat(cwrap->client)) {
return LONG2NUM((long)dbretstatus(cwrap->client));
} else {
return Qnil;
}
}
|
#sqlsent? ⇒ Boolean
176 177 178 179 |
# File 'ext/tiny_tds/client.c', line 176
static VALUE rb_tinytds_sqlsent(VALUE self) {
GET_CLIENT_WRAPPER(self);
return cwrap->userdata->dbsql_sent ? Qtrue : Qfalse;
}
|
#tds_version ⇒ Object
TinyTds::Client (public)
146 147 148 149 |
# File 'ext/tiny_tds/client.c', line 146
static VALUE rb_tinytds_tds_version(VALUE self) {
GET_CLIENT_WRAPPER(self);
return INT2FIX(dbtds(cwrap->client));
}
|
#tds_version_info ⇒ Object
63 64 65 66 |
# File 'lib/tiny_tds/client.rb', line 63 def tds_version_info info = TDS_VERSIONS_GETTERS[tds_version] "#{info[:name]} - #{info[:description]}" if info end |