SlideShare a Scribd company logo
1 of 11
Download to read offline
Accessing MySQL from Ruby
Contents
1.      Introduction .................................................................................................................................... 2
2.      Prerequisites ................................................................................................................................... 2
3.      Setup ............................................................................................................................................... 2
     3.1.       Populate MySQL Database ...................................................................................................... 2
     3.2.       Set up ODBC Access ................................................................................................................ 3
4.      Discovery ......................................................................................................................................... 4
     4.1.       Web Service Creation using SOA Gateway ............................................................................. 4
     4.2.       Accessing the WSDL ................................................................................................................ 6
5.      Accessing a Web Service with Ruby ................................................................................................ 8
     Ruby Editor.......................................................................................................................................... 8
     Ruby Code ........................................................................................................................................... 8
     Debugging Code .................................................................................................................................. 9
6.      Conclusion ..................................................................................................................................... 10
7.      Appendix ....................................................................................................................................... 10




Accessing MySQL from Ruby                                                                              Author: John O’Mahony, Risaris Ltd
1. Introduction
In this tutorial we will show you how to build a Ruby application to access MySQL via the SOA
Gateway.


2. Prerequisites
It is assumed that you are running the 3 components, MySQL, Ruby and the SOA Gateway on
Windows.

It is assumed you already have a SOA Gateway server and Control Centre installed. See here for
more info about installing the SOA Gateway.


3. Setup
Download the latest binaries for Ruby from the Ruby downloads page, install it
according to the install.txt document in the Ruby distribution library. For this tutorial I downloaded
Ruby 1.8.6 One-Click Installer and followed the default options.

You will also need a MySQL database. Again, the Open Source version (known as the MySQL
Community Server) can be freely downloaded from the MySQL website. See this link for download,
and here to step you through the installation and configuration.

    3.1.Populate MySQL Database
    Now that you’ve got MySQL installed and configured, you will need to populate it with some
    demo data. For this we use the RisarisBank sample. This is available here.

           Save this file to “C:TempRisarisBank.sql”
           Connect to the MySQL Server using the mysql command.

            E.g shell> mysql –u root –p

            This command connects to the server using the MySQL root account to make sure that
            you'll have permission to create the RisarisBank database. The -p option tells mysql
            to prompt you for the root password. Enter the password when prompted. (Remember
            that the MySQL root account is not the same as the operating system root account
            and probably will have a different password.)

           Create the RisarisBank database.

            mysql> CREATE DATABASE RisarisBank;

            mysql> use RisarisBank;

           Load the contents of RisarisBank.sql into the RisarisBank database. E.g.

            mysql> SOURCE c:TempRisarisBank.sql

           After the SOURCE command finishes, you can view your new tables.




Accessing MySQL from Ruby                                          Author: John O’Mahony, Risaris Ltd
mysql> SHOW TABLES;

           mysql> DESCRIBE CustomerInformation;

           mysql> DESCRIBE Branch;

           etc …

   3.2.Set up ODBC Access
   The final thing to do with your MySQL Database is to set up an ODBC DSN which will be used by
   the SOA Gateway to access this database.

   Click Start, Control Panel, Administrative Tools, Data Sources (ODBC)

   From the resulting screen, choose the “System DSN” Tab.

   Click Add

   From the list of data source drivers, select “MySQL ODBC 3.51 Driver”.

       If you do not see this driver in the list, you need to install the MySQL Connector. See here for
       more information. We recommend installing v3.51.

   Click Finish, and a window will appear allowing you to enter the DSN information. Add the
   following:

       Data Source Name: RisarisBank

       Description: The Risaris Bank Sample in MySQL

       Server: localhost

       User: root

       Password: *** your MySQL root password ***

       Database: RisarisBank (select from the drop down list)




Accessing MySQL from Ruby                                          Author: John O’Mahony, Risaris Ltd
All other options can be left as-is. Click OK.


4. Discovery
At this stage you’ve got Ruby installed, and a MySQL database with some sample data in it. In this
section we’ll show you how to create web services from each of the MySQL tables. These web
services can be used by the Ruby language (and many others) to give you direct real-time access to
your MySQL Data.

   4.1.Web Service Creation using SOA Gateway
   Start your SOA Gateway Control Centre. See here for an introduction to the Control Centre.

   In your servers view, right click the entry which represents your local SOA Gateway Server. Select
   “Create New Web Services”.




Accessing MySQL from Ruby                                        Author: John O’Mahony, Risaris Ltd
From the next dialog, choose “MySQL Driver”. If you do not see have a MySQL Driver in the list,
   see how to create one here.




   Click Next.

   The next screen gives you the ability to add information about your DSN




