Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 48

MySQL™

Getting most out of


Connector/ODBC

Venu Anuganti
Developer, MySQL Inc

© MySQL AB 2003
© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

Presentation Goals
• ODBC
– Overview
– Fundamentals
– Architecture

• Connector/ODBC
– Installation
– Connection Options
– Supported and Unsupported Features
– How to use with Microsoft Access
– How to use with Open Office
– How to use in the .NET environment
– Migrating from other Databases
– Current status and TODO
© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

Who are you?


How many of you ...

• Already using the Connector/ODBC 3.51 ?

• Still using the old MyODBC 2.50 ?

• Going to use the ODBC solution in the near future or


with third party tools ?
© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

ODBC Overview

• Open Data Base Connectivity (ODBC)


• Maximum Interoperability
• Language-independent
• Why was ODBC created ?
• What is it actually ?
© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

ODBC and the Standard CLI


• Call Level Interface (CLI)
• X/Open CAE, “Data Management - CLI”
• ISO/IEC, “SQL/CLI”
© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

ODBC Solution
• Requirements
– Access Multiple DBMSs
• using same source code without recompiling and relinking
• Simultaneously
– Which DBMS features should ODBC expose ?
• Common to all DBMSs
• Any feature that is available in any DBMS
• Solves
– It is a Call Level Interface(CLI)
– Defines Standard SQL Grammar
– Driver Manager -> simultaneous access to multiple DBMSs
– Feature Set
© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

ODBC Architecture
Application

ODBC API

Driver Manager
ODBC API

Driver Driver Driver Driver

Data Data Data Data


Source Source Source Source
© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

Connector/ODBC

• Connector/ODBC is a MySQL ODBC Driver

• Also known as MyODBC

• Conforms to ODBC 3.51 specification, level 1


(complete core API + level 2 features)

• Works on all major Operating Systems


© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

Basic Connector/ODBC Application Steps


© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

Installation
• Windows
– From Binary distribution
– From Source

• Unix
– From Source
--with-mysql[-libs/includes]
--with-iodbc[..]
--with-unixODBC[..]
– From Binary distribution
© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

Data Source Name


• What is a Data Source Name (DSN) ?
• Types
– Machine Data Source
• User Data Source
• System Data Source
– File Data Source
• What does Connector/ODBC DSN contain ?
Username (UID) Password (PWD) Server
Database Port Socket
Options Stmt DSN
Description
© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

Setting up a DSN on Windows

ODBC Data Source Administrator


© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

Setting up a DSN on Windows (cont ..)

Connector/ODBC 3.51 DSN Configuration Dialog


© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

Connector/ODBC Options

Connector/ODBC 3.51 Connection Options


© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

Connection Options
• What is the need of them ?
© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

Bit Description
1 Returns the real width of a column.
Returns the true value of affected rows. If this flag is set
2 then MySQL returns 'found rows' instead. One must have
MySQL 3.21.14 or newer to get this to work.
Make a debug log in `c:\myodbc.log'(`/tmp/myodbc.log').
This is the same as putting
4
MYSQL_DEBUG=d:t:O,c::\myodbc.log in
`AUTOEXEC.BAT'
8 Don't set any packet limit for results and parameters.
Don't prompt for questions even if driver would like to
16
prompt
32 Enable or disable the dynamic cursor support.
© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

64 Ignore use of database name in 'database.table.column'.

128 Force use of ODBC manager cursors (experimental).

256 Disable the use of extended fetch (experimental).

512 Pad CHAR fields to full column length.


SQLDescribeCol() will return fully qualified column
1024
names
2048 Use the compressed server/client protocol
Tell server to ignore space after function name and before
4096 '(' (needed by Power Builder). This will make all function
names keywords!
8192 Connect with named pipe
© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

Change LONGLONG columns to INT columns (some


16384
applications can't handle LONGLONG).
Return 'user' as Table_qualifier and Table_owner from
32768
SQLTables (experimental)
Read parameters from the client and odbc groups from
65536
`my.cnf'
Add some extra safety checks (should not bee needed
131072
but...)

262144 Disable transactions

Enable query logging to `c:\myodbc.sql‘ or


524288
`/tmp/myodbc.sql' file - enabled only in debug mode
© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

Do not cache the results locally in the driver, instead


read from server (mysql_use_result). This works only
for forward-only cursors. This option is very important
1048576
in dealing with large tables when one doesn't want the
driver to cache the entire resultset.

Force the use of 'Forward-only' cursor type. In case of


applications setting the deafult static/dynamic cursor
2097152 type, and one wants driver to use non-cache resultsets,
then this option will ensure the forward-only cursor
behaviour.
© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

Test Data Source

Connector/ODBC 3.51 Test Data Source


© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

Configuring DSN on Unix


• Using unixODBC-ODBCConfig
• Using ODBC.INI direct editing
© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

Using ODBCConfig - UnixODBC

unixODBC ODBCConfig tool


© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

Using ODBCConfig - unixODBC

unixODBC ODBCConfig – DSN Add (Driver Selection)


© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

Using ODBCConfig - unixODBC

unixODBC ODBCConfig – DSN Add (Connector/ODBC setup)


© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

Configuring DSN on Unix (cont ..)

• ODBC.INI
[myodbc3-test]
Driver = /usr/local/lib/libmyodbc3.so
Description = Connector/ODBC 3.51 Driver DSN
SERVER = localhost
PORT =
USER = root
Password =
Database = test
OPTION =3
SOCKET =
• ODBCINI and ODBCSYSDIR
© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

Without Predefined DSN


• Odbcinst.ini
ConnectionString = “
DRIVER={MySQL ODBC 3.51 Driver}; \
SERVER=localhost; \
Port=3306; \
DATABASE=test; \
USER=venu; \
PASSWORD=venu; \
OPTION=3; \
SOCKET=/tmp/mysql.sock; \
STMT=;\
© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

