获得了打开的连接的句柄后,您可以访问和修改存储在数据库中的数据。可能最简单的操作是检索某些行并输出它们。
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() |
![]() |
使用DocCommentXchange讨论此页。
|
版权 © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1 |