Accessing MySQL from Ruby                                       Author: John O’Mahony, Risaris Ltd
Enter the above information and click Discover.

   The wizard will display all the tables it finds at this (RisarisBank) DSN.

   Click “Select All”, and click “Import”.

   The wizard will create web services from each one of these tables.




   You’ve just created 8 Web Services from your 8 MySQL Tables!



   4.2.Accessing the WSDL
   Web Service Description Language (WSDL) is a standard, XML-based language that is used to
   describe a Web Service.

   For each of the 8 web services you’ve created in the previous section, the SOA Gateway provides
   you with a WSDL to describe the Web Service. The WSDL itself is usually interpreted by a web



Accessing MySQL from Ruby                                            Author: John O’Mahony, Risaris Ltd
service client, such as Ruby, but it is useful to know where to find the WSDL for each of your
   Web Services.

   As WSDL is XML-based, it will open in your browser of choice. To see the WSDL for one of your
   Risaris Bank web services, do the following in your SOA Gateway Control Centre:

          Click on the web service you are interested in, for example the “branch” web service.
          The properties for this web service should appear in your Properties View. If you do not
           see the Properties view, select Window -> Show View -> Other -> General -> Properties
           and click OK.
          In the properties view, there is a link to your WSDL. Click it to open the WSDL in a
           browser.




Accessing MySQL from Ruby                                         Author: John O’Mahony, Risaris Ltd
You can view the WSDL for the other web services by clicking the link from their properties
       view.
       This WSDL is the starting point for using Web Services, and can be used time and again by
       different web service clients.




5. Accessing a Web Service with Ruby
We will use a Ruby script to access our new Risaris Bank Web Services via the WSDL. Those familiar
with Ruby will probably want to change the script provided but it can be run with minimum changes
described below. The whole script is provided in APPENDIX A.

    Ruby Editor
   Use the editor provided, SciTE.exe, which is located in folder scite where you installed Ruby.
   Copy the code from Appendix A and save the code as the filename RBCustomerTutorial.rb (as in
   example below).

   Hit F5 and the results will appear in the right-hand pane:




   Ruby Code
    Depending on your MySQL settings you will have to change the username/password provided in
   the on_simple_outbound method. In this example the user is root with no password.


   "<UsernameToken><Username>root</Username><Password></Password></UsernameToken>"



