dbd-adonet 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +49 -0
- data/dbd-adonet.gemspec +28 -0
- data/lib/dbd/adonet.rb +77 -0
- data/lib/dbd/adonet/prepared_statement.rb +55 -0
- metadata +71 -0
data/README.rdoc
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
= IronRuby DBI - Easing data access for ironruby
|
2
|
+
|
3
|
+
* http://github.com/casualjim/ironruby-dbi
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
This project aims to provide adapters based on the .NET System.Data infrastructure.
|
8
|
+
It does so to make using existing ruby OR/M solutions easier to integrate.
|
9
|
+
|
10
|
+
== FEATURES/PROBLEMS:
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
== SYNOPSIS:
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
== REQUIREMENTS:
|
20
|
+
|
21
|
+
* To use the caricature library you need to have uuidtools installed
|
22
|
+
(sudo) gem install uuidtools
|
23
|
+
(sudo) igem install uuidtools
|
24
|
+
|
25
|
+
== INSTALL:
|
26
|
+
|
27
|
+
(sudo) igem install ironruby-dbi
|
28
|
+
|
29
|
+
== LICENSE:
|
30
|
+
|
31
|
+
Copyright (c) 2009 IronRuby-DBI team
|
32
|
+
|
33
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
34
|
+
of this software and associated documentation files (the "Software"), to deal
|
35
|
+
in the Software without restriction, including without limitation the rights
|
36
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
37
|
+
copies of the Software, and to permit persons to whom the Software is
|
38
|
+
furnished to do so, subject to the following conditions:
|
39
|
+
|
40
|
+
The above copyright notice and this permission notice shall be included in
|
41
|
+
all copies or substantial portions of the Software.
|
42
|
+
|
43
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
44
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
45
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
46
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
47
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
48
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
49
|
+
THE SOFTWARE.
|
data/dbd-adonet.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# WARNING : RAKE AUTO-GENERATED FILE. DO NOT MANUALLY EDIT!
|
2
|
+
# RUN : 'rake gem:update_gemspec'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.authors = ["Ivan Porto Carrero"]
|
6
|
+
s.description = "A DBD implementation for .NET based drivers."
|
7
|
+
s.email = "ivan@flanders.co.nz"
|
8
|
+
s.extra_rdoc_files = ["README.rdoc"]
|
9
|
+
s.files = ["README.rdoc",
|
10
|
+
"dbd-adonet.gemspec",
|
11
|
+
"lib/dbd/adonet.rb",
|
12
|
+
"lib/dbd/adonet/prepared_statement.rb"]
|
13
|
+
s.has_rdoc = true
|
14
|
+
s.homepage = "http://casualjim.github.com/ironruby-dbi"
|
15
|
+
s.loaded = false
|
16
|
+
s.name = "dbd-adonet"
|
17
|
+
s.platform = "ruby"
|
18
|
+
s.rdoc_options = ["--quiet", "--title", "A DBD implementation for .NET based drivers.", "--main", "README.rdoc"]
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
s.required_ruby_version = ">= 1.8.4"
|
21
|
+
s.required_rubygems_version = ">= 0"
|
22
|
+
s.rubyforge_project = "ironruby-dbi"
|
23
|
+
s.rubygems_version = "1.3.5"
|
24
|
+
s.specification_version = 3
|
25
|
+
s.add_runtime_dependency "dbi", "= 0.4.3"
|
26
|
+
s.summary = "A DBD implementation for .NET based drivers."
|
27
|
+
s.version = "0.3.2"
|
28
|
+
end
|
data/lib/dbd/adonet.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'rubygems' unless defined? Gem
|
2
|
+
|
3
|
+
module DBI
|
4
|
+
module IRONRUBY
|
5
|
+
USES_DBD_VERSION = "0.4.3"
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
gem 'dbi', "= #{DBI::IRONRUBY::USES_DBD_VERSION}" unless ENV['RUBY_DBI']
|
10
|
+
$:.unshift "#{ENV['RUBY_DBI']}/lib"
|
11
|
+
require 'dbi'
|
12
|
+
require 'System.Data'
|
13
|
+
|
14
|
+
module DBI
|
15
|
+
module IRONRUBY
|
16
|
+
VERSION = '0.3.2'
|
17
|
+
end
|
18
|
+
|
19
|
+
module DBD
|
20
|
+
|
21
|
+
PROVIDERS = {
|
22
|
+
:odbc => "System.Data.Odbc",
|
23
|
+
:oledb => "System.Data.OleDb",
|
24
|
+
:oracle => "System.Data.OracleClient",
|
25
|
+
:mssql => "System.Data.SqlClient",
|
26
|
+
:sqlce => "System.Data.SqlServerCe.3.5",
|
27
|
+
:mysql => "MySql.Data.MySqlClient",
|
28
|
+
:sqlite => "System.Data.SQLite",
|
29
|
+
:postgresql => "Npgsql"
|
30
|
+
}
|
31
|
+
|
32
|
+
# Implements the basic functionality that constitutes a Driver
|
33
|
+
#
|
34
|
+
# Drivers do not have a direct interface exposed to the user; these methods
|
35
|
+
# are mostly for DBD authors.
|
36
|
+
#
|
37
|
+
# As with DBI::BaseDatabase, "DBD Required" and "DBD Optional" will be used
|
38
|
+
# to explain the same requirements.
|
39
|
+
#
|
40
|
+
class BaseAdonetDriver < DBI::BaseDriver
|
41
|
+
|
42
|
+
DEFAULT_PROVIDER = PROVIDERS[:mssql]
|
43
|
+
|
44
|
+
include System::Data::Common
|
45
|
+
|
46
|
+
def initialize(dbi_version, key)
|
47
|
+
major, minor = dbi_version.split(".").collect { |x| x.to_i }
|
48
|
+
dbi_major, dbi_minor = DBI::VERSION.split(".").collect { |x| x.to_i }
|
49
|
+
unless major == dbi_major and minor == dbi_minor
|
50
|
+
raise InterfaceError, "Wrong DBD API version used"
|
51
|
+
end
|
52
|
+
@provider = PROVIDERS[key] || DEFAULT_PROVIDER
|
53
|
+
end
|
54
|
+
|
55
|
+
# Connect to the database. DBD Required.
|
56
|
+
def connect(dbname, user, auth, attr)
|
57
|
+
connection = factory.create_connection
|
58
|
+
connection.connection_string = dbname
|
59
|
+
connection.open
|
60
|
+
return create_database(connection, attr);
|
61
|
+
rescue RuntimeError, System::Data::SqlClient::SqlException => err
|
62
|
+
raise DBI::DatabaseError.new(err.message)
|
63
|
+
end
|
64
|
+
|
65
|
+
def create_database(connection, attr)
|
66
|
+
raise NotImplementedError
|
67
|
+
end
|
68
|
+
|
69
|
+
def factory
|
70
|
+
@factory ||= DbProviderFactories.get_factory(@provider)
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module DBI
|
2
|
+
module Adonet
|
3
|
+
class PreparedStatement < DBI::SQL::PreparedStatement
|
4
|
+
|
5
|
+
# attempts to bind the arguments in +args+ to this statement.
|
6
|
+
# Will raise StandardError if there are any extents issues.
|
7
|
+
def bind
|
8
|
+
@unbound.each do |res_pos, arg_pos|
|
9
|
+
@result[res_pos] = "@p#{arg_pos + 1}"
|
10
|
+
end
|
11
|
+
|
12
|
+
@result.join("")
|
13
|
+
end
|
14
|
+
alias_method :to_s, :bind
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
# prepares the statement for binding. This is done by scanning the
|
19
|
+
# statement and itemizing what needs to be bound and what does not.
|
20
|
+
#
|
21
|
+
# This information will then be used by #bind to appropriately map
|
22
|
+
# parameters to the intended destinations.
|
23
|
+
def prepare
|
24
|
+
@result = []
|
25
|
+
@unbound = {}
|
26
|
+
pos = 0
|
27
|
+
@arg_index = 0
|
28
|
+
|
29
|
+
tokens.each { |part|
|
30
|
+
case part
|
31
|
+
when '?'
|
32
|
+
@result[pos] = nil
|
33
|
+
@unbound[pos] = @arg_index
|
34
|
+
pos += 1
|
35
|
+
@arg_index += 1
|
36
|
+
when '??'
|
37
|
+
if @result[pos-1] != nil
|
38
|
+
@result[pos-1] << "?"
|
39
|
+
else
|
40
|
+
@result[pos] = "?"
|
41
|
+
pos += 1
|
42
|
+
end
|
43
|
+
else
|
44
|
+
if @result[pos-1] != nil
|
45
|
+
@result[pos-1] << part
|
46
|
+
else
|
47
|
+
@result[pos] = part
|
48
|
+
pos += 1
|
49
|
+
end
|
50
|
+
end
|
51
|
+
}
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dbd-adonet
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ivan Porto Carrero
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-03-02 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: dbi
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - "="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.4.3
|
24
|
+
version:
|
25
|
+
description: A DBD implementation for .NET based drivers.
|
26
|
+
email: ivan@flanders.co.nz
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.rdoc
|
33
|
+
files:
|
34
|
+
- README.rdoc
|
35
|
+
- dbd-adonet.gemspec
|
36
|
+
- lib/dbd/adonet.rb
|
37
|
+
- lib/dbd/adonet/prepared_statement.rb
|
38
|
+
has_rdoc: true
|
39
|
+
homepage: http://casualjim.github.com/ironruby-dbi
|
40
|
+
licenses: []
|
41
|
+
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options:
|
44
|
+
- --quiet
|
45
|
+
- --title
|
46
|
+
- A DBD implementation for .NET based drivers.
|
47
|
+
- --main
|
48
|
+
- README.rdoc
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.8.4
|
56
|
+
version:
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
version:
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project: ironruby-dbi
|
66
|
+
rubygems_version: 1.3.5
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: A DBD implementation for .NET based drivers.
|
70
|
+
test_files: []
|
71
|
+
|