Web Development with SQL Anywhere - sqlanywhere-forum.sap… fileRuby Modules • There are two...

27
b l i h SQ h Web Development with SQL Anywhere Eric Farrar Product Manager Product Manager

Transcript of Web Development with SQL Anywhere - sqlanywhere-forum.sap… fileRuby Modules • There are two...

Page 1: Web Development with SQL Anywhere - sqlanywhere-forum.sap… fileRuby Modules • There are two separate Ruby APIs for SQL Anywhere • dbd-sqlanywhere – SQL Anywhere driver for

b l i h SQ hWeb Development with SQL Anywhere

Eric FarrarProduct ManagerProduct Manager

Page 2: Web Development with SQL Anywhere - sqlanywhere-forum.sap… fileRuby Modules • There are two separate Ruby APIs for SQL Anywhere • dbd-sqlanywhere – SQL Anywhere driver for

Outline

• Server‐side Scripting and Web Servers

• Updated PHP Support

• New Ruby Support

• New Python Support

• Rich Internet Application (RIA) Technologies• HTTP Server• HTTP Server

• JSON

• New METHOD typesyp

• PHP Page Processing

• Database‐Hosted Web Applications• Consuming Web Services

• SQL Anywhere Web Edition

Page 3: Web Development with SQL Anywhere - sqlanywhere-forum.sap… fileRuby Modules • There are two separate Ruby APIs for SQL Anywhere • dbd-sqlanywhere – SQL Anywhere driver for

Updated PHP SupportUpdated PHP Support

• PHP support was available in previous versions

• PHP must be installed locally on the server machine

• PHP connectivity is made through PHP libraries that are installed with SQL Anywhere 11Q y

Page 4: Web Development with SQL Anywhere - sqlanywhere-forum.sap… fileRuby Modules • There are two separate Ruby APIs for SQL Anywhere • dbd-sqlanywhere – SQL Anywhere driver for

MySQL PHP API CompatibilityMySQL PHP API Compatibility 

• Previous to version 11, all function calls had the format of sqlanywhere_{function name}

• For version 11, all function calls have format of sasql_{function name}

F i ll h b h d l l h h• Function calls have been changed to closely match the format of the mysqli PHP functions

• Porting a PHP application from MySQL to SQL Anywhere can be mostly accomplished by changing all instances of “mysqli_” to “sasql_”

• Old API still works in version 11, but is deprecated, p

Page 5: Web Development with SQL Anywhere - sqlanywhere-forum.sap… fileRuby Modules • There are two separate Ruby APIs for SQL Anywhere • dbd-sqlanywhere – SQL Anywhere driver for

Getting the PHP DriverGetting the PHP Driver

• Need to install a SQL Anywhere modulesQ y

• Modules are DLLs (Windows) and Shared Objects (‘nix)

• Source code also available to build directly into PHP• Precompiled PHP binaries available in /Bin32• Newest version available from the SQL Anywhere PHP Module pageModule page

• Working to integrate into the PECL (PHP Extension Community Library) package manager

Page 6: Web Development with SQL Anywhere - sqlanywhere-forum.sap… fileRuby Modules • There are two separate Ruby APIs for SQL Anywhere • dbd-sqlanywhere – SQL Anywhere driver for

New Ruby SupportNew Ruby Support

• New support for Ruby

• Ruby must be installed locally on the server machine

• Ruby connectivity is made through Ruby libraries that are available through the Ruby package manager (rubygem)g y p g g ( yg )

Page 7: Web Development with SQL Anywhere - sqlanywhere-forum.sap… fileRuby Modules • There are two separate Ruby APIs for SQL Anywhere • dbd-sqlanywhere – SQL Anywhere driver for

Ruby ModulesRuby Modules

• There are two separate Ruby APIs for SQL Anywhere

• dbd-sqlanywhere– SQL Anywhere driver for the for the popular Ruby/DBI module (based off of Perl DBI)(based off of Perl DBI)