Accessing MySQL from Ruby                                       Author: John O’Mahony, Risaris Ltd
Note also the WSDL URL http://localhost:56000/customerinformation?WSDL. Again depending
   on your SOA Gateway configuration you may need to change the server/port number.

   In this example provided we are issuing a list request on the customer information table in the
   RisarisBank database. The list request can handle a wilcarded customer number key:

   param = {"CustomerNumber" => "1*"}

   result = soap.list(param)

   Finally we can query the result for the customer’s first name:

   for cust in (result. customerinformationRoot.customerinformationGroup)

    print(cust.firstName, "n")

   end

   Obviously this can be replaced by any of the column names in the customer information table.

   Debugging Code
   The code provided should work off the bat. However, depending on your MySQL configuration,
   the RisarisBank tables may not be in lowercase as in our example e.g. customerinformation
   versus CustomerInformation. If this is the case the code will not work as is and all occurrences of
   customerinformation should be replaced by CustomerInformation.

   The p and puts functions are useful for checking the content of variables. For example p result
   after the result = soap.list(param) call gives the following information and is useful for checking
   column names for adding new code.

   #<SOAP::Mapping::Object:0x3240c04
   {}customerinformationRoot=#<SOAP::Mapping::Object:0x3240ad8
   {}customerinformationGroup=[#<SOAP::Mapping::Object:0x32409ac
   {}CustomerNumber="1" {}FirstName="Casper" {}Surname="Ankergren"
   {}AddressLine1="34 Green Street" {}AddressLine2="Crosses Street"
   {}City="Mansfield" {}Postcode="MA5 9AJ" {}DateOfBirth="30/05/1978">,
   #<SOAP::Mapping::Object:0x323f4bc {}CustomerNumber="10"
   {}FirstName="Grenville" {}Surname="Dekker" {}AddressLine1="22 Uttoxter
   New Road" {}AddressLine2="Chaddesden" {}City="Leeds" {}Postcode="LS4
   9WB" {}DateOfBirth="21/10/1974">, #<SOAP::Mapping::Object:0x323e0b2
   {}CustomerNumber="11" {}FirstName="Jane" {}Surname="Freeman"
   {}AddressLine1="3 Portland Street" {}AddressLine2="Lichfield"
   {}City="Gloucester" {}Postcode="GL4 8KD" {}DateOfBirth="26/10/1980">,
   #<SOAP::Mapping::Object:0x323ccb2 {}CustomerNumber="12"
   {}FirstName="Dale" {}Surname="Rolling" {}AddressLine1="The Hunters Rest"
   {}AddressLine2="Branston" {}City="Preston" {}Postcode="PR4 4HG"
   {}DateOfBirth="06/12/1989">, #<SOAP::Mapping::Object:0x323b8b2
   {}CustomerNumber="13" {}FirstName="Arnold" {}Surname="Corrigan"
   {}AddressLine1="14 Anderson Street" {}AddressLine2="Allestree"
   {}City="Derby" {}Postcode="DE6 8FT" {}DateOfBirth="10/06/1970">,
   #<SOAP::Mapping::Object:0x323a4b2 {}CustomerNumber="14"
   {}FirstName="Alfred" {}Surname="Summerscale" {}AddressLine1="3701 S.



Accessing MySQL from Ruby                                           Author: John O’Mahony, Risaris Ltd
George Mason" {}AddressLine2="Melbourne" {}City="Bath" {}Postcode="BA6
   8UU" {}DateOfBirth="07/08/1982">, #<SOAP::Mapping::Object:0x32390b2
   {}CustomerNumber="15" {}FirstName="Peter" {}Surname="Spiegel"
   {}AddressLine1="11663 Charter Oak Co" {}AddressLine2="Foremark"
   {}City="Manchester" {}Postcode="M98 4GT" {}DateOfBirth="29/12/1971">,
   #<SOAP::Mapping::Object:0x3237cb2 {}CustomerNumber="16"
   {}FirstName="John" {}Surname="Sviridov" {}AddressLine1="3319 Rosemere
   Court" {}AddressLine2="Brailsford" {}City="Leeds" {}Postcode="LS8 5QQ"
   {}DateOfBirth="12/06/1984">, #<SOAP::Mapping::Object:0x32368b2
   {}CustomerNumber="17" {}FirstName="Sarah" {}Surname="Hall"
   {}AddressLine1="4 Denmark Lane" {}AddressLine2="East Bridgford"
   {}City="Portsmouth" {}Postcode="PO9 7QN" {}DateOfBirth="12/02/1983">,
   #<SOAP::Mapping::Object:0x32354b2 {}CustomerNumber="18"
   {}FirstName="Elspeth" {}Surname="Jones" {}AddressLine1="12375 W. Ohio
   Circle" {}AddressLine2="Risley" {}City="Birmingham" {}Postcode="B93 1IO"
   {}DateOfBirth="28/08/1986">, #<SOAP::Mapping::Object:0x32340b2
   {}CustomerNumber="19" {}FirstName="Nigel" {}Surname="Wyllis"
   {}AddressLine1="14 Borough Road" {}AddressLine2="Ockbrook"
   {}City="Leeds" {}Postcode="LS8 2WL" {}DateOfBirth="29/04/1981">]>>



6. Conclusion
This tutorial shows how to access MySQL from Ruby using the SOA Gateway. As you can see, you
have built a powerful application that uses Web Services to retrieve information in real-time.


7. Appendix
require 'soap/wsdlDriver'

require 'soap/header/simplehandler'



# A handler to add authentication parameters to the SOAP header.

  class AutheticationHeaderHandler < SOAP::Header::SimpleHandler

      @@HEADER_NAME = 'Security'

     def initialize(namespace)

           super(XSD::QName.new(namespace, @@HEADER_NAME))

     end



     def on_simple_outbound

       #Change the username/password below to reflect your own environment


"<UsernameToken><Username>root</Username><Password></Password></UsernameTok
en>"




Accessing MySQL from Ruby                                      Author: John O’Mahony, Risaris Ltd
end

  end

wsdl_url = "http://localhost:56000/customerinformation?WSDL"



soap = SOAP::WSDLDriverFactory.new(wsdl_url).create_rpc_driver

soap.wiredump_file_base = "soapresult"

soap.headerhandler <<
AutheticationHeaderHandler.new("http://www.risaris.com/security")



param = {"CustomerNumber" => "1*"}



result = soap.list(param)

for cust in (result.customerinformationRoot.customerinformationGroup)

  print(cust.firstName, "n")

end




Accessing MySQL from Ruby                       Author: John O’Mahony, Risaris Ltd

More Related Content

