getting the most out of myodbc

Upload: suraj-singh

Post on 10-Apr-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/8/2019 Getting the Most Out of MyODBC

    1/48

    MySQL

    Getting most out of

    Connector/ODBC

    Venu Anuganti

    Developer, MySQL Inc

    MySQL AB 2003

  • 8/8/2019 Getting the Most Out of MyODBC

    2/48

    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

  • 8/8/2019 Getting the Most Out of MyODBC

    3/48

    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 orwith third party tools ?

  • 8/8/2019 Getting the Most Out of MyODBC

    4/48

    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 ?

  • 8/8/2019 Getting the Most Out of MyODBC

    5/48

    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

  • 8/8/2019 Getting the Most Out of MyODBC

    6/48

    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

  • 8/8/2019 Getting the Most Out of MyODBC

    7/48

    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

  • 8/8/2019 Getting the Most Out of MyODBC

    8/48

    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 majorOperating Systems

  • 8/8/2019 Getting the Most Out of MyODBC

    9/48

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

    Basic Connector/ODBC Application Steps

  • 8/8/2019 Getting the Most Out of MyODBC

    10/48

    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

  • 8/8/2019 Getting the Most Out of MyODBC

    11/48

    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

  • 8/8/2019 Getting the Most Out of MyODBC

    12/48

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

    Setting up a DSN on Windows

    ODBC Data Source Administrator

  • 8/8/2019 Getting the Most Out of MyODBC

    13/48

    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

  • 8/8/2019 Getting the Most Out of MyODBC

    14/48

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

    Connector/ODBC Options

    Connector/ODBC 3.51 Connection Options

  • 8/8/2019 Getting the Most Out of MyODBC

    15/48

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

    Connection Options

    What is the need of them ?

  • 8/8/2019 Getting the Most Out of MyODBC

    16/48

    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.

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

    prompt

    32 Enable or disable the dynamic cursor support.

  • 8/8/2019 Getting the Most Out of MyODBC

    17/48

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

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

    128 Force use of ODBC manager cursors (experimental).

    256 Disable the use ofextended fetch (experimental).

    512 Pad CHAR fields to full column length.

    1024SQLDescribeCol() 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

  • 8/8/2019 Getting the Most Out of MyODBC

    18/48

    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).

    32768Return 'user' as Table_qualifier and Table_owner from

    SQLTables (experimental)

    65536Read parameters from the client and odbc groups from

    `my.cnf'

    131072Add some extra safety checks (should not bee needed

    but...)

    262144 Disable transactions

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

    `/tmp/myodbc.sql' file - enabled only in debug mode

  • 8/8/2019 Getting the Most Out of MyODBC

    19/48

    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 onlyfor 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.

  • 8/8/2019 Getting the Most Out of MyODBC

    20/48

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

    Test Data Source

    Connector/ODBC 3.51 Test Data Source

  • 8/8/2019 Getting the Most Out of MyODBC

    21/48

    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

  • 8/8/2019 Getting the Most Out of MyODBC

    22/48

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

    Using ODBCConfig - UnixODBC

    unixODBC ODBCConfig tool

  • 8/8/2019 Getting the Most Out of MyODBC

    23/48

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

    Using ODBCConfig - unixODBC

    unixODBC ODBCConfig DSN Add (Driver Selection)

  • 8/8/2019 Getting the Most Out of MyODBC

    24/48

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

    Using ODBCConfig - unixODBC

    unixODBC ODBCConfig DSN Add (Connector/ODBC setup)

  • 8/8/2019 Getting the Most Out of MyODBC

    25/48

    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

  • 8/8/2019 Getting the Most Out of MyODBC

    26/48

    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=;\

  • 8/8/2019 Getting the Most Out of MyODBC

    27/48

    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

  • 8/8/2019 Getting the Most Out of MyODBC

    28/48

    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

  • 8/8/2019 Getting the Most Out of MyODBC

    29/48

    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

  • 8/8/2019 Getting the Most Out of MyODBC

    30/48

    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 SaveAs Type

    box, click ODBC Databases ()

    Displays ODBC DSN Administrator

    To IMPORT orLINK 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 ()

  • 8/8/2019 Getting the Most Out of MyODBC

    31/48

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

    Issues with MS Access

    Reasons for

    #DELETED

    Write conflict

    Row cant be found for updating/deleting

    Work around

  • 8/8/2019 Getting the Most Out of MyODBC

    32/48

    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 byOpenOffice 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

  • 8/8/2019 Getting the Most Out of MyODBC

    33/48

    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:

  • 8/8/2019 Getting the Most Out of MyODBC

    34/48

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

    OpenOffice Data Source Administration

  • 8/8/2019 Getting the Most Out of MyODBC

    35/48

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

    OpenOffice DSN Connector/ODBC setup

  • 8/8/2019 Getting the Most Out of MyODBC

    36/48

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

    OpenOffice Table(s) selection

  • 8/8/2019 Getting the Most Out of MyODBC

    37/48

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

    OpenOffice Working with Data Sources

  • 8/8/2019 Getting the Most Out of MyODBC

    38/48

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

    OpenOffice Table Management

  • 8/8/2019 Getting the Most Out of MyODBC

    39/48

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

    OpenOffice Table Management options

  • 8/8/2019 Getting the Most Out of MyODBC

    40/48

    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

  • 8/8/2019 Getting the Most Out of MyODBC

    41/48

    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

    SourceMySQL

    ODBC.NET API

    ODBC API

    MySQL C API

  • 8/8/2019 Getting the Most Out of MyODBC

    42/48

    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

  • 8/8/2019 Getting the Most Out of MyODBC

    43/48

    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/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

  • 8/8/2019 Getting the Most Out of MyODBC

    44/48

    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

  • 8/8/2019 Getting the Most Out of MyODBC

    45/48

    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 .

  • 8/8/2019 Getting the Most Out of MyODBC

    46/48

    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

  • 8/8/2019 Getting the Most Out of MyODBC

    47/48

    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

    UnicodeAPIs

    Descriptors

    Array ParameterHandling

    Performance

    Existing majorbugs ( if any ) from 3.51

    Alpha release

  • 8/8/2019 Getting the Most Out of MyODBC

    48/48

    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

    Programmers Reference Manual

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