• activerecord-sqlanywhere-adapter– Adapter for the ActiveRecord Object Relational Mapper

– ActiveRecord is the ORM used by Ruby on Rails

• All are available though the RubyGem package manager• gem install dbd-sqlanywhere• gem install activerecord-sqlanywhere-adapter

Page 8: Web Development with SQL Anywhere - sqlanywhere-forum.sap… fileRuby Modules • There are two separate Ruby APIs for SQL Anywhere • dbd-sqlanywhere – SQL Anywhere driver for

New Python SupportNew Python Support

• New support for Python

• Python must be installed locally on the server machine

• Python connectivity is made through Python libraries that are available as Python .eggs through setuptoolsy gg g p

Page 9: Web Development with SQL Anywhere - sqlanywhere-forum.sap… fileRuby Modules • There are two separate Ruby APIs for SQL Anywhere • dbd-sqlanywhere – SQL Anywhere driver for

Python ModulesPython Modules

• SQL Anywhere Python Database API 2.0 driverQ y y• http://code.google.com/p/sqlanydb/

• SQL Anywhere Django Driver// / /• http://code.google.com/p/sqlany‐django

• Both modules are available using the setuptools package managerg p p g g

Page 10: Web Development with SQL Anywhere - sqlanywhere-forum.sap… fileRuby Modules • There are two separate Ruby APIs for SQL Anywhere • dbd-sqlanywhere – SQL Anywhere driver for

Other Server‐Side Scripting EnvironmentsOther Server Side Scripting Environments

• Continued support and updates for

• ASP.NET– New support for ADO.NET 3.5 and Entity Framework (LINQ)

New support for ASPNET Membership and Role Providers– New support for ASP.NET Membership and Role Providers

– New support for ASP.NET 2.0 Providers

– Nhibernate Dialect

• JavaServer Pages and Servlets– iAnywhere JDBC

» Enhanced performance scalability» Enhanced performance scalability

– Hibernate Dialect

• Perl– Rewrite of Perl DBI driver

Page 11: Web Development with SQL Anywhere - sqlanywhere-forum.sap… fileRuby Modules • There are two separate Ruby APIs for SQL Anywhere • dbd-sqlanywhere – SQL Anywhere driver for

Rich Internet TechnologiesRich Internet Technologies

• SQL Anywhere can work with almost all RIA technologies

• Including– Ajax

Adobe Flash/Flex/AIR– Adobe Flash/Flex/AIR

– Microsoft SilverLight

– JavaFX

• Supports many data interchange formats– XML

– HTML– HTML

– Raw Binary

– JSON (new)

Page 12: Web Development with SQL Anywhere - sqlanywhere-forum.sap… fileRuby Modules • There are two separate Ruby APIs for SQL Anywhere • dbd-sqlanywhere – SQL Anywhere driver for

Outline

• Server‐side Scripting and Web Servers

• Updated PHP Support

• New Ruby Support

• Rich Internet Application (RIA) Technologies• HTTP Server

• JSON• JSON

• New METHOD types

• PHP Page Processingg g

• Database‐Hosted Web Applications• Consuming Web Services

• SQL Anywhere Web Edition

Page 13: Web Development with SQL Anywhere - sqlanywhere-forum.sap… fileRuby Modules • There are two separate Ruby APIs for SQL Anywhere • dbd-sqlanywhere – SQL Anywhere driver for

Built‐In HTTP ServerBuilt In HTTP Server

• Introduced in version 9• Integrated into the database engine• Started using the –xs option• Web services are created using CREATE SERVICE command• Allows the database to produce web services• Support return protocols:

• HTTP• DISH• SOAP

• Support return formats:Support return formats:

• XML• HTMLJSON ( )• JSON (new)

Page 14: Web Development with SQL Anywhere - sqlanywhere-forum.sap… fileRuby Modules • There are two separate Ruby APIs for SQL Anywhere • dbd-sqlanywhere – SQL Anywhere driver for

What is JSON?What is JSON?

