OLE and ODBC: Taming the Technologies The Third Annual Perl Conference, 1999 Sunday, August 22, 1999Roth Consulting ODBC.

Slides:



Advertisements
Similar presentations
Connecting to Databases. connecting to DB DB server typically a standalone application Server runs on localhost for smaller sites –i.e. Same machine as.
Advertisements

Connecting to Databases. relational databases tables and relations accessed using SQL database -specific functionality –transaction processing commit.
Database Connections with ASP.Net
Data Access Worldwide May 16 – 18, 2007 Copyright 2007, Data Access Worldwide May 16 – 18, 2007 Copyright 2007, Data Access Worldwide Standardizing Application.
Fundamentals, Design, and Implementation, 9/e Chapter 12 ODBC, OLE DB, ADO, and ASP.
15 Chapter 15 Web Database Development Database Systems: Design, Implementation, and Management, Fifth Edition, Rob and Coronel.
Fundamentals, Design, and Implementation, 9/e Chapter 11 Managing Databases with SQL Server 2000.
1 - Oracle Server Architecture Overview
Fundamentals, Design, and Implementation, 9/e COS 346 DAY 22.
DT228/3 Web Development Databases. Database Almost all web application on the net access a database e.g. shopping sites, message boards, search engines.
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
How to using MS Access database in Perl/CGI Web Programming Wei Sun.
Database Security and Auditing: Protecting Data Integrity and Accessibility Chapter 3 Administration of Users.
The GUS 3.0 Perl Object Layer CBIL Jonathan Schug June
Today’s Agenda Chapter 12 Admin Tasks Chapter 13 Automating Admin Tasks.
Introducing PHP Data Objects Wez Furlong
ODBC Open DataBase Connectivity a standard database access method developed by Microsoft to access data from any application regardless of which database.
PHP Programming. Topics Background and History of PHP Installation Comments in PHP Variables Conditions Loops Functions File Handling Database Handling.
1 Web Database Processing. Web Database Applications Static Report Publishing a report is prepared from a database application and exported to HTML DB.
PI Data Access via OLE DB/SQL
1 ODBC, OLE DB, ADO, and ASP. 2 Introduction  Because database applications today reside in a complicated environment, various standards have been developed.
4-1 INTERNET DATABASE CONNECTOR Colorado Technical University IT420 Tim Peterson.
Advanced Database Management System Lab no. 11. SQL Commands (for MySQL) –Update –Replace –Delete.
Chapter 7 PHP Interacts with Ms. Access (Open DataBase Connectivity (ODBC))
Java Database Connectivity (JDBC) Introduction to JDBC JDBC is a simple API for connecting from Java applications to multiple databases. Lets you smoothly.
Sayed Ahmed Computer Engineering, BUET, Bangladesh MSC, Computer Science, U of Manitoba, Canada
Database Programming in Java Corresponds with Chapter 32, 33.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Web Server Administration Chapter 7 Installing and Testing a Programming Environment.
© Dennis Shasha, Philippe Bonnet – 2013 Communicating with the Outside.
Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
(Chapter 10 continued) Our examples feature MySQL as the database engine. It's open source and free. It's fully featured. And it's platform independent.
JDBC Java and Databases, including Postgress. JDBC l Developed by Industry leaders l Three main goals: –JDBC should be an SQL-level API –JDBC should capitalize.
Discovering Computers Fundamentals Fifth Edition Chapter 9 Database Management.
JDBC. JDBC stands for Java Data Base Connectivity. JDBC is different from ODBC in that – JDBC is written in Java (hence is platform independent, object.
DATABASE TRANSACTION. Transaction It is a logical unit of work that must succeed or fail in its entirety. A transaction is an atomic operation which may.
1 Chapter Overview Performing Configuration Tasks Setting Up Additional Features Performing Maintenance Tasks.
Improving Database Performance Derrick Rapley
3-Tier Client/Server Internet Example. TIER 1 - User interface and navigation Labeled Tier 1 in the following graphic, this layer comprises the entire.
2010/11 : [1]PHP with MySQLBuilding Web Applications using MySQL and PHP (W1) PHP with MySQL.
Transactions and Locks A Quick Reference and Summary BIT 275.
1 CS 430 Database Theory Winter 2005 Lecture 14: Additional SQL Topics.
Controlling Web Site Access Using Logins CS 320. Basic Approach HTML form a php page that collects the username and password  Sends them to second PHP.
PowerBuilder Online Courses - by Prasad Bodepudi Database Painter Primary & Foreign Keys Extended Attributes PowerBuilder System Tables Database Profiles.
PHP Programming. Topics Database Handling (MySQL, MSSQL, ODBC)
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
5-1 VISUAL J++ Colorado Technical University IT420 Tim Peterson.
Database Connectivity and Server-Side Scripting Chapter 12.
ASP-2-1 SERVER AND CLIENT SIDE SCRITPING Colorado Technical University IT420 Tim Peterson.
CSC 2720 Building Web Applications Accessing MySQL from PHP.
CP476 Internet Computing Perl CGI and MySql 1 Relational Databases –A database is a collection of data organized to allow relatively easy access for retrievals,
A Guide to SQL, Eighth Edition Chapter Six Updating Data.
ECMM6018 Enterprise Networking For Electronic Commerce Tutorial 6 CGI/Perl and databases.
SQL and Java The vision for Java is to be the concrete and nails that people use to build this incredible network system that is happening all around us.
1 ADO Activex Data Objects. 2 ADO ADO allows users to access data easily from many existing databases (such as Access or Paradox) From ODBC compliant.
Oracle Business Intelligence Foundation – Testing and Deploying OBI Repository.
© SCRIBE SOFTWARE CORPORATION 2008 Tips and Tricks for Working with Scribe Insight Trace Files.
JDBC.
Delete Data Database Administration Fundamentals LESSON 3.4.
Data Access with ADO.NET
JDBC Database Management Database connectivity
Stored Procedures.
Chapter 8 Working with Databases and MySQL
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Transactions, Locking and Query Optimisation
Introduction of Week 11 Return assignment 9-1 Collect assignment 10-1
Chapter 10 ADO.
Contents Preface I Introduction Lesson Objectives I-2
Presentation transcript:

OLE and ODBC: Taming the Technologies The Third Annual Perl Conference, 1999 Sunday, August 22, 1999Roth Consulting ODBC

OLE and ODBC: Taming the Technologies (ODBC) 2 Uses SQL Requires ODBC to be installed Win32::ODBC supports access into the ODBC API ODBC: Open DataBase Connectivity

Roth ConsultingOLE and ODBC: Taming the Technologies (ODBC) 3 ODBC Options Perl can access ODBC –Win32::OLE ( OLEDB, ADO ) Memory & processor overhead Not guaranteed to be ODBC or SQL Some bugs yet to be ironed out (eg. SQL Server and multiple text columns) –ODBCTie Is this still maintained? –DBI General DBI rules apply Cross platform –Win32::ODBC Requires Win32 machine

Roth ConsultingOLE and ODBC: Taming the Technologies (ODBC) 4 Who uses Perl and ODBC? Unbelievable amount of Perl and ODBC use –Database maintenance –Administration –Web commerce –Inter/intranet data access Professional Applications –Digital Paper’s Intranet Docs (IDOC) product Partner with Xerox 99% Perl based Can serve up to 2 million documents

Roth ConsultingOLE and ODBC: Taming the Technologies (ODBC) 5 What drivers are installed? Enumerate installed ODBC drivers with: %Drivers = Win32::ODBC::Drivers() –Returns a hash –Hash keys are driver names –Hash value is string with driver specific attributes delimited by semicolons: “ Attrib1=Value1;Attrib2=Value2;Attribn=Valuen ”

Roth ConsultingOLE and ODBC: Taming the Technologies (ODBC) 6 DSN: Data Source Name All database connections begin with a DSN Named database configuration Three types: –User DSN –System DSN –File DSN Win 95/98 only understand User and File When used as a CGI/ASP script with a web server always use System DSN!

Roth ConsultingOLE and ODBC: Taming the Technologies (ODBC) 7 DSN: Data Source Name Create manually using the ODBC control panel applet Create using Win32::ODBC::ConfigDSN() ConfigDSN( $Action, $Driver, $Attrib1, $Attribn ) –Actions ODBC_ADD_DSNAdd new DSN ODBC_MODIFY_DSNModify existing DSN ODBC_REMOVE_DSNRemove existing DSN ODBC_ADD_SYS_DSNAdd new system DSN ODBC_MODIFY_SYS_DSNModify existing system DSN ODBC_REMOVE_SYS_DSNRemove existing system DSN –Driver depends upon installed drivers (keys from Win32::ODBC::Drivers() ): Microsoft Access Driver (*.mdb) II

Roth ConsultingOLE and ODBC: Taming the Technologies (ODBC) 8 DSN: Data Source Name –Attributes are any valid ODBC driver keywords One required keyword: –DSN=Foo Other keywords differ based on ODBC driver Best way to discover keywords is by reading docs or manually creating a DSN then examining the Registry Do not include a “ Driver ” keyword III

Roth ConsultingOLE and ODBC: Taming the Technologies (ODBC) 9 DSN: Data Source Name use Win32::ODBC; # Create a DSN... Win32::ODBC::ConfigDSN( ODBC_ADD_DSN, $Driver, "DSN=My DSN Name", "Description=A Test DSN", "DBQ=c:\\temp\\$MyData.mdb", "DEFAULTDIR= C:\\Database", "UID=Admin", "PWD=Adminpassword" ); IV

Roth ConsultingOLE and ODBC: Taming the Technologies (ODBC) 10 Connecting Create a new Win32::ODBC object: $db = new Win32::ODBC( "My DSN" ); The DSN can either be the name of a DSN or it can be a full connect string: –“ My DSN ” –“ DSN=My DSN;UID=Foo;PWD=Bar ” If the DSN passed in is really a Win32::ODBC object then that object is “cloned” $db2 = new Win32::ODBC( $db ); –$db2 is identical to $db but with different STMT’s –Some database systems do not like such clones

Roth ConsultingOLE and ODBC: Taming the Technologies (ODBC) 11 Executing SQL Statement Submit a text based SQL query $Result = $db->Sql( “SELECT * FROM Foo” ); This is the only method call which returns a non- false value upon failure –Returns error number (ODBC driver specific; not really valuable) –Call $db->Error() for more error details

Roth ConsultingOLE and ODBC: Taming the Technologies (ODBC) 12 Call FetchRow() until it returns false Collect the data with Data() or DataHash() while( $db->FetchRow() ) { my( %Data ) = $db->DataHash(); …process data… } Fetching Results

Roth ConsultingOLE and ODBC: Taming the Technologies (ODBC) 13 Batch Queries If you submitted a batch query or a stored procedure returns multiple result sets repeat the FetchRow() process until MoreResults() returns FALSE. do { while( $db->FetchRow() ) { my( %Data ) = $db->DataHash(); …process data… } } while( $db->MoreResults() );

Roth ConsultingOLE and ODBC: Taming the Technologies (ODBC) 14 Closing The Connection To close the database connection call Close() $db->Close();

Roth ConsultingOLE and ODBC: Taming the Technologies (ODBC) 15 Transactions By default an ODBC connection is in AutoCommit mode –All transactions are committed to the database immediately Turn off AutoCommit mode with: $db->SetConnectOption($db->SQL_AUTOCOMMIT, $db->SQL_AUTOCOMMIT_OFF ); Perform queries (select, insert, delete, update, etc) To commit or rollback call Transact(): $db->Transact( $db->SQL_COMMIT ); $db->Transact( $db->SQL_ROLLBACK );

Roth ConsultingOLE and ODBC: Taming the Technologies (ODBC) 16 Row Counts Report number of rows in the result set with: $db->RowCount(); Not all ODBC drivers support it Some ODBC drivers only support it for insert and delete Alternative is to issue a SQL count query: SELECT Count(*) FROM Foo –The result set is one row and one column containing a value which is the number of rows

Roth ConsultingOLE and ODBC: Taming the Technologies (ODBC) 17 Connection Options You can set and query connection options with: $db->GetConnectOption( $Option ); $db->SetConnectOption( $Option, $Value ); SetConnectOption() returns TRUE if successfully set and FALSE if it failed to set the option GetConnectOption() returns the current value of the specified option. It does not return any errors!

Roth ConsultingOLE and ODBC: Taming the Technologies (ODBC) 18 Connection Option Examples To discover the current qualifier (SQL Server this is the database, in Access it is the.mdb file): $Row = $db->GetConnectOption( $db-> SQL_CURRENT_QUALIFIER ); To change the login timeout value (in seconds): $db->SetConnectOption( $db->SQL_LOGIN_TIMEOUT, 10 ); Query the ODBC trace log file: $db->GetConnectOption($db->SQL_OPT_TRACEFILE ); Set ODBC trace logging to on: $db->SetConnectOption($db->SQL_OPT_TRACE, $db->SQL_OPT_TRACE_ON );

Roth ConsultingOLE and ODBC: Taming the Technologies (ODBC) 19 Special Connect Options Some connection options must be set before the connection to the database is performed Pass these into the new() function: $db = new Win32::ODBC( $Dsn, ODBC::SQL_LOGIN_TIMEOUT => 10, ODBC::SQL_OPT_TRACEFILE => ‘c:\trace.log’, ODBC::SQL_OPT_TRACE => ODBC::SQL_OPT_TRACE_ON );

Roth ConsultingOLE and ODBC: Taming the Technologies (ODBC) 20 Stmt Options Every time you submit a command to the database (such as a query) call it a statement or a stmt (for short) You can set and query options for stmt’s with: $db->GetStmtOption( $Option ); $db->SetStmtOption( $Option, $Value ); SetStmtOption() returns TRUE if successfully set and FALSE if it failed to set the option GetStmtOption() returns the current value of the specified option. It does not return any errors!

Roth ConsultingOLE and ODBC: Taming the Technologies (ODBC) 21 Stmt Option Examples To discover the current row: $Row = $db->GetStmtOption( $db->SQL_ROW_NUMBER ); To change the query timeout value (in seconds): $db->SetStmtOption( $db->SQL_QUERY_TIMEOUT, 10 ); Set the driver to not scan the query for escape clauses: $db->SetStmtOption($db->SQL_NOSCAN, $db->SQL_NOSCAN_ON );

Roth ConsultingOLE and ODBC: Taming the Technologies (ODBC) 22 Programming DBI, by Tim Bunce and Alligator Descartes, O’Reilly & Associates. Win32 Perl Programming: The Standard Extensions, Dave Roth, MacMillan Publishing. Win32 Scripting Journal, The Perl Journal, Other Sources Of Information Programming DBI, by Tim Bunce and Alligator Descartes, O’Reilly & Associates. Win32 Perl Programming: The Standard Extensions, Dave Roth, MacMillan Publishing. Win32 Scripting Journal, The Perl Journal,

Roth ConsultingOLE and ODBC: Taming the Technologies (ODBC) 23