What's hot

New Flash Builder 4 WSDL and HTTP Connectors
New Flash Builder 4 WSDL and HTTP ConnectorsNew Flash Builder 4 WSDL and HTTP Connectors
New Flash Builder 4 WSDL and HTTP Connectorsrtretola
 
Creating and connecting to odi master and work repositories
Creating and connecting to odi master and work repositoriesCreating and connecting to odi master and work repositories
Creating and connecting to odi master and work repositoriesAbdoulaye M Yansane
 
Session And Cookies In Servlets - Java
Session And Cookies In Servlets - JavaSession And Cookies In Servlets - Java
Session And Cookies In Servlets - JavaJainamParikh3
 
Java API for XML Web Services (JAX-WS)
Java API for XML Web Services (JAX-WS)Java API for XML Web Services (JAX-WS)
Java API for XML Web Services (JAX-WS)Peter R. Egli
 
IBM Connect 2016 - Break out of the Box
IBM Connect 2016 - Break out of the BoxIBM Connect 2016 - Break out of the Box
IBM Connect 2016 - Break out of the BoxKarl-Henry Martinsson
 
Bt0083 server side programing
Bt0083 server side programing Bt0083 server side programing
Bt0083 server side programing Techglyphs
 
Servlet ppt by vikas jagtap
Servlet ppt by vikas jagtapServlet ppt by vikas jagtap
Servlet ppt by vikas jagtapVikas Jagtap
 
Java web services using JAX-WS
Java web services using JAX-WSJava web services using JAX-WS
Java web services using JAX-WSIndicThreads
 

What's hot (15)

New Flash Builder 4 WSDL and HTTP Connectors
New Flash Builder 4 WSDL and HTTP ConnectorsNew Flash Builder 4 WSDL and HTTP Connectors
New Flash Builder 4 WSDL and HTTP Connectors
 
Creating and connecting to odi master and work repositories
Creating and connecting to odi master and work repositoriesCreating and connecting to odi master and work repositories
Creating and connecting to odi master and work repositories
 
WebLogic FAQs
WebLogic FAQsWebLogic FAQs
WebLogic FAQs
 
Nick harris-sic-2011
Nick harris-sic-2011Nick harris-sic-2011
Nick harris-sic-2011
 
Session And Cookies In Servlets - Java
Session And Cookies In Servlets - JavaSession And Cookies In Servlets - Java
Session And Cookies In Servlets - Java
 
Java API for XML Web Services (JAX-WS)
Java API for XML Web Services (JAX-WS)Java API for XML Web Services (JAX-WS)
Java API for XML Web Services (JAX-WS)
 
JAX-WS Basics
JAX-WS BasicsJAX-WS Basics
JAX-WS Basics
 
IBM Connect 2016 - Break out of the Box
IBM Connect 2016 - Break out of the BoxIBM Connect 2016 - Break out of the Box
IBM Connect 2016 - Break out of the Box
 
Break out of The Box - Part 2
Break out of The Box - Part 2Break out of The Box - Part 2
Break out of The Box - Part 2
 
AD102 - Break out of the Box
AD102 - Break out of the BoxAD102 - Break out of the Box
AD102 - Break out of the Box
 
11-DWR-and-JQuery
11-DWR-and-JQuery11-DWR-and-JQuery
11-DWR-and-JQuery
 
Dwr
DwrDwr
Dwr
 
Bt0083 server side programing
Bt0083 server side programing Bt0083 server side programing
Bt0083 server side programing
 
Servlet ppt by vikas jagtap
Servlet ppt by vikas jagtapServlet ppt by vikas jagtap
Servlet ppt by vikas jagtap
 
Java web services using JAX-WS
Java web services using JAX-WSJava web services using JAX-WS
Java web services using JAX-WS
 

Viewers also liked

Viewers also liked (7)

rails.html
rails.htmlrails.html
rails.html
 
Devoxx%202008%20Tutorial
Devoxx%202008%20TutorialDevoxx%202008%20Tutorial
Devoxx%202008%20Tutorial
 
ruby-efl-tutorial-hsyl20
ruby-efl-tutorial-hsyl20ruby-efl-tutorial-hsyl20
ruby-efl-tutorial-hsyl20
 
lab56_db
lab56_dblab56_db
lab56_db
 
has_many_and_belongs_to_many
has_many_and_belongs_to_manyhas_many_and_belongs_to_many
has_many_and_belongs_to_many
 
wtst3_pettichord3
wtst3_pettichord3wtst3_pettichord3
wtst3_pettichord3
 
