ydbi 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +6 -0
  3. data/ChangeLog +3699 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +25 -0
  6. data/Rakefile +8 -0
  7. data/TODO +44 -0
  8. data/bench/bench.rb +79 -0
  9. data/bin/dbi +518 -0
  10. data/bin/test_broken_dbi +37 -0
  11. data/build/Rakefile.dbi.rb +60 -0
  12. data/build/rake_task_lib.rb +187 -0
  13. data/doc/DBD_SPEC.rdoc +88 -0
  14. data/doc/DBI_SPEC.rdoc +157 -0
  15. data/doc/homepage/contact.html +62 -0
  16. data/doc/homepage/development.html +124 -0
  17. data/doc/homepage/index.html +83 -0
  18. data/doc/homepage/ruby-dbi.css +91 -0
  19. data/examples/test1.pl +39 -0
  20. data/examples/test1.rb +20 -0
  21. data/examples/xmltest.rb +8 -0
  22. data/lib/dbd/Mysql.rb +137 -0
  23. data/lib/dbd/ODBC.rb +89 -0
  24. data/lib/dbd/Pg.rb +188 -0
  25. data/lib/dbd/SQLite.rb +97 -0
  26. data/lib/dbd/SQLite3.rb +124 -0
  27. data/lib/dbd/mysql/database.rb +405 -0
  28. data/lib/dbd/mysql/driver.rb +125 -0
  29. data/lib/dbd/mysql/statement.rb +188 -0
  30. data/lib/dbd/odbc/database.rb +128 -0
  31. data/lib/dbd/odbc/driver.rb +38 -0
  32. data/lib/dbd/odbc/statement.rb +137 -0
  33. data/lib/dbd/pg/database.rb +516 -0
  34. data/lib/dbd/pg/exec.rb +47 -0
  35. data/lib/dbd/pg/statement.rb +160 -0
  36. data/lib/dbd/pg/tuples.rb +121 -0
  37. data/lib/dbd/pg/type.rb +209 -0
  38. data/lib/dbd/sqlite/database.rb +151 -0
  39. data/lib/dbd/sqlite/statement.rb +125 -0
  40. data/lib/dbd/sqlite3/database.rb +201 -0
  41. data/lib/dbd/sqlite3/statement.rb +78 -0
  42. data/lib/dbi.rb +336 -0
  43. data/lib/dbi/base_classes.rb +12 -0
  44. data/lib/dbi/base_classes/database.rb +135 -0
  45. data/lib/dbi/base_classes/driver.rb +47 -0
  46. data/lib/dbi/base_classes/statement.rb +171 -0
  47. data/lib/dbi/binary.rb +25 -0
  48. data/lib/dbi/columninfo.rb +107 -0
  49. data/lib/dbi/exceptions.rb +65 -0
  50. data/lib/dbi/handles.rb +49 -0
  51. data/lib/dbi/handles/database.rb +241 -0
  52. data/lib/dbi/handles/driver.rb +60 -0
  53. data/lib/dbi/handles/statement.rb +408 -0
  54. data/lib/dbi/row.rb +269 -0
  55. data/lib/dbi/sql.rb +22 -0
  56. data/lib/dbi/sql/preparedstatement.rb +115 -0
  57. data/lib/dbi/sql_type_constants.rb +75 -0
  58. data/lib/dbi/trace.rb +91 -0
  59. data/lib/dbi/types.rb +218 -0
  60. data/lib/dbi/typeutil.rb +109 -0
  61. data/lib/dbi/utils.rb +60 -0
  62. data/lib/dbi/utils/date.rb +59 -0
  63. data/lib/dbi/utils/tableformatter.rb +112 -0
  64. data/lib/dbi/utils/time.rb +52 -0
  65. data/lib/dbi/utils/timestamp.rb +96 -0
  66. data/lib/dbi/utils/xmlformatter.rb +73 -0
  67. data/lib/dbi/version.rb +3 -0
  68. data/prototypes/types2.rb +237 -0
  69. data/readme.md +274 -0
  70. data/setup.rb +1585 -0
  71. data/test/DBD_TESTS +50 -0
  72. data/test/TESTING +16 -0
  73. data/test/dbd/general/test_database.rb +206 -0
  74. data/test/dbd/general/test_statement.rb +326 -0
  75. data/test/dbd/general/test_types.rb +296 -0
  76. data/test/dbd/mysql/base.rb +26 -0
  77. data/test/dbd/mysql/down.sql +19 -0
  78. data/test/dbd/mysql/test_blob.rb +18 -0
  79. data/test/dbd/mysql/test_new_methods.rb +7 -0
  80. data/test/dbd/mysql/test_patches.rb +111 -0
  81. data/test/dbd/mysql/up.sql +28 -0
  82. data/test/dbd/odbc/base.rb +30 -0
  83. data/test/dbd/odbc/down.sql +19 -0
  84. data/test/dbd/odbc/test_new_methods.rb +12 -0
  85. data/test/dbd/odbc/test_ping.rb +10 -0
  86. data/test/dbd/odbc/test_statement.rb +44 -0
  87. data/test/dbd/odbc/test_transactions.rb +58 -0
  88. data/test/dbd/odbc/up.sql +33 -0
  89. data/test/dbd/postgresql/base.rb +31 -0
  90. data/test/dbd/postgresql/down.sql +31 -0
  91. data/test/dbd/postgresql/test_arrays.rb +179 -0
  92. data/test/dbd/postgresql/test_async.rb +121 -0
  93. data/test/dbd/postgresql/test_blob.rb +36 -0
  94. data/test/dbd/postgresql/test_bytea.rb +87 -0
  95. data/test/dbd/postgresql/test_ping.rb +10 -0
  96. data/test/dbd/postgresql/test_timestamp.rb +77 -0
  97. data/test/dbd/postgresql/test_transactions.rb +58 -0
  98. data/test/dbd/postgresql/testdbipg.rb +307 -0
  99. data/test/dbd/postgresql/up.sql +60 -0
  100. data/test/dbd/sqlite/base.rb +32 -0
  101. data/test/dbd/sqlite/test_database.rb +30 -0
  102. data/test/dbd/sqlite/test_driver.rb +68 -0
  103. data/test/dbd/sqlite/test_statement.rb +112 -0
  104. data/test/dbd/sqlite/up.sql +25 -0
  105. data/test/dbd/sqlite3/base.rb +32 -0
  106. data/test/dbd/sqlite3/test_database.rb +77 -0
  107. data/test/dbd/sqlite3/test_driver.rb +67 -0
  108. data/test/dbd/sqlite3/test_statement.rb +88 -0
  109. data/test/dbd/sqlite3/up.sql +33 -0
  110. data/test/dbi/tc_columninfo.rb +94 -0
  111. data/test/dbi/tc_date.rb +88 -0
  112. data/test/dbi/tc_dbi.rb +184 -0
  113. data/test/dbi/tc_row.rb +256 -0
  114. data/test/dbi/tc_sqlbind.rb +168 -0
  115. data/test/dbi/tc_statementhandle.rb +29 -0
  116. data/test/dbi/tc_time.rb +77 -0
  117. data/test/dbi/tc_timestamp.rb +142 -0
  118. data/test/dbi/tc_types.rb +268 -0
  119. data/test/ts_dbd.rb +131 -0
  120. data/test/ts_dbi.rb +16 -0
  121. data/ydbi.gemspec +24 -0
  122. metadata +224 -0
