IronPythonããADO.NETã使ããµã³ãã«
Pythonããã°ã©ããIronPythonãå§ããå ´åã.NETçµé¨è
ãªãã¨ã¯ã»ã¨ãã©ãªãã¨æãã®ã§ç°¡åãªãµã³ãã«ãç¨æãã¦ã¿ã¾ããã
ãã¼ã¿ãã¼ã¹ã¯MySqlã¨ãã¾ãããADO.NETã®ãã©ã¤ãã¼ã¯ここからãADO.NETãåãã¦ã®æ¹ã¯ãアプリケーションとデータの仲介役 : DataAdapterã5åã»ã©ã覧ãã ããã(^^;
import clr clr.AddReferenceByPartialName ('System.Data') clr.AddReferenceToFile ('MySql.Data.dll') from System.Data import * from MySql.Data.MySqlClient import * connstr = 'User Id=%s;Password=%s;Database=%s' % ('user', 'pass', 'db') statement = 'SELECT ename, job FROM emp' def test_reader (conn): cmd = conn.CreateCommand () cmd.CommandText = statement r = cmd.ExecuteReader () while r.Read (): print 'Employee Name:%s, Job:%s' % (r['ename'], r['job']) r.Close () def test_adapter (conn): da = MySqlDataAdapter (statement, conn) ds = DataSet () da.Fill (ds) for r in ds.Tables[0].Rows: print 'Employee Name:%s, Job:%s' % (r['ename'], r['job']) conn = None try: conn = MySqlConnection (connstr) conn.Open () # DataReaderã§ã¢ã¯ã»ã¹ test_reader (conn) # DataAdapterã§ã¢ã¯ã»ã¹ test_adapter (conn) finally: if not conn is None: conn.Close ()