rubyonrails
rubyonrailsrubyonrails
rubyonrails
 

Similar to Accessing MySQL from Ruby in a concise guide

Accessing my sql_from_java
Accessing my sql_from_javaAccessing my sql_from_java
Accessing my sql_from_javaTran Rean
 
Introduction to MySQL - Part 1
Introduction to MySQL - Part 1Introduction to MySQL - Part 1
Introduction to MySQL - Part 1webhostingguy
 
Introduction to MySQL - Part 1
Introduction to MySQL - Part 1Introduction to MySQL - Part 1
Introduction to MySQL - Part 1webhostingguy
 
Introduction to MySQL - Part 1
Introduction to MySQL - Part 1Introduction to MySQL - Part 1
Introduction to MySQL - Part 1webhostingguy
 
Introduction to MySQL - Part 1
Introduction to MySQL - Part 1Introduction to MySQL - Part 1
Introduction to MySQL - Part 1webhostingguy
 
My sql università di enna a.a. 2005-06
My sql   università di enna a.a. 2005-06My sql   università di enna a.a. 2005-06
My sql università di enna a.a. 2005-06YUCHENG HU
 
Spring boot-application
Spring boot-applicationSpring boot-application
Spring boot-applicationParag Patil
 
Guide - Migrating from Heroku to AWS using CloudFormation
Guide - Migrating from Heroku to AWS using CloudFormationGuide - Migrating from Heroku to AWS using CloudFormation
Guide - Migrating from Heroku to AWS using CloudFormationRob Linton
 
Mysqlppt3510
Mysqlppt3510Mysqlppt3510
Mysqlppt3510Anuja Lad
 
How To Create RDS Database for WordPress in AWS on RHEL 7 or CentOS 7
How To Create RDS Database for WordPress in AWS on RHEL 7 or CentOS 7How To Create RDS Database for WordPress in AWS on RHEL 7 or CentOS 7
How To Create RDS Database for WordPress in AWS on RHEL 7 or CentOS 7VCP Muthukrishna
 
SULTHAN's PHP, MySQL & wordpress
SULTHAN's PHP, MySQL & wordpressSULTHAN's PHP, MySQL & wordpress
SULTHAN's PHP, MySQL & wordpressSULTHAN BASHA
 
MySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA ToolMySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA ToolMiguel Araújo
 

Similar to Accessing MySQL from Ruby in a concise guide (20)

Accessing my sql_from_java
Accessing my sql_from_javaAccessing my sql_from_java
Accessing my sql_from_java
 
Introduction to MySQL - Part 1
Introduction to MySQL - Part 1Introduction to MySQL - Part 1
Introduction to MySQL - Part 1
 
Introduction to MySQL - Part 1
Introduction to MySQL - Part 1Introduction to MySQL - Part 1
Introduction to MySQL - Part 1
 
Introduction to MySQL - Part 1
Introduction to MySQL - Part 1Introduction to MySQL - Part 1
Introduction to MySQL - Part 1
 
Introduction to MySQL - Part 1
Introduction to MySQL - Part 1Introduction to MySQL - Part 1
Introduction to MySQL - Part 1
 
My sql università di enna a.a. 2005-06
My sql   università di enna a.a. 2005-06My sql   università di enna a.a. 2005-06
My sql università di enna a.a. 2005-06
 
Mysql tutorial
Mysql tutorialMysql tutorial
Mysql tutorial
 
Spring boot-application
Spring boot-applicationSpring boot-application
Spring boot-application
 
MySQL Shell for DBAs
MySQL Shell for DBAsMySQL Shell for DBAs
MySQL Shell for DBAs
 
Guide - Migrating from Heroku to AWS using CloudFormation
Guide - Migrating from Heroku to AWS using CloudFormationGuide - Migrating from Heroku to AWS using CloudFormation
Guide - Migrating from Heroku to AWS using CloudFormation
 
Sql installation
Sql installationSql installation
Sql installation
 
Mysql tutorial 5257
Mysql tutorial 5257Mysql tutorial 5257
Mysql tutorial 5257
 
Mysqlppt3510
Mysqlppt3510Mysqlppt3510
Mysqlppt3510
 
Mysqlppt3510
Mysqlppt3510Mysqlppt3510
Mysqlppt3510
 
How To Create RDS Database for WordPress in AWS on RHEL 7 or CentOS 7
How To Create RDS Database for WordPress in AWS on RHEL 7 or CentOS 7How To Create RDS Database for WordPress in AWS on RHEL 7 or CentOS 7
How To Create RDS Database for WordPress in AWS on RHEL 7 or CentOS 7
 