@@ -0,0 +1,62 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
4
+ <head>
5
+ <meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8"/>
6
+ <title>Ruby/DBI - Direct database access layer for Ruby</title>
7
+ <link rel="stylesheet" type="text/css" href="ruby-dbi.css"/>
8
+ </head>
9
+ <body>
10
+ <div class="body-container">
11
+ <h1>Ruby/DBI - Contact Information</h1>
12
+ <div class="main-container">
13
+ <div class="nav-container">
14
+ <h1>Links</h1>
15
+ <a href="index.html">Home</a>
16
+ <a href="http://rubyforge.org/projects/ruby-dbi">RubyForge Project</a>
17
+ <a href="http://ruby-dbi.rubyforge.org/rdoc/index.html">RDoc</a>
18
+ <a href="development.html">Developer Information</a>
19
+ <a href="http://www.kitebird.com/articles/ruby-dbi.html">Ruby/DBI Tutorial</a>
20
+ <a href="contact.html">Contact/Reporting Bugs</a>
21
+ </div>
22
+ <p>
23
+ If you'd like to contact us to report a bug or submit a patch,
24
+ please use the <a
25
+ href="http://rubyforge.org/tracker/?group_id=234">tracker</a>
26
+ on RubyForge.
27
+ </p>
28
+
29
+ <p>
30
+ If you'd like to ask questions about using Ruby/DBI, there is a
31
+ <a href="http://rubyforge.org/mailman/listinfo/ruby-dbi-users">ruby-dbi-users</a> email list where those questions
32
+ can be answered. Likewise, <a
33
+ href="http://rubyforge.org/mailman/listinfo/ruby-dbi-bugs">ruby-dbi-bugs</a>
34
+ is for discussing bug reports in detail, and <a
35
+ href="http://rubyforge.org/mailman/listinfo/ruby-dbi-devel-new">ruby-dbi-devel-new</a> is for discussing future
36
+ development and management of the project.
37
+ </p>
38
+
39
+ <p>
40
+ If you're an irc user, the <b>#ruby-dbi</b> irc channel on
41
+ <b>freenode</b> will get you in touch with developers and
42
+ advanced users.
43
+ </p>
44
+
45
+ <p>
46
+ If these avenues are not working for you for some reason,
47
+ please feel free to contact <a
48
+ href="mailto:erik-at-hollensbe-dot-org">Erik</a>
49
+ directly. He will be glad to help!
50
+ </p>
51
+ </div>
52
+ <br />
53
+ <br />
54
+ <div class="copyright">
55
+ &copy;2008 Erik Hollensbe, all rights reserved. Please see the
56
+ README file for the full copyright notice. Please see the
57
+ LICENSE file in the source package for information on
58
+ redistributing the source or any of the site content.
59
+ </div>
60
+ </div>
61
+ </body>
62
+ </html>
@@ -0,0 +1,124 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
4
+ <head>
5
+ <meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8"/>
6
+ <title>Ruby/DBI - Direct database access layer for Ruby</title>
7
+ <link rel="stylesheet" type="text/css" href="ruby-dbi.css"/>
8
+ </head>
9
+ <body>
10
+ <div class="body-container">
11
+ <h1>Ruby/DBI - Development Information</h1>
12
+ <div class="main-container">
13
+ <div class="nav-container">
14
+ <h1>Links</h1>
15
+ <a href="index.html">Home</a>
16
+ <a href="http://rubyforge.org/projects/ruby-dbi">RubyForge Project</a>
17
+ <a href="http://ruby-dbi.rubyforge.org/rdoc/index.html">RDoc</a>
18
+ <a href="development.html">Developer Information</a>
19
+ <a href="http://www.kitebird.com/articles/ruby-dbi.html">Ruby/DBI Tutorial</a>
20
+ <a href="contact.html">Contact/Reporting Bugs</a>
21
+ </div>
22
+ <p>
23
+ Regarding patches, please consider these issues:
24
+ <br />
25
+ <ul>
26
+ <li>
27
+ If your patch does not contain tests, it better be
28
+ very compelling, as someone else will be forced to
29
+ write them.
30
+ </li>
31
+ <li>
32
+ Please ensure your patch addresses the whole
33
+ problem space. If it's a patch for DBI, makes sure it
34
+ works with <b>all</b> DBDs. Likewise, if it is DBD
35
+ scope, it should handle all versions of the database
36
+ that DBD supports.
37
+ </li>
38
+ <li>
39
+ Please follow the existing formatting in the
40
+ files. Check your diffs to see that you aren't
41
+ generating patches with tons of formatting-only
42
+ changes.
43
+ </li>
44
+ <li>
45
+ If you plan a series of patches, consider setting
46
+ up a git repository, or merging your patches before
47
+ you submit them.
48
+ </li>
49
+ </ul>
50
+ <br />
51
+ </p>
52
+ <p>
53
+ Regarding bug reports, please consider these issues:
54
+ <br />
55
+ <ul>
56
+ <li>
57
+ Use the tracker if you can. Posting to the lists or
58
+ a private email is ok, but if it's multipart or
59
+ significantly complex you may be asked to post it
60
+ to the tracker anyways.
61
+ </li>
62
+ <li>
63
+ Please search the tracker first, and have a
64
+ repeatable use case that accurately describes your
65
+ problem.
66
+ </li>
67
+ <li>
68
+ If you post to the tracker, have a rubyforge
69
+ account and ensure you're logged in. If you don't,
70
+ and questions to need to be asked, your bug will
71
+ likely be quickly round-filed. Our tracker is not
72
+ your cathartic dumping ground.
73
+ </li>
74
+ </ul>
75
+ <p>
76
+ If you'd like to contact us to report a bug or submit a patch,
77
+ please use the <a
78
+ href="http://rubyforge.org/tracker/?group_id=234">tracker</a>
79
+ on RubyForge. If you plan long term development, consider
80
+ setting up a git repository other developers can pull from.
81
+ </p>
82
+
83
+ <p>
84
+ Please see the <a href="contact.html">contact</a> page
85
+ about contacting developers or mailing lists.
86
+ </p>
87
+
88
+ <p>
89
+ We now use 'git' for our revision control system. We now push
90
+ to several locations:
91
+
92
+ <dl>
93
+ <dt>Rubyforge</dt>
94
+ <dd>git://rubyforge.org/ruby-dbi.git</dd>
95
+ <dt>GitHub</dt>
96
+ <dd>git://github.com/erikh/ruby-dbi.git</dd>
97
+ <dt>hollensbe.org</dt>
98
+ <dd>git://hollensbe.org/git/ruby-dbi.git</dd>
99
+ </dl>
100
+ <br />
101
+
102
+ Forward development occurs in the 'development' branch,
103
+ which is version-tagged and merged into 'master' at release
104
+ time. 'master' is used to track release versions and
105
+ maintenance to those versions.
106
+ </p>
107
+
108
+ <p>
109
+ Ruby/DBI is a BSD-licensed product. As a result, the
110
+ licensing on your patches must be the same. Please do
111
+ not send patches that are of any other license. Thanks!
112
+ </p>
113
+ </div>
114
+ <br />
115
+ <br />
116
+ <div class="copyright">
117
+ &copy;2008 Erik Hollensbe, all rights reserved. Please see the
118
+ README file for the full copyright notice. Please see the
119
+ LICENSE file in the source package for information on
120
+ redistributing the source or any of the site content.
121
+ </div>
122
+ </div>
123
+ </body>
124
+ </html>
@@ -0,0 +1,83 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
4
+ <head>
5
+ <meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8"/>
6
+ <title>Ruby/DBI - Direct database access layer for Ruby</title>
7
+ <link rel="stylesheet" type="text/css" href="ruby-dbi.css"/>
8
+ </head>
9
+ <body>
10
+ <div class="body-container">
11
+ <h1>Ruby/DBI - Direct database access layer for Ruby</h1>
12
+ <div class="main-container">
13
+ <div class="nav-container">
14
+ <h1>Links</h1>
15
+ <a href="index.html">Home</a>
16
+ <a href="http://rubyforge.org/projects/ruby-dbi">RubyForge Project</a>
17
+ <a href="http://ruby-dbi.rubyforge.org/rdoc/index.html">RDoc</a>
18
+ <a href="development.html">Developer Information</a>
19
+ <a href="http://www.kitebird.com/articles/ruby-dbi.html">Ruby/DBI Tutorial</a>
20
+ <a href="contact.html">Contact/Reporting Bugs</a>
21
+ </div>
22
+
23
+ <p>
24
+ Ruby/DBI is a database interface in the spirit of Perl's prolific
25
+ <a href="http://search.cpan.org/~timb/DBI/DBI.pm">DBI</a> authored
26
+ by Tim Bunce.
27
+ </p>
28
+
29
+ <p>
30
+ Ruby/DBI differs in quite a few ways, however. It incorporates
31
+ many "rubyisms" while maintaining the core DBI interface, and a
32
+ suite of commonly used DBD's are maintained with the
33
+ application.
34
+ </p>
35
+
36
+ <p>
37
+ Ruby/DBI is <i>not</i> an ORM, like <a
38
+ href="http://ar.rubyonrails.com">ActiveRecord</a> or <a
39
+ href="http://datamapper.rubyforge.org">DataMapper</a>. It is a
40
+ lightweight, centralized API to database manipulation. An ORM may
41
+ or may not be what you want for a given situation, due to weight,
42
+ ease-of-use or other issues. Our goal with Ruby/DBI is to provide a
43
+ compelling, lightweight interface that you can use for things where
44
+ an ORM is too much or too cumbersome.
45
+ </p>
46
+
47
+ <p>
48
+ Getting started with Ruby/DBI is very easy if you have a working
49
+ knowledge of SQL and your target database. Read the <a
50
+ href="http://ruby-dbi.rubyforge.org/rdoc/index.html">Documentation</a>
51
+ to get on your way!
52
+ </p>
53
+
54
+ <p>
55
+ The maintainer, Erik Hollensbe, has made a commitment to
56
+ keeping Ruby/DBI compatible with future Ruby releases. There is
57
+ also a significant interest in enhancing the suite by further
58
+ clarifying and enforcing the interface, and further tailoring DBI
59
+ for the specific needs of Ruby users (as opposed to many of the
60
+ Perlisms maintained) without impacting the goal of the project.
61
+ There is also significant effort applied to clarifying the
62
+ underpinnings, making debugging and development simpler.
63
+ </p>
64
+
65
+ <p>
66
+ Ruby/DBI is a very old project as far as the ruby community is
67
+ concerned, tracing back to at least 2001. There are plenty of
68
+ people who <a
69
+ href="http://ruby-dbi.rubyforge.org/rdoc/index.html">have
70
+ contributed</a> to this effort. Big thanks to the original
71
+ project lead, Michael Neumann, and Francis Hwang and Daniel Berger, who held the
72
+ project in escrow for such a long time.
73
+ </p>
74
+ </div>
75
+ <div class="copyright">
76
+ &copy;2008 Erik Hollensbe, all rights reserved. Please see the
77
+ README file for the full copyright notice. Please see the
78
+ LICENSE file in the source package for information on
79
+ redistributing the source or any of the site content.
80
+ </div>
81
+ </div>
82
+ </body>
83
+ </html>
@@ -0,0 +1,91 @@
1
+ BODY {
2
+ background-color: #666;
3
+ }
4
+
5
+ a:visited {
6
+ color: #144;
7
+ }
8
+
9
+ a {
10
+ color: white;
11
+ }
12
+
13
+ a:active {
14
+ text-decoration: none;
15
+ }
16
+
17
+ a:hover {
18
+ text-decoration: none;
19
+ }
20
+
21
+ .body-container {
22
+ margin-left: auto;
23
+ margin-right: auto;
24
+ margin-top: 50px;
25
+ width: 80%;
26
+ background-color: #AAA;
27
+ color: black;
28
+ padding: 10px;
29
+ border: 1px solid black;
30
+ }
31
+
32
+ h1 {
33
+ display: block;
34
+ margin: 2em;
35
+ border: 1px solid black;
36
+ padding: 1em;
37
+ color: #444;
38
+ font-size: 1em;
39
+ text-align: center;
40
+ font-family: sans-serif;
41
+ }
42
+
43
+ .main-container {
44
+ margin: 2em;
45
+ }
46
+
47
+ .nav-container {
48
+ display: block;
49
+ border: 1px solid black;
50
+ float: left;
51
+ vertical-align; top:
52
+ font-size: .8em;
53
+ min-width: 20%;
54
+ margin-right: 2em;
55
+ margin-bottom: 2em;
56
+ }
57
+
58
+ .nav-container h1 {
59
+ margin: 0;
60
+ padding: 0;
61
+ border: 0;
62
+ border-bottom: 1px solid black;
63
+ font-size: 1.2em;
64
+ font-weight: bold;
65
+ color: black;
66
+ text-align: center;
67
+ font-family: sans-serif;
68
+ }
69
+
70
+ .nav-container a {
71
+ display: block;
72
+ padding: 5px;
73
+ }
74
+
75
+ .nav-container a:hover {
76
+ background-color: #444;
77
+ color: white;
78
+ font-weight: bold;
79
+ }
80
+
81
+ .copyright {
82
+ display: block;
83
+ margin: 2em;
84
+ border: 1px solid black;
85
+ padding: 1em;
86
+ color: #444;
87
+ font-size: 0.6em;
88
+ text-align: center;
89
+ font-family: sans-serif;
90
+ }
91
+
@@ -0,0 +1,39 @@
1
+ use DBI;
2
+
3
+ $dbh = DBI->connect("dbi:Oracle:oracle.neumann", "scott", "tiger", {RaiseError => 1, AutoCommit => 0} );
4
+
5
+
6
+ $dbh->do("DROP TABLE MYTEST");
7
+ $dbh->do("CREATE TABLE MYTEST (a INT, b VARCHAR2(256), c FLOAT, d VARCHAR2(256))");
8
+
9
+ $sth = $dbh->prepare("INSERT INTO MYTEST VALUES (:1, :2, :3, :4)");
10
+
11
+ $i = 1;
12
+
13
+ while ($i <= 10000) {
14
+
15
+ $sth->execute($i, "Michael der $i. von Neumann", 5.6 * $i, "HALLO LEUTE WIE GEHTS DENN SO?");
16
+
17
+ $i = $i + 1;
18
+ #print $i, "\n";
19
+ }
20
+
21
+
22
+ $dbh->commit();
23
+
24
+
25
+
26
+
27
+
28
+ #$sth = $dbh->prepare("SELECT * FROM EMP");
29
+
30
+ #$sth->execute();
31
+
32
+ #while (@row = $sth->fetchrow_array()) {
33
+ # print(@row);
34
+ #}
35
+
36
+
37
+ $dbh->disconnect();
38
+
39
+
@@ -0,0 +1,20 @@
1
+ require "dbi"
2
+
3
+ dbh = DBI.connect("dbi:Oracle:oracle.neumann", "scott", "tiger", 'AutoCommit' => false)
4
+
5
+ dbh.do("DROP TABLE MYTEST")
6
+ dbh.do("CREATE TABLE MYTEST (a INT, b VARCHAR2(256), c FLOAT, d VARCHAR2(256))")
7
+
8
+ sth = dbh.prepare("INSERT INTO MYTEST VALUES (:1, :2, :3, :4)")
9
+
10
+ 1.upto(10000) do |i|
11
+ sth.execute(i.to_s, "Michael der #{i}. von Neumann", (5.6 * i).to_s, "HALLO LEUTE WIE GEHTS DENN SO?")
12
+ #print i, "\n"
13
+ end
14
+
15
+ sth.finish
16
+
17
+ dbh.commit
18
+
19
+ dbh.disconnect
20
+
@@ -0,0 +1,8 @@
1
+ require "dbi"
2
+
3
+ DBI.connect("dbi:Oracle:oracle.neumann") do |dbh|
4
+ dbh.execute("SELECT * FROM EMP") do |sth|
5
+ DBI::Utils::XMLFormatter.table(sth.fetch_all, "EMP")
6
+ end
7
+ end
8
+
@@ -0,0 +1,137 @@
1
+ #--
2
+ # Copyright (c) 2001, 2002 Michael Neumann <neumann@s-direktnet.de>
3
+ #
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions
8
+ # are met:
9
+ # 1. Redistributions of source code must retain the above copyright
10
+ # notice, this list of conditions and the following disclaimer.
11
+ # 2. Redistributions in binary form must reproduce the above copyright
12
+ # notice, this list of conditions and the following disclaimer in the
13
+ # documentation and/or other materials provided with the distribution.
14
+ # 3. The name of the author may not be used to endorse or promote products
15
+ # derived from this software without specific prior written permission.
16
+ #
17
+ # THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18
+ # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19
+ # AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
20
+ # THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23
+ # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24
+ # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25
+ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26
+ # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ #
28
+ # $Id$
29
+ #++
30
+
31
+ begin
32
+ require 'rubygems'
33
+ gem 'mysql'
34
+ gem 'dbi'
35
+ rescue LoadError => e
36
+ end
37
+
38
+ require 'dbi'
39
+ require "mysql"
40
+ require "thread" # for Mutex
41
+
42
+ module DBI
43
+ module DBD
44
+ #
45
+ # DBD::Mysql - Database Driver for the MySQL database system.
46
+ #
47
+ # Requires DBI and the 'mysql' gem or package to work.
48
+ #
49
+ # Only things that extend DBI's results are documented.
50
+ #
51
+ module Mysql
52
+ VERSION = "0.4.4"
53
+ DESCRIPTION = "MySQL DBI DBD, Leverages 'mysql' low-level driver"
54
+
55
+ MyError = ::MysqlError
56
+
57
+ #
58
+ # returns 'Mysql'
59
+ #
60
+ # See DBI::TypeUtil#convert for more information.
61
+ #
62
+ def self.driver_name
63
+ "Mysql"
64
+ end
65
+
66
+ DBI::TypeUtil.register_conversion(driver_name) do |obj|
67
+ newobj = case obj
68
+ when ::DBI::Binary
69
+ obj = obj.to_s.gsub(/\\/) { "\\\\" }
70
+ obj = obj.to_s.gsub(/'/) { "''" }
71
+ "'#{obj}'"
72
+ when ::DateTime
73
+ "'#{obj.strftime("%Y-%m-%d %H:%M:%S")}'"
74
+ when ::Time
75
+ "'#{obj.strftime("%H:%M:%S")}'"
76
+ when ::Date
77
+ "'#{obj.strftime("%Y-%m-%d")}'"
78
+ when ::NilClass
79
+ "NULL"
80
+ else
81
+ obj
82
+ end
83
+
84
+ if newobj.object_id == obj.object_id
85
+ [newobj, true]
86
+ else
87
+ [newobj, false]
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+
94
+ #
95
+ # Utility Methods for the MySQL DBD.
96
+ #
97
+
98
+ module DBI::DBD::Mysql::Util
99
+ private
100
+
101
+ # Raise exception using information from MysqlError object e.
102
+ # For state value, use SQLSTATE value if mysql-ruby defines
103
+ # sqlstate method, otherwise nil.
104
+ def error(e)
105
+ sqlstate = e.respond_to?("sqlstate") ? e.sqlstate : nil
106
+ raise DBI::DatabaseError.new(e.message, e.errno, sqlstate)
107
+ end
108
+
109
+ end # module Util
110
+
111
+ module DBI::DBD::Mysql::Type
112
+ #
113
+ # Custom handling for DATE types in MySQL. See DBI::Type for more
114
+ # information.
115
+ #
116
+ class Date < DBI::Type::Null
117
+ def self.parse(obj)
118
+ obj = super
119
+ return obj unless obj
120
+
121
+ case obj.class
122
+ when ::Date
123
+ return obj
124
+ when ::String
125
+ return ::Date.strptime(obj, "%Y-%m-%d")
126
+ else
127
+ return ::Date.parse(obj.to_s) if obj.respond_to? :to_s
128
+ return ::Date.parse(obj.to_str) if obj.respond_to? :to_str
129
+ return obj
130
+ end
131
+ end
132
+ end
133
+ end
134
+
135
+ require 'dbd/mysql/driver'
136
+ require 'dbd/mysql/database'
137
+ require 'dbd/mysql/statement'