Archive for the ‘Boo’ Category

  1. 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!
  2. Hello, ODP.NET(Boo) World!

    Posted on 2月 26th, 2013 by cx20

    ODP.NET(Boo)

    ODP.NET(Oracle Data Provider for .NET)は、.NET ベースの Oracle Database 接続用 API である。ODAC(Oracle Data Access Component)と呼ばれるパッケージに含まれる。
    .NET 環境での Oracle Database 用データプロバイダとしては、マイクロソフト社が提供する「Microsoft Oracle Client」とオラクル社が提供する「ODP.NET」があるが、現在、「Microsoft Oracle Client」はマイクロソフト社自身が非推奨としており、今後は ODP.NET の使用が推奨されている。

    データプロバイダ 説明
    System.Data.OracleClient .NET Framework Data Provider for Oracle
    Oracle.DataAccess.Client Oracle Data Provider for .NET

    ソースコード(Boo + ODP.NET + Oracle)

    import System
    import Oracle.DataAccess.Client
     
    [STAThread]
    def Main(argv as (string)):
        conStr = "Data Source=ORCL;User ID=scott;Password=tiger"
        sqlStr = "SELECT 'Hello, ODP.NET World!' AS Message FROM DUAL"
     
        con = OracleConnection(conStr)
        cmd = OracleCommand(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, ODP.NET World!
  3. Hello, ADO.NET(Boo) World!

    Posted on 2月 25th, 2013 by cx20

    ADO.NET(Boo)

    ADO.NET(ActiveX Data Objects .NET)は、ADO の後継で .NET ベースの DBMS 接続用 API である。
    .NET データプロバイダを介することで様々な DBMS への接続が可能となっている。
    .NET Framework 標準で使用できる .NET データプロバイダとしては、以下のようなプロバイダがある。

    データプロバイダ名 説明
    System.Data.SqlClient Microsoft SQL Server
    System.Data.OleDb OLE DB
    System.Data.Odbc ODBC
    System.Data.OracleClient Oracle

    ソースコード(Boo + ADO.NET + OLE DB + Jet データベース)

    import System
    import System.Data.OleDb
     
    [STAThread]
    def Main(argv as (string)):
        conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=hello.mdb;"
        sqlStr = "SELECT 'Hello, ADO.NET World!' AS Message"
     
        con = OleDbConnection(conStr)
        cmd = OleDbCommand(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()

    ソースコード(Boo + ADO.NET + OLE DB + ACE データベース)

    import System
    import System.Data.OleDb
     
    [STAThread]
    def Main(argv as (string)):
        conStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=hello.accdb;"
        sqlStr = "SELECT 'Hello, ADO.NET World!' AS Message"
     
        con = OleDbConnection(conStr)
        cmd = OleDbCommand(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()

    ソースコード(Boo + ADO.NET + SQL Server)

    import System
    import System.Data.SqlClient
     
    [STAThread]
    def Main(argv as (string)):
        conStr = "SERVER=(local);DATABASE=master;UID=sa;PWD=P@ssW0rd;"
        sqlStr = "SELECT 'Hello, ADO.NET World!' AS Message"
     
        con = SqlConnection(conStr)
        cmd = SqlCommand(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()

    ソースコード(Boo + ADO.NET + Oracle)

    import System
    import System.Data.OracleClient
     
    [STAThread]
    def Main(argv as (string)):
        conStr = "Data Source=ORCL;User ID=scott;Password=tiger"
        sqlStr = "SELECT 'Hello, ADO.NET World!' AS Message FROM DUAL"
     
        con = OracleConnection(conStr)
        cmd = OracleCommand(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()

    ソースコード(Boo + ADO.NET + ODBC + MySQL)

    import System
    import System.Data.Odbc
     
    [STAThread]
    def Main(argv as (string)):
        conStr = "Driver={MySQL ODBC 5.1 Driver};Server=localhost;UID=root;PWD=P@ssW0rd"
        sqlStr = "SELECT 'Hello, ADO.NET World!' AS Message"
     
        con = OdbcConnection(conStr)
        cmd = OdbcCommand(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()

    コンパイル方法(32bit OLE DB 使用時)

    C:¥> booc -platform:x86 Hello.boo

    コンパイル方法(64bit OLE DB 使用時)

    C:¥> booc -platform:x64 Hello.boo

    コンパイル方法(上記以外)

    C:¥> booc Hello.boo

    実行結果

    Message
    ---------------------
    Hello, ADO.NET World!
  4. Hello, COM(Boo) World!

    Posted on 2月 8th, 2013 by cx20

    COM(Boo)

    COM(Component Object Model)はマイクロソフトの提唱するプログラム部品の仕様である。
    COM を用いて開発された部品であれば言語を問わず利用することができる。
    以下は Boo による COM クライアントの例となっている。

    ソースコード(実行時バインディング)

    import System
    import System.Reflection
    import System.Runtime.InteropServices
     
    [STAThread]
    def Main(argv as (string)):
        objType = Type.GetTypeFromProgID("Shell.Application") 
        shell = Activator.CreateInstance(objType)
        param as (object) = ( 0, "Hello, COM(Boo) World!", 0, 36 )
        folder = shell.GetType().InvokeMember( "BrowseForFolder", BindingFlags.InvokeMethod, null, shell, param )
        if (folder != null):
            Marshal.ReleaseComObject(folder)
        Marshal.ReleaseComObject(shell)

    コンパイル方法(実行時バインディング)

    C:¥> booc Hello.boo

    実行結果

    +----------------------------------------+
    |Browse For Folder                    [X]|
    +----------------------------------------+
    | Hello, COM(Boo) Wolrd!                 |
    |                                        |
    | +------------------------------------+ |
    | |[Windows]                           | |
    | | +[addins]                          | |
    | | +[AppCompat]                       | |
    | | +[AppPatch]                        | |
    | | +[assembly]                        | |
    | |     :                              | |
    | |     :                              | |
    | |     :                              | |
    | +------------------------------------+ |
    | [Make New Folder]    [  OK  ] [Cancel] |
    +----------------------------------------+
  5. Hello, Win32 API(Boo) World!

    Posted on 6月 24th, 2012 by cx20

    Win32 API(Boo)

    Win32 API は、Windows の機能にアクセスする為の API(Application Programming Interface)である。
    以下は Boo による Win32 API の呼出し例である。

    ソースコード

    import System.Runtime.InteropServices
     
    [DllImport("User32.dll", EntryPoint:"MessageBox")]
    def MessageBox(hwnd as int, text as string, caption as string, type as int):
        pass
     
    MessageBox(0, "Hello, Win32 API(Boo) World!", "Hello, World", 0)

    コンパイル方法

    C:¥> booc Hello.boo

    実行結果

    ---------------------------
    Hello, World!
    ---------------------------
    Hello, Win32 API(Boo) World!
    ---------------------------
    OK   
    ---------------------------
  6. Hello, Windows Forms(Boo) World!

    Posted on 6月 14th, 2012 by cx20

    Windows Forms(Boo)

    Windows フォーム(Windows Forms)は .NET Framework におけるユーザーインターフェイス基盤である。Windows アプリケーションにおけるウィンドウやダイアログに対応する。
    以下は Boo における Windows フォーム の例となっている。

    ソースコード

    import System
    import System.Drawing
    import System.Windows.Forms
     
    class HelloForm( Form ):
        def constructor():
            super()
            self.Size = Size( 640, 480 )
            self.Text = "Hello, World!"
            label1 = Label()
            label1.Size = Size( 320, 20 )
            label1.Text = "Hello, Windows Forms(Boo) World!"
            self.Controls.Add( label1 )
     
    [STAThread]
    def Main(argv as (string)):
        form = HelloForm()
        Application.Run( form )

    実行方法

    C:¥> booc -target:winexe Hello.boo

    実行結果

    +------------------------------------------+
    |Hello, World!                    [_][~][X]|
    +------------------------------------------+
    |Hello, Windows Forms(Boo) World!          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    +------------------------------------------+
  7. Hello, Boo World!

    Posted on 1月 26th, 2012 by cx20

    Boo

    Booは .NET Framework 向けのオブジェクト指向言語である。構文は Python に近い。名前の由来は不明だがロゴ(パックマンの敵キャラに似ている)からお化けのことと思われる。
    C# 同様に、UNIX 環境向けの .NET Framework 互換プロジェクト「Mono」により他の OS でも動作させることができる。

    ソースコード

    #!/usr/bin/env booi
    print "Hello, Boo World!"

    ソースコード(.NET ライブラリを使用した場合)

    #!/usr/bin/env booi
    import System
    Console.WriteLine("Hello, Boo World!")

    実行方法(スクリプトファイルを指定して実行)

    $ booi hello.boo

    実行方法(実行権限を付与して実行)

    $ chmod +x hello.boo
    $ ./hello.boo

    コンパイル&実行方法(Mono)

    $ booc hello.boo
    $ mono ./hello.exe

    コンパイル&実行方法(.NET Framework)

    C:¥> booc hello.boo
    C:¥> hello

    実行結果

    Hello, Boo World!