The result of a SELECT statement is an object of the SapDB_ResultSet class. You can use this object to call each result row in sequence, without loading the entire result set in the main memory.
1. Creating the Python file sample_2.py:
#
# To reference Python libraries:
# -------------------------------------------
import sys
import sapdb.sql
# Starting the session with the database instance
# -------------------------------------------
database_user = sys.argv [1]
database_user_password = sys.argv [2]
database_name = sys.argv [3]
session = sapdb.sql.connect (database_user, database_user_password, database_name)
select = """
SELECT msgno, language, msgtext FROM messages
WHERE msgno BETWEEN -1000 AND -1"""
#
# If the SQL method executes a SELECT statement,
# the result is an object of the SAPDB_ResultSet class.
-----------------------------------------------
cursor = session.sql (select)
#
# The next method releases the following row of the result set.
# When the last row of the result set is reached,
# the next method returns the value 'None'.
-----------------------------------------------
row = cursor.next ()
while row:
errorcode, language, message = row
print "%6d %s" % (errorcode, message)
row = cursor.next ()
#
# Ending the session with the database instance
# ---------------------------------------------
session.release ()
2. To call the Python file sample_2.py from the command line and transfer database user MONA’s data to the Python program with the password RED and the database instance named DEMODB, specify the following:
python sample_2.py MONA RED DEMODB