• JavaScript Object Notation

• Light‐weight data interchange format

• Similar to XML, but less verbose (and less functional)

[{

"Surname": "Whitney","GivenName": "Fran","DepartmentID": 100

CREATE SERVICE "json_test"AUTHORIZATION OFFUSER DBATYPE 'JSON' p

},{

"Surname": "Cobb","GivenName": "Matthew","DepartmentID": 100

AS SELECT TOP 2 Surname, GivenName, DepartmentID

FROM Employees }

]

Employees

Web Service DefinitionResultant JSON string

Page 15: Web Development with SQL Anywhere - sqlanywhere-forum.sap… fileRuby Modules • There are two separate Ruby APIs for SQL Anywhere • dbd-sqlanywhere – SQL Anywhere driver for

Using JSONUsing JSON

• JSON strings are ‘executable’ in JavaScript

• Result Sets returned as array of key/value pairs

• No need to parse XML to exchange data

• JSON support available in almost all languagesJSON support available in almost all languages

var employeeList = eval(“(“ + json text “)”);var employeeList = eval( ( + json_text ) );alert (employeeList[1].Surname);

Page 16: Web Development with SQL Anywhere - sqlanywhere-forum.sap… fileRuby Modules • There are two separate Ruby APIs for SQL Anywhere • dbd-sqlanywhere – SQL Anywhere driver for

HTTP METHODsHTTP METHODs

• SQL Anywhere 11 supports (client and server requests):

• GET

• POST

• PUT (new)

• DELETE (new)

HEAD ( )• HEAD (new)• METHODs accepted are set on a service‐by‐service basis

DECLARE method char(6);SET method = HTTP_HEADER('@HttpMethod');_IF method = 'GET' THEN

…ELSEIF method = 'POST' THEN

…END IF;END IF;

Page 17: Web Development with SQL Anywhere - sqlanywhere-forum.sap… fileRuby Modules • There are two separate Ruby APIs for SQL Anywhere • dbd-sqlanywhere – SQL Anywhere driver for

HTTP FunctionsHTTP Functions

• HTML_ENCODE

• HTML_DECODE

• HTTP_ENCODE

• HTTP DECODEHTTP_DECODE

• HTML_HEADER

• HTTP_BODY (new)

• Returns the body of an HTTP in binary form without doing any character conversions

• Useful for posting image data compressed data etcUseful for posting image data, compressed data, etc

Page 18: Web Development with SQL Anywhere - sqlanywhere-forum.sap… fileRuby Modules • There are two separate Ruby APIs for SQL Anywhere • dbd-sqlanywhere – SQL Anywhere driver for

PHP Page ProcessingPHP Page Processing

• SQL Anywhere 11 allows PHP as an External Stored Procedures

• HTTP Server can process PHP directly

Page 19: Web Development with SQL Anywhere - sqlanywhere-forum.sap… fileRuby Modules • There are two separate Ruby APIs for SQL Anywhere • dbd-sqlanywhere – SQL Anywhere driver for

Creating PHP External Stored ProceduresCreating PHP External Stored Procedures

• Load PHP script into database using INSTALL PHP

INSTALL EXTERNAL OBJECT 'PHPScript‘NEW FROM FILE 'php-file' ENVIRONMENT PHP;

• Create procedure to ‘wrap’ the PHP script

CREATE PROCEDURE SimplePHPDemo( params )CREATE PROCEDURE SimplePHPDemo( params ) EXTERNAL NAME '<file=PHPScript>

PHPFunction( $sa_php_arg0);' LANGUAGE PHP;

Page 20: Web Development with SQL Anywhere - sqlanywhere-forum.sap… fileRuby Modules • There are two separate Ruby APIs for SQL Anywhere • dbd-sqlanywhere – SQL Anywhere driver for

PHP Helper FunctionsPHP Helper Functions

• Two stored procedures exist to run PHP from within SQL Anywhere:

• sa_http_php_page_interpreted(php_page, method, url, version,headers request body )headers, request_body )

