Entering content frame

This graphic is explained in the accompanying text SELECT Statement and Displaying the Structure of the Result Set Locate the document in the library structure

The structure of a result set is not always known when the application program is written. You can use the getDescription Method to determine this structure at program run time.

 

1. Creating the Python file sample_4.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 getDescription method releases

# a list of the column descriptions.

----------------------------------------------

descriptions = cursor.getDescription ()

for description in descriptions:

    print '======================='

    # Column name

    print 'Name:', description [0]

    # Type of the column as a string

    print 'Type:', description [1]

    # Type of the column as an integer

    print 'Type:', description [2]

    # Column length

    print 'Len:', description [3]

    # Number of decimal places

    print 'Frac:', description [4]

    # Result set columns are always required columns.

    print 'Mandatory:', description [5]

    # Result set columns are always output.

    print 'in/out:', description [6]

#

# Ending the session with the database instance

# --------------------------------------------

session.release ()

 

2. To call the Python file sample_4.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_4.py MONA RED DEMODB

 

 

Leaving content frame