My sql basic
My sql basicMy sql basic
My sql basic
 
AWS essentials EC2
AWS essentials EC2AWS essentials EC2
AWS essentials EC2
 
SULTHAN's PHP, MySQL & wordpress
SULTHAN's PHP, MySQL & wordpressSULTHAN's PHP, MySQL & wordpress
SULTHAN's PHP, MySQL & wordpress
 
MySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA ToolMySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA Tool
 
rails.html
rails.htmlrails.html
rails.html
 

More from tutorialsruby

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>tutorialsruby
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 

More from tutorialsruby (20)

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
CSS
CSSCSS
CSS
 
CSS
CSSCSS
CSS
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 

Recently uploaded

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 

Recently uploaded (20)

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 

Accessing MySQL from Ruby in a concise guide

  • 1. Accessing MySQL from Ruby Contents 1. Introduction .................................................................................................................................... 2 2. Prerequisites ................................................................................................................................... 2 3. Setup ............................................................................................................................................... 2 3.1. Populate MySQL Database ...................................................................................................... 2 3.2. Set up ODBC Access ................................................................................................................ 3 4. Discovery ......................................................................................................................................... 4 4.1. Web Service Creation using SOA Gateway ............................................................................. 4 4.2. Accessing the WSDL ................................................................................................................ 6 5. Accessing a Web Service with Ruby ................................................................................................ 8 Ruby Editor.......................................................................................................................................... 8 Ruby Code ........................................................................................................................................... 8 Debugging Code .................................................................................................................................. 9 6. Conclusion ..................................................................................................................................... 10 7. Appendix ....................................................................................................................................... 10 Accessing MySQL from Ruby Author: John O’Mahony, Risaris Ltd
  • 2. 1. Introduction In this tutorial we will show you how to build a Ruby application to access MySQL via the SOA Gateway. 2. Prerequisites It is assumed that you are running the 3 components, MySQL, Ruby and the SOA Gateway on Windows. It is assumed you already have a SOA Gateway server and Control Centre installed. See here for more info about installing the SOA Gateway. 3. Setup Download the latest binaries for Ruby from the Ruby downloads page, install it according to the install.txt document in the Ruby distribution library. For this tutorial I downloaded Ruby 1.8.6 One-Click Installer and followed the default options. You will also need a MySQL database. Again, the Open Source version (known as the MySQL Community Server) can be freely downloaded from the MySQL website. See this link for download, and here to step you through the installation and configuration. 3.1.Populate MySQL Database Now that you’ve got MySQL installed and configured, you will need to populate it with some demo data. For this we use the RisarisBank sample. This is available here.  Save this file to “C:TempRisarisBank.sql”  Connect to the MySQL Server using the mysql command. E.g shell> mysql –u root –p This command connects to the server using the MySQL root account to make sure that you'll have permission to create the RisarisBank database. The -p option tells mysql to prompt you for the root password. Enter the password when prompted. (Remember that the MySQL root account is not the same as the operating system root account and probably will have a different password.)  Create the RisarisBank database. mysql> CREATE DATABASE RisarisBank; mysql> use RisarisBank;  Load the contents of RisarisBank.sql into the RisarisBank database. E.g. mysql> SOURCE c:TempRisarisBank.sql  After the SOURCE command finishes, you can view your new tables. Accessing MySQL from Ruby Author: John O’Mahony, Risaris Ltd
  • 3. mysql> SHOW TABLES; mysql> DESCRIBE CustomerInformation; mysql> DESCRIBE Branch; etc … 3.2.Set up ODBC Access The final thing to do with your MySQL Database is to set up an ODBC DSN which will be used by the SOA Gateway to access this database. Click Start, Control Panel, Administrative Tools, Data Sources (ODBC) From the resulting screen, choose the “System DSN” Tab. Click Add From the list of data source drivers, select “MySQL ODBC 3.51 Driver”. If you do not see this driver in the list, you need to install the MySQL Connector. See here for more information. We recommend installing v3.51. Click Finish, and a window will appear allowing you to enter the DSN information. Add the following: Data Source Name: RisarisBank Description: The Risaris Bank Sample in MySQL Server: localhost User: root Password: *** your MySQL root password *** Database: RisarisBank (select from the drop down list) Accessing MySQL from Ruby Author: John O’Mahony, Risaris Ltd
  • 4. All other options can be left as-is. Click OK. 4. Discovery At this stage you’ve got Ruby installed, and a MySQL database with some sample data in it. In this section we’ll show you how to create web services from each of the MySQL tables. These web services can be used by the Ruby language (and many others) to give you direct real-time access to your MySQL Data. 4.1.Web Service Creation using SOA Gateway Start your SOA Gateway Control Centre. See here for an introduction to the Control Centre. In your servers view, right click the entry which represents your local SOA Gateway Server. Select “Create New Web Services”. Accessing MySQL from Ruby Author: John O’Mahony, Risaris Ltd
  • 5. From the next dialog, choose “MySQL Driver”. If you do not see have a MySQL Driver in the list, see how to create one here. Click Next. The next screen gives you the ability to add information about your DSN Accessing MySQL from Ruby Author: John O’Mahony, Risaris Ltd
  • 6. Enter the above information and click Discover. The wizard will display all the tables it finds at this (RisarisBank) DSN. Click “Select All”, and click “Import”. The wizard will create web services from each one of these tables. You’ve just created 8 Web Services from your 8 MySQL Tables! 4.2.Accessing the WSDL Web Service Description Language (WSDL) is a standard, XML-based language that is used to describe a Web Service. For each of the 8 web services you’ve created in the previous section, the SOA Gateway provides you with a WSDL to describe the Web Service. The WSDL itself is usually interpreted by a web Accessing MySQL from Ruby Author: John O’Mahony, Risaris Ltd
  • 7. service client, such as Ruby, but it is useful to know where to find the WSDL for each of your Web Services. As WSDL is XML-based, it will open in your browser of choice. To see the WSDL for one of your Risaris Bank web services, do the following in your SOA Gateway Control Centre:  Click on the web service you are interested in, for example the “branch” web service.  The properties for this web service should appear in your Properties View. If you do not see the Properties view, select Window -> Show View -> Other -> General -> Properties and click OK.  In the properties view, there is a link to your WSDL. Click it to open the WSDL in a browser. Accessing MySQL from Ruby Author: John O’Mahony, Risaris Ltd
  • 8. You can view the WSDL for the other web services by clicking the link from their properties view. This WSDL is the starting point for using Web Services, and can be used time and again by different web service clients. 5. Accessing a Web Service with Ruby We will use a Ruby script to access our new Risaris Bank Web Services via the WSDL. Those familiar with Ruby will probably want to change the script provided but it can be run with minimum changes described below. The whole script is provided in APPENDIX A. Ruby Editor Use the editor provided, SciTE.exe, which is located in folder scite where you installed Ruby. Copy the code from Appendix A and save the code as the filename RBCustomerTutorial.rb (as in example below). Hit F5 and the results will appear in the right-hand pane: Ruby Code Depending on your MySQL settings you will have to change the username/password provided in the on_simple_outbound method. In this example the user is root with no password. "<UsernameToken><Username>root</Username><Password></Password></UsernameToken>" Accessing MySQL from Ruby Author: John O’Mahony, Risaris Ltd
  • 9. Note also the WSDL URL http://localhost:56000/customerinformation?WSDL. Again depending on your SOA Gateway configuration you may need to change the server/port number. In this example provided we are issuing a list request on the customer information table in the RisarisBank database. The list request can handle a wilcarded customer number key: param = {"CustomerNumber" => "1*"} result = soap.list(param) Finally we can query the result for the customer’s first name: for cust in (result. customerinformationRoot.customerinformationGroup) print(cust.firstName, "n") end Obviously this can be replaced by any of the column names in the customer information table. Debugging Code The code provided should work off the bat. However, depending on your MySQL configuration, the RisarisBank tables may not be in lowercase as in our example e.g. customerinformation versus CustomerInformation. If this is the case the code will not work as is and all occurrences of customerinformation should be replaced by CustomerInformation. The p and puts functions are useful for checking the content of variables. For example p result after the result = soap.list(param) call gives the following information and is useful for checking column names for adding new code. #<SOAP::Mapping::Object:0x3240c04 {}customerinformationRoot=#<SOAP::Mapping::Object:0x3240ad8 {}customerinformationGroup=[#<SOAP::Mapping::Object:0x32409ac {}CustomerNumber="1" {}FirstName="Casper" {}Surname="Ankergren" {}AddressLine1="34 Green Street" {}AddressLine2="Crosses Street" {}City="Mansfield" {}Postcode="MA5 9AJ" {}DateOfBirth="30/05/1978">, #<SOAP::Mapping::Object:0x323f4bc {}CustomerNumber="10" {}FirstName="Grenville" {}Surname="Dekker" {}AddressLine1="22 Uttoxter New Road" {}AddressLine2="Chaddesden" {}City="Leeds" {}Postcode="LS4 9WB" {}DateOfBirth="21/10/1974">, #<SOAP::Mapping::Object:0x323e0b2 {}CustomerNumber="11" {}FirstName="Jane" {}Surname="Freeman" {}AddressLine1="3 Portland Street" {}AddressLine2="Lichfield" {}City="Gloucester" {}Postcode="GL4 8KD" {}DateOfBirth="26/10/1980">, #<SOAP::Mapping::Object:0x323ccb2 {}CustomerNumber="12" {}FirstName="Dale" {}Surname="Rolling" {}AddressLine1="The Hunters Rest" {}AddressLine2="Branston" {}City="Preston" {}Postcode="PR4 4HG" {}DateOfBirth="06/12/1989">, #<SOAP::Mapping::Object:0x323b8b2 {}CustomerNumber="13" {}FirstName="Arnold" {}Surname="Corrigan" {}AddressLine1="14 Anderson Street" {}AddressLine2="Allestree" {}City="Derby" {}Postcode="DE6 8FT" {}DateOfBirth="10/06/1970">, #<SOAP::Mapping::Object:0x323a4b2 {}CustomerNumber="14" {}FirstName="Alfred" {}Surname="Summerscale" {}AddressLine1="3701 S. Accessing MySQL from Ruby Author: John O’Mahony, Risaris Ltd
  • 10. George Mason" {}AddressLine2="Melbourne" {}City="Bath" {}Postcode="BA6 8UU" {}DateOfBirth="07/08/1982">, #<SOAP::Mapping::Object:0x32390b2 {}CustomerNumber="15" {}FirstName="Peter" {}Surname="Spiegel" {}AddressLine1="11663 Charter Oak Co" {}AddressLine2="Foremark" {}City="Manchester" {}Postcode="M98 4GT" {}DateOfBirth="29/12/1971">, #<SOAP::Mapping::Object:0x3237cb2 {}CustomerNumber="16" {}FirstName="John" {}Surname="Sviridov" {}AddressLine1="3319 Rosemere Court" {}AddressLine2="Brailsford" {}City="Leeds" {}Postcode="LS8 5QQ" {}DateOfBirth="12/06/1984">, #<SOAP::Mapping::Object:0x32368b2 {}CustomerNumber="17" {}FirstName="Sarah" {}Surname="Hall" {}AddressLine1="4 Denmark Lane" {}AddressLine2="East Bridgford" {}City="Portsmouth" {}Postcode="PO9 7QN" {}DateOfBirth="12/02/1983">, #<SOAP::Mapping::Object:0x32354b2 {}CustomerNumber="18" {}FirstName="Elspeth" {}Surname="Jones" {}AddressLine1="12375 W. Ohio Circle" {}AddressLine2="Risley" {}City="Birmingham" {}Postcode="B93 1IO" {}DateOfBirth="28/08/1986">, #<SOAP::Mapping::Object:0x32340b2 {}CustomerNumber="19" {}FirstName="Nigel" {}Surname="Wyllis" {}AddressLine1="14 Borough Road" {}AddressLine2="Ockbrook" {}City="Leeds" {}Postcode="LS8 2WL" {}DateOfBirth="29/04/1981">]>> 6. Conclusion This tutorial shows how to access MySQL from Ruby using the SOA Gateway. As you can see, you have built a powerful application that uses Web Services to retrieve information in real-time. 7. Appendix require 'soap/wsdlDriver' require 'soap/header/simplehandler' # A handler to add authentication parameters to the SOAP header. class AutheticationHeaderHandler < SOAP::Header::SimpleHandler @@HEADER_NAME = 'Security' def initialize(namespace) super(XSD::QName.new(namespace, @@HEADER_NAME)) end def on_simple_outbound #Change the username/password below to reflect your own environment "<UsernameToken><Username>root</Username><Password></Password></UsernameTok en>" Accessing MySQL from Ruby Author: John O’Mahony, Risaris Ltd
  • 11. end end wsdl_url = "http://localhost:56000/customerinformation?WSDL" soap = SOAP::WSDLDriverFactory.new(wsdl_url).create_rpc_driver soap.wiredump_file_base = "soapresult" soap.headerhandler << AutheticationHeaderHandler.new("http://www.risaris.com/security") param = {"CustomerNumber" => "1*"} result = soap.list(param) for cust in (result.customerinformationRoot.customerinformationGroup) print(cust.firstName, "n") end Accessing MySQL from Ruby Author: John O’Mahony, Risaris Ltd