• sa_http_php_page(php_page)• The php_page text is a regular long varchar. It can be:_

• read from disk

• read from the database

• etc.

Page 21: Web Development with SQL Anywhere - sqlanywhere-forum.sap… fileRuby Modules • There are two separate Ruby APIs for SQL Anywhere • dbd-sqlanywhere – SQL Anywhere driver for

Database‐Hosted Web ApplicationsDatabase Hosted Web Applications

• SQL Anywhere can host RIA applications

• Application executable can be stored in the database

• Support files (JS, CSS, etc) can also be stored there

• Built‐in HTTP server can serve up the pages

• HTTP Server can respond to web requests from the applicationapplication

• Example

• Offline Web– Can use MobiLink to synchronize both the application and the data

• SQL Anywhere MonitorSQL Anywhere Monitor

Page 22: Web Development with SQL Anywhere - sqlanywhere-forum.sap… fileRuby Modules • There are two separate Ruby APIs for SQL Anywhere • dbd-sqlanywhere – SQL Anywhere driver for

Entire Web Applications in SQL Anywherepp Q y

Page 23: Web Development with SQL Anywhere - sqlanywhere-forum.sap… fileRuby Modules • There are two separate Ruby APIs for SQL Anywhere • dbd-sqlanywhere – SQL Anywhere driver for

OutlineOutline

• Server‐side Scripting and Web Serversp g

• Updated PHP Support

• New Ruby Support

• Rich Internet Application (RIA) Technologies• HTTP Server

• JSON• JSON

• New METHOD types

• PHP Page ProcessingPHP Page Processing

• Database‐Hosted Web Applications• Consuming Web Services

• SQL Anywhere Web Edition

Page 24: Web Development with SQL Anywhere - sqlanywhere-forum.sap… fileRuby Modules • There are two separate Ruby APIs for SQL Anywhere • dbd-sqlanywhere – SQL Anywhere driver for

Using External Web ServicesUsing External Web Services

• SQL Anywhere can not only produce web services, it can also consume them

• Remote Web Service can be wrapped to appear as a regular SQL procedure

CREATE PROCEDURE test() URL 'HTTPS://localhost/myservice' CERTIFICATE 'file=C:\srv_cert.id;co=iAnywhere; unit=SA;name=JohnSmith';

• Sample use cases:

• Hourly database event that retrieves current exchange rate for use with queries

• Use Google Location APIs to determine distance between two addresses in the databasebetween two addresses in the database

Page 25: Web Development with SQL Anywhere - sqlanywhere-forum.sap… fileRuby Modules • There are two separate Ruby APIs for SQL Anywhere • dbd-sqlanywhere – SQL Anywhere driver for

OutlineOutline

• Server‐side Scripting and Web Serversp g

• Updated PHP Support

• New Ruby Support

• Rich Internet Application (RIA) Technologies• HTTP Server

• JSON• JSON

• New METHOD types

• PHP Page ProcessingPHP Page Processing

• Database‐Hosted Web Applications• Consuming Web Services

• SQL Anywhere Web Edition

Page 26: Web Development with SQL Anywhere - sqlanywhere-forum.sap… fileRuby Modules • There are two separate Ruby APIs for SQL Anywhere • dbd-sqlanywhere – SQL Anywhere driver for

SQL Anywhere Web EditionSQL Anywhere Web Edition

• SQL Anywhere Web Edition is a free version of SQL Anywhere available for the development and deployment of web applications 

• Supports Java, ASP.NET, PHP, and more

• May only be used for web browser applicationsy y pp

• No restrictions on database size, cache size, CPUs, optimization techniques, execution strategies, or SQL language support

• Intended to appeal to grass‐roots web developersIntended to appeal to grass roots web developers

Page 27: Web Development with SQL Anywhere - sqlanywhere-forum.sap… fileRuby Modules • There are two separate Ruby APIs for SQL Anywhere • dbd-sqlanywhere – SQL Anywhere driver for