開かれた接続へのハンドルを取得したら、データベースに格納されているデータにアクセスして修正できます。最も単純な操作は、おそらくいくつかのローを取得して出力することです。
cursor メソッドは、開いている接続にカーソルを作成するために使用します。execute メソッドは、結果セットを作成するために使用します。fetchall メソッドは、この結果セットからローを取得するために使用します。
import sqlanydb # Create a connection object, then use it to create a cursor con = sqlanydb.connect( userid="DBA", password="sql" ) cursor = con.cursor() # Execute a SQL string sql = "SELECT * FROM Employees" cursor.execute(sql) # Get a cursor description which contains column names desc = cursor.description print len(desc) # Fetch all results from the cursor into a sequence, # display the values as column name=value pairs, # and then close the connection rowset = cursor.fetchall() for row in rowset: for col in range(len(desc)): print "%s=%s" % (desc[col][0], row[col] ) print cursor.close() con.close() |
Copyright © 2009, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.1 |