Remote Connection
• Setup DSN with the server name pointing to the
hostname that you want to connect

• Next GRANT the privileges for the user from which


he is connecting using GRANT
– Grant *.* to user@hostname [IDENTIFIED BY passwod]..

• Establish a connection
© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

Connector/ODBC with MS Access


• Using MS Access as a Front end
• Install Latest MDAC and Microsoft Jet
• Alternatives

– WinSQL (http://www.indussoft.com/)
– Open Offfice (http://www.openoffice.org/)
– Microsoft Visual Database Project
© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

Export/Import/Linking of tables from


Access
• What is a Linked Table ?
• In the Database window click the name of the table or query you want to
export, and then on the File menu, click Export
© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

• In the Export Object Type 'Object name' To dialog box, in the Save As Type
box, click ODBC Databases ()

• Displays ODBC DSN Administrator

• To IMPORT or LINK Table(s):


– On the File menu, point to Get External Data, and then click Import/Link
Tables
– In the files of type box, select ODBC Databases ()
© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

Issues with MS Access

• Reasons for

– #DELETED
– Write conflict
– Row can’t be found for updating/deleting

• Work around
© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

Connector/ODBC with OpenOffice


• OpenOffice 1.1 Beta supports MySQL directly as an
built-in entity using ‘ODBC’ layer.

• Connector/ODBC recent versions are pre-tested by


OpenOffice team before the releases

• Platform independent tool to manage tables and its data


along with pass-through query execution

• Difference between Microsoft Access and OpenOffice


© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

Using OpenOffice with Connector/ODBC

• Install latest versions of


– OpenOffice (1.1 Beta currently)
– Connector/ODBC 3.51 Driver (3.51.06 currently)
– MySQL Server (3.23.56)

• Create Connector/ODBC DSN, ‘myodbc3-test’

• Setup Connector/ODBC DSN, ‘myodbc3-test’ within OpenOffice


– Select Tools -> Data Sources options from the Main menu
– Opens Data Source Administration, as shown below:
© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

OpenOffice – Data Source Administration


© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

OpenOffice – DSN – Connector/ODBC setup


© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

OpenOffice – Table(s) selection


© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

OpenOffice – Working with Data Sources


© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

OpenOffice – Table Management


© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

OpenOffice – Table Management options


© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

Connector/ODBC with .NET


• ODBC.NET Provider
– Add-in component to the Microsoft.NET Framework
– Directly accesses native ODBC drivers

• Setup
– Microsoft .NET Framework SDK
– MDAC 2.6 or later (2.7 is recommended)
– ODBC.NET Provider (Microsoft.Data.Odbc name space)
• Installed to “C:\Program
Files\Microsoft.NET\Odbc.Net”
© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

ODBC.NET Architecture
ODBC.NET Application

ODBC.NET API

ODBC.NET Provider
ODBC API

Driver Driver Connector/ODBC


MySQL C API

Data Data
MySQL
Source Source
© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

Developing ODBC.NET Applications


Main classes
OdbcCommand OdbcInfoMessageEventArgs
OdbcCommandBuilder OdbcParameter
OdbcConnection OdbcParameterCollection
OdbcDataAdapter OdbcPermission
OdbcDataReader OdbcPermissionAttribute
OdbcError OdbcRowUpdatedEventArgs
OdbcErrrorCollection OdbcRowUpdatingEventArgs
OdbcException OdbcTransaction

Enumeration Type OdbcType

Ref: ODBC.NET Data Provider Reference Document


© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

Developing ODBC.NET Applications (cont ..)

• First, import the ODBC.NET namespace


Imports Microsoft.Data.Odbc ( VB.net )
using Microsoft.Data.Odbc (C# )

• Connect to MySQL server by loading Connector/ODBC


String myconStr= “DSN=myodbc3-test;…”
OdbcConnection myOdbcCon= new OdbcConnection(myConStr)
myOdbcCon.open()

• Complete article on ‘Exploring MySQL in the .NET


environment” can be found from here:
http://www.mysql.com/articles/dotnet
© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

Migrating
• MS Access
• MS Data Transformation Services (DTS)
• Export to plain SQL
© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

Products that works with Connector/ODBC


• All noted ODBC compliant Tools and Applications

MS Access OpenOffice Delphi


CTD ColdFusion Crystal Reports
Erwin MS Office tools FileMaker Pro
FoxPro Notes 4.5/4.6 MS Visio Enterprise
Vision Visual Objects Visual Interdev
Perl DBD-ODBC ParaDox PowerBuilder
PowerDesigner ODBC.NET SQLExpress
StarOffice Samba Server ….
© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

ODBC Programming Hints


• Direct linking with the driver will drastically increase the
performance by a factor of ~40-50%

• Do not use the debug version of the driver DLL

• Turn off all ODBC and Connector/ODBC loggers

• Avoid using ODBC API calls that works on prepared


results instead use it on execute call
© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

Connector/ODBC 3.52
• ODBC Specification 3.51/3.52
• MySQL 4.1 Binary Protocol compatible
• Unicode APIs
• Descriptors
• Array Parameter Handling
• Performance
• Existing major bugs ( if any ) from 3.51
• Alpha release
© MySQL AB 2003 | Venu Anuganti | www.mysql.com
MySQL™: Getting most out of Connector/ODBC

Questions ?
• Mailing list:
myodbc@lists.mysql.com

• List Archives:
http://lists.mysql.com/

• Frequently Asked Questions


http://www.mysql.com/products/myodbc/faq_toc.html

• Programmer’s Reference Manual


http://www.mysql.com/products/myodbc/manual_toc.html

You might also like