SlideShare a Scribd company logo
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 Connectors
rtretola
 
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
Abdoulaye M Yansane
 
WebLogic FAQs
WebLogic FAQsWebLogic FAQs
WebLogic FAQs
Amit Sharma
 
Nick harris-sic-2011
Nick harris-sic-2011Nick harris-sic-2011
Nick harris-sic-2011
Seattle Interactive Conference
 
Session And Cookies In Servlets - Java
Session And Cookies In Servlets - JavaSession And Cookies In Servlets - Java
Session And Cookies In Servlets - Java
JainamParikh3
 
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
 
JAX-WS Basics
JAX-WS BasicsJAX-WS Basics
JAX-WS Basics
Wes Williams
 
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
Karl-Henry Martinsson
 
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
Karl-Henry Martinsson
 
AD102 - Break out of the Box
AD102 - Break out of the BoxAD102 - Break out of the Box
AD102 - Break out of the Box
Karl-Henry Martinsson
 
11-DWR-and-JQuery
11-DWR-and-JQuery11-DWR-and-JQuery
11-DWR-and-JQuery
tutorialsruby
 
Dwr
DwrDwr
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 jagtap
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
IndicThreads
 

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

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

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

Accessing my sql_from_java
Accessing my sql_from_javaAccessing my sql_from_java
Accessing my sql_from_java
Tran Rean
 
Introduction to MySQL - Part 1
Introduction to MySQL - Part 1Introduction to MySQL - Part 1
Introduction to MySQL - Part 1
webhostingguy
 
Introduction to MySQL - Part 1
Introduction to MySQL - Part 1Introduction to MySQL - Part 1
Introduction to MySQL - Part 1
webhostingguy
 
Introduction to MySQL - Part 1
Introduction to MySQL - Part 1Introduction to MySQL - Part 1
Introduction to MySQL - Part 1
webhostingguy
 
Introduction to MySQL - Part 1
Introduction to MySQL - Part 1Introduction to MySQL - Part 1
Introduction to MySQL - Part 1
webhostingguy
 
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
YUCHENG HU
 
Mysql tutorial
Mysql tutorialMysql tutorial
Mysql tutorial
Pankaj Sipl
 
Spring boot-application
Spring boot-applicationSpring boot-application
Spring boot-application
Parag Patil
 
MySQL Shell for DBAs
MySQL Shell for DBAsMySQL Shell for DBAs
MySQL Shell for DBAs
Frederic Descamps
 
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
Rob Linton
 
Sql installation
Sql installationSql installation
Sql installation
Balakumaran Arunachalam
 
Mysql tutorial 5257
Mysql tutorial 5257Mysql tutorial 5257
Mysql tutorial 5257
Phuong Do Anh
 
Mysqlppt3510
Mysqlppt3510Mysqlppt3510
Mysqlppt3510
Anuja Lad
 
Mysqlppt3510
Mysqlppt3510Mysqlppt3510
Mysqlppt3510
Khan Rahimeen
 
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
VCP Muthukrishna
 
My sql basic
My sql basicMy sql basic
My sql basic
Prabhat gangwar
 
AWS essentials EC2
AWS essentials EC2AWS essentials EC2
AWS essentials EC2
mustafa sarac
 
SULTHAN's PHP, MySQL & wordpress
SULTHAN's PHP, MySQL & wordpressSULTHAN's PHP, MySQL & wordpress
SULTHAN's PHP, MySQL & wordpress
SULTHAN 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 Tool
Miguel Araújo
 
rails.html
rails.htmlrails.html
rails.html
tutorialsruby
 

Similar to Accessing_MySQL_from_Ruby (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 – INS0
tutorialsruby
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
tutorialsruby
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
tutorialsruby
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
tutorialsruby
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
tutorialsruby
 
CSS
CSSCSS
CSS
CSSCSS
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
tutorialsruby
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
tutorialsruby
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
tutorialsruby
 

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

20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Zilliz
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 

Recently uploaded (20)

20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 

Accessing_MySQL_from_Ruby

  • 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