Posts Tagged ‘Connector/NET’

  1. Hello, Connector/NET(ClojureCLR) World!

    Posted on 4月 15th, 2013 by cx20

    Connector/NET(ClojureCLR)

    Connector/NET は、.NET ベースの MySQL 接続用 API である。
    以下は ClojureCLR による Connector/NET ライブラリを使用した MySQL への接続例となっている。

    ソースコード(ClojureCLR + Connector/NET + MySQL)

    (System.Reflection.Assembly/LoadWithPartialName "System.Data")
    (System.Reflection.Assembly/LoadWithPartialName "MySql.Data")
     
    (import '(MySql.Data.MySqlClient MySqlConnection))
    (import '(MySql.Data.MySqlClient MySqlCommand))
    (import '(MySql.Data.MySqlClient MySqlDataReader))
     
    (def conStr "server=localhost;user id=root;password=P@ssW0rd")
    (def sqlStr "SELECT 'Hello, Connector/NET World!' AS Message")
    (def con (MySqlConnection. conStr))
    (def cmd (MySqlCommand. sqlStr con))
    (.Open con)
    (def reader (.ExecuteReader cmd))
    (if (.Read reader)
        (do
            (System.Console/WriteLine (.GetName reader 0))
            (System.Console/WriteLine "---------------------")
            (System.Console/WriteLine (.GetValue reader 0))
        )
    )
    (.Close reader)
    (.Close con)

    コンパイル方法

    C:¥> Clojure.Main hello.clj

    実行結果

    MESSAGE
    ---------------------
    Hello, Connector/NET World!
  2. Hello, Connector/NET(IronScheme) World!

    Posted on 4月 14th, 2013 by cx20

    Connector/NET(IronScheme)

    Connector/NET は、.NET ベースの MySQL 接続用 API である。
    以下は IronScheme による Connector/NET ライブラリを使用した MySQL への接続例となっている。

    ソースコード(IronRuby + Connector/NET + MySQL)

    (import
        (rnrs)
        (ironscheme clr)
    )
     
    (clr-reference System)
    (clr-reference System.Data)
    (clr-reference MySql.Data)
     
    (clr-using System)
    (clr-using MySql.Data.MySqlClient)
     
    (begin
        (define conStr "server=localhost;user id=root;password=P@ssW0rd")
        (define sqlStr "SELECT 'Hello, Connector/NET World!' AS Message")
        (define con (clr-new MySqlConnection conStr))
        (define cmd (clr-new MySqlCommand sqlStr con))
        (clr-call MySqlConnection Open con)
        (define reader (clr-call MySqlCommand ExecuteReader cmd))
        (if (clr-call MySqlDataReader Read reader)
            (begin
                (clr-static-call System.Console WriteLine (clr-call MySqlDataReader GetName reader 0))
                (clr-static-call System.Console WriteLine "---------------------")
                (clr-static-call System.Console WriteLine (clr-call MySqlDataReader GetValue reader 0))
            )
        )
        (clr-call MySqlDataReader Close reader)
        (clr-call MySqlConnection Close con)
    )

    実行方法

    C:¥> isc Hello.ss

    実行結果

    MESSAGE
    ---------------------
    Hello, Connector/NET World!
  3. Hello, Connector/NET(Oxygene) World!

    Posted on 4月 13th, 2013 by cx20

    Connector/NET(Oxygene)

    Connector/NET は、.NET ベースの MySQL 接続用 API である。
    以下は Oxygene による Connector/NET ライブラリを使用した MySQL への接続例となっている。

    ソースコード(Oxygene + Connector/NET + MySQL)

    namespace hello;
     
    interface
    uses
        System,
        MySql.Data.MySqlClient;
     
    type
        Hello = class
    public
        class method Main(args: array of String): Integer;
    end;
     
    implementation
     
    class method Hello.Main(args: array of String): Integer;
    var
        conStr: String;
        sqlStr: String;
        con: MySqlConnection;
        cmd: MySqlCommand;
        reader: MySqlDataReader;
    begin
        conStr := "server=localhost;user id=root;password=P@ssW0rd";
        sqlStr := "SELECT 'Hello, Connector/NET World!' AS Message";
        con := new MySqlConnection(conStr);
        cmd := new MySqlCommand(sqlStr, con);
        con.Open();
        reader := cmd.ExecuteReader();
        while reader.Read() do begin
            System.Console.WriteLine( reader.GetName(0) );
            System.Console.WriteLine( "---------------------" );
            System.Console.WriteLine( reader[0] );
        end;
        reader.Close();
        con.Close();
    end;
     
    end.

    コンパイル方法

    C:¥> oxygene Hello.pas ^
           -type:exe -cputype:x86 ^
           -ref:System.dll;System.Data.dll;MySql.Data.dll

    実行結果

    MESSAGE
    ---------------------
    Hello, Connector/NET World!
  4. Hello, Connector/NET(Nemerle) World!

    Posted on 4月 12th, 2013 by cx20

    Connector/NET(Nemerle)

    Connector/NET は、.NET ベースの MySQL 接続用 API である。
    以下は Nemerle による Connector/NET ライブラリを使用した MySQL への接続例となっている。

    ソースコード(Nemerle + Connector/NET + MySQL)

    using System;
    using MySql.Data.MySqlClient;
     
    class Hello
    {
        public static Main() : void {
            def conStr = "server=localhost;user id=root;password=P@ssW0rd";
            def sqlStr = "SELECT 'Hello, Connector/NET World!' AS Message";
     
            def con = MySqlConnection(conStr);
            def cmd = MySqlCommand(sqlStr, con);
            con.Open();
            def reader = cmd.ExecuteReader();
            while( reader.Read() )
            {
                Console.WriteLine( reader.GetName(0) );
                Console.WriteLine( "---------------------" );
                Console.WriteLine( reader[0] );
            }
            reader.Close();
            con.Close();
        }
    }

    コンパイル方法

    C:¥> ncc -o Hello.exe -r:MySql.Data Hello.n

    実行結果

    MESSAGE
    ---------------------
    Hello, Connector/NET World!
  5. Hello, Connector/NET(Boo) World!

    Posted on 4月 11th, 2013 by cx20

    Connector/NET(Boo)

    Connector/NET は、.NET ベースの MySQL 接続用 API である。
    以下は Boo による Connector/NET ライブラリを使用した MySQL への接続例となっている。

    ソースコード(Boo + Connector/NET + MySQL)

    import System
    import MySql.Data.MySqlClient
     
    [STAThread]
    def Main(argv as (string)):
        conStr = "server=localhost;user id=root;password=P@ssW0rd"
        sqlStr = "SELECT 'Hello, Connector/NET World!' AS Message"
     
        con = MySqlConnection(conStr)
        cmd = MySqlCommand(sqlStr, con)
        con.Open()
     
        reader = cmd.ExecuteReader()
        while reader.Read():
            Console.WriteLine( reader.GetName(0) )
            Console.WriteLine( "---------------------" )
            Console.WriteLine( reader.GetValue(0) )
     
        reader.Close()
        con.Close()

    コンパイル方法

    C:¥> booc Hello.boo

    実行結果

    MESSAGE
    ---------------------
    Hello, Connector/NET World!
  6. Hello, Connector/NET(Cobra) World!

    Posted on 4月 10th, 2013 by cx20

    Connector/NET(Cobra)

    Connector/NET は、.NET ベースの MySQL 接続用 API である。
    以下は Cobra による Connector/NET ライブラリを使用した MySQL への接続例となっている。

    ソースコード(Cobra + Connector/NET + MySQL)

    use System
    use System.Data
    use MySql.Data.MySqlClient
     
    class Program
        def main is shared
            conStr = "server=localhost;user id=root;password=P@ssW0rd"
            sqlStr = "SELECT 'Hello, Connector/NET World!' AS Message"
     
            con = MySqlConnection(conStr)
            cmd = MySqlCommand(sqlStr, con)
            con.open()
     
            reader = cmd.executeReader()
            while reader.read()
                Console.writeLine( reader.getName(0) )
                Console.writeLine( "---------------------" )
                Console.writeLine( reader.getValue(0) )
     
            reader.close()
            con.close()

    コンパイル方法

    C:¥> cobra -compile Hello.cobra

    実行結果

    MESSAGE
    ---------------------
    Hello, Connector/NET World!
  7. Hello, Connector/NET(Phalanger) World!

    Posted on 4月 9th, 2013 by cx20

    Connector/NET(Phalanger)

    Connector/NET は、.NET ベースの MySQL 接続用 API である。
    以下は Phalanger による Connector/NET ライブラリを使用した MySQL への接続例となっている。

    ソースコード(Phalanger + Connector/NET + MySQL)

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <phpNet>
            <classLibrary>
                <add assembly="mscorlib" />
                <add assembly="System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
                <add assembly="System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
                <add assembly="MySql.Data, Version=6.5.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
            </classLibrary>
        </phpNet>
    </configuration>
    <?
    use System;
    use MySqlDataMySqlClient;
     
    class Hello
    {
        static function Main()
        {
            $conStr = "server=localhost;user id=root;password=P@ssW0rd";
            $sqlStr = "SELECT 'Hello, Connector/NET World!' AS Message";
     
            $con = new MySqlDataMySqlClientMySqlConnection($conStr);
            $cmd = new MySqlDataMySqlClientMySqlCommand($sqlStr, $con);
            $con->Open();
            $reader = $cmd->ExecuteReader();
            while ($reader->Read())
            {
                SystemConsole::WriteLine( $reader->GetName(0) );
                SystemConsole::WriteLine( "---------------------" );
                SystemConsole::WriteLine( $reader->GetValue(0) );
            }
            $reader->Close();
            $con->Close();
        }
    }
    ?>

    コンパイル方法

    C:¥> phpc /pure Hello.php

    実行結果

    MESSAGE
    ---------------------
    Hello, Connector/NET World!
  8. Hello, Connector/NET(IronRuby) World!

    Posted on 4月 8th, 2013 by cx20

    Connector/NET(IronRuby)

    Connector/NET は、.NET ベースの MySQL 接続用 API である。
    以下は IronRuby による Connector/NET ライブラリを使用した MySQL への接続例となっている。

    ソースコード(IronRuby + Connector/NET + MySQL)

    require 'mscorlib'
    require 'System'
    require 'MySql.Data'
    include System
    include MySql::Data::MySqlClient
     
    conStr = "server=localhost;user id=root;password=P@ssW0rd"
    sqlStr = "SELECT 'Hello, Connector/NET World!' AS Message"
     
    con = MySqlConnection.new(conStr)
    cmd = MySqlCommand.new(sqlStr, con)
    con.Open()
     
    reader = cmd.ExecuteReader()
    while reader.Read() do
        Console.WriteLine( reader.GetName(0) )
        Console.WriteLine( "---------------------" )
        Console.WriteLine( reader.GetValue(0) )
    end
     
    reader.Close()
    con.Close()

    実行方法

    C:¥> ir Hello.rb

    実行結果

    MESSAGE
    ---------------------
    Hello, Connector/NET World!
  9. Hello, Connector/NET(IronPython) World!

    Posted on 4月 7th, 2013 by cx20

    Connector/NET(IronPython)

    Connector/NET は、.NET ベースの MySQL 接続用 API である。
    以下は IronPython による Connector/NET ライブラリを使用した MySQL への接続例となっている。

    ソースコード(IronPython + Connector/NET + MySQL)

    import clr
    clr.AddReference("System.Data")
    clr.AddReference("MySql.Data")
    from System import *
    from MySql.Data.MySqlClient import *
     
    conStr = "server=localhost;user id=root;password=P@ssW0rd"
    sqlStr = "SELECT 'Hello, Connector/NET World!' AS Message"
     
    con = MySqlConnection(conStr)
    cmd = MySqlCommand(sqlStr, con)
    con.Open()
     
    reader = cmd.ExecuteReader()
    while reader.Read():
        Console.WriteLine( reader.GetName(0) )
        Console.WriteLine( "---------------------" )
        Console.WriteLine( reader.GetValue(0) )
     
    reader.Close()
    con.Close()

    実行方法

    C:¥> ipy Hello.py

    実行結果

    MESSAGE
    ---------------------
    Hello, Connector/NET World!
  10. Hello, Connector/NET(PowerShell) World!

    Posted on 4月 6th, 2013 by cx20

    Connector/NET(PowerShell)

    Connector/NET は、.NET ベースの MySQL 接続用 API である。
    以下は PowerShell による Connector/NET ライブラリを使用した MySQL への接続例となっている。

    ソースコード(PowerShell + Connector/NET + MySQL)

    [void][Reflection.Assembly]::LoadWithPartialName("MySql.Data")
    $conStr = "server=localhost;user id=root;password=P@ssW0rd"
    $sqlStr = "SELECT 'Hello, Connector/NET World!' AS Message"
    $con = New-Object MySql.Data.MySqlClient.MySqlConnection($conStr)
    $cmd = New-Object MySql.Data.MySqlClient.MySqlCommand($sqlStr, $con)
    $con.Open()
    $reader = $cmd.ExecuteReader()
    while ( $reader.read() )
    {
        $reader.getName(0)
        "---------------------"
        $reader[0]
    }
    $con.Close()

    実行方法

    C:¥> powershell -file Hello.ps1

    実行結果

    MESSAGE
    ---------------------
    Hello, Connector/NET World!