MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

48
MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003

Transcript of MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

Page 1: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

MySQL™

Getting most out of Connector/ODBC

Venu Anuganti Developer, MySQL Inc

© MySQL AB 2003

Page 2: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

© MySQL AB 2003 | Venu Anuganti | www.mysql.comMySQL™: 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

Page 3: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

© MySQL AB 2003 | Venu Anuganti | www.mysql.comMySQL™: 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 ?

Page 4: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

© MySQL AB 2003 | Venu Anuganti | www.mysql.comMySQL™: 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 ?

Page 5: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

© MySQL AB 2003 | Venu Anuganti | www.mysql.comMySQL™: 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”

Page 6: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

© MySQL AB 2003 | Venu Anuganti | www.mysql.comMySQL™: 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

Page 7: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

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

ODBC Architecture

Application

Driver Manager

Driver Driver Driver Driver

Data Source

Data Source

Data Source

Data Source

ODBC API

ODBC API

Page 8: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

© MySQL AB 2003 | Venu Anuganti | www.mysql.comMySQL™: 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

Page 9: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

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

Basic Connector/ODBC Application Steps

Page 10: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

© MySQL AB 2003 | Venu Anuganti | www.mysql.comMySQL™: 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

Page 11: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

© MySQL AB 2003 | Venu Anuganti | www.mysql.comMySQL™: 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

Page 12: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

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

Setting up a DSN on Windows

ODBC Data Source Administrator

Page 13: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

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

Setting up a DSN on Windows (cont ..)

Connector/ODBC 3.51 DSN Configuration Dialog

Page 14: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

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

Connector/ODBC Options

Connector/ODBC 3.51 Connection Options

Page 15: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

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

Connection Options

• What is the need of them ?

Page 16: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

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

Bit Description

1 Returns the real width of a column.

2 Returns the true value of affected rows. If this flag is set

then MySQL returns 'found rows' instead. One must have MySQL 3.21.14 or newer to get this to work.

4 Make a debug log in `c:\myodbc.log'(`/tmp/myodbc.log').

This is the same as putting MYSQL_DEBUG=d:t:O,c::\myodbc.log in `AUTOEXEC.BAT'

8 Don't set any packet limit for results and parameters.

16 Don't prompt for questions even if driver would like to

prompt

32 Enable or disable the dynamic cursor support.

Page 17: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

© MySQL AB 2003 | Venu Anuganti | www.mysql.comMySQL™: 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.

1024 SQLDescribeCol() will return fully qualified column names

2048 Use the compressed server/client protocol

4096 Tell server to ignore space after function name and before '(' (needed by Power Builder). This will make all function names keywords!

8192 Connect with named pipe

Page 18: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

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

16384 Change LONGLONG columns to INT columns (some applications can't handle LONGLONG).

32768 Return 'user' as Table_qualifier and Table_owner from SQLTables (experimental)

65536 Read parameters from the client and odbc groups from `my.cnf'

131072 Add some extra safety checks (should not bee needed but...)

262144 Disable transactions

524288 Enable query logging to `c:\myodbc.sql‘ or `/tmp/myodbc.sql' file - enabled only in debug mode

Page 19: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

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

1048576

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 in dealing with large tables when one doesn't want the driver to cache the entire resultset.

2097152

Force the use of 'Forward-only' cursor type. In case of applications setting the deafult static/dynamic cursor type, and one wants driver to use non-cache resultsets, then this option will ensure the forward-only cursor behaviour.

Page 20: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

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

Test Data Source

Connector/ODBC 3.51 Test Data Source

Page 21: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

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

Configuring DSN on Unix

• Using unixODBC-ODBCConfig• Using ODBC.INI direct editing

Page 22: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

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

Using ODBCConfig - UnixODBC

unixODBC ODBCConfig tool

Page 23: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

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

Using ODBCConfig - unixODBC

unixODBC ODBCConfig – DSN Add (Driver Selection)

Page 24: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

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

Using ODBCConfig - unixODBC

unixODBC ODBCConfig – DSN Add (Connector/ODBC setup)

Page 25: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

© MySQL AB 2003 | Venu Anuganti | www.mysql.comMySQL™: 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

Page 26: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

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

Without Predefined DSN

• Odbcinst.iniConnectionString = “

DRIVER={MySQL ODBC 3.51 Driver}; \

SERVER=localhost; \

Port=3306; \

DATABASE=test; \

USER=venu; \

PASSWORD=venu; \

OPTION=3; \

SOCKET=/tmp/mysql.sock; \

STMT=;\

Page 27: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

© MySQL AB 2003 | Venu Anuganti | www.mysql.comMySQL™: 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

Page 28: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

© MySQL AB 2003 | Venu Anuganti | www.mysql.comMySQL™: 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

Page 29: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

© MySQL AB 2003 | Venu Anuganti | www.mysql.comMySQL™: 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

Page 30: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

© MySQL AB 2003 | Venu Anuganti | www.mysql.comMySQL™: 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 ()

Page 31: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

© MySQL AB 2003 | Venu Anuganti | www.mysql.comMySQL™: 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

Page 32: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

© MySQL AB 2003 | Venu Anuganti | www.mysql.comMySQL™: 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

Page 33: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

© MySQL AB 2003 | Venu Anuganti | www.mysql.comMySQL™: 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:

Page 34: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

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

OpenOffice – Data Source Administration

Page 35: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

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

OpenOffice – DSN – Connector/ODBC setup

Page 36: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

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

OpenOffice – Table(s) selection

Page 37: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

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

OpenOffice – Working with Data Sources

Page 38: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

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

OpenOffice – Table Management

Page 39: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

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

OpenOffice – Table Management options

Page 40: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

© MySQL AB 2003 | Venu Anuganti | www.mysql.comMySQL™: 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”

Page 41: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

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

ODBC.NET Architecture

ODBC.NET Application

ODBC.NET Provider

Driver Driver Connector/ODBC

Data Source

Data Source

MySQL

ODBC.NET API

ODBC API

MySQL C API

Page 42: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

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

Developing ODBC.NET Applications

OdbcCommand OdbcInfoMessageEventArgs

OdbcCommandBuilder OdbcParameter

OdbcConnection OdbcParameterCollection

OdbcDataAdapter OdbcPermission

OdbcDataReader OdbcPermissionAttribute

OdbcError OdbcRowUpdatedEventArgs

OdbcErrrorCollection OdbcRowUpdatingEventArgs

OdbcException OdbcTransaction

Main classes

Enumeration Type OdbcType

Ref: ODBC.NET Data Provider Reference Document

Page 43: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

© MySQL AB 2003 | Venu Anuganti | www.mysql.comMySQL™: 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/ODBCString 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

Page 44: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

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

Migrating

• MS Access• MS Data Transformation Services (DTS)• Export to plain SQL

Page 45: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

© MySQL AB 2003 | Venu Anuganti | www.mysql.comMySQL™: 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 ….

Page 46: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

© MySQL AB 2003 | Venu Anuganti | www.mysql.comMySQL™: 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

Page 47: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

© MySQL AB 2003 | Venu Anuganti | www.mysql.comMySQL™: 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

Page 48: MySQL™ Getting most out of Connector/ODBC Venu Anuganti Developer, MySQL Inc © MySQL AB 2003.

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

Questions ?

• Mailing list:

[email protected]

• 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