execute is a method of the SapDB_Prepared class. You can use this method to execute SQL statements with parameters, for example database procedures.
Syntax
execute (sqlParms = [])
Attribute |
Description |
---|---|
sqlParms |
Parameter list with input parameters |
Result:
Successful execution: See Possible SQL Results
Output parameters, if any
If an error occurs: Exception of the SQLError Class (sdb.sql module)
Syntax
select = session.prepare ('SELECT * FROM hotel.customer WHERE cno = ?') select.execute ([3000])
<SapDB_ResultSet object at ...>
You create the avg_price database procedure:
Syntax
session.sql ("""CREATE DBPROCEDURE avg_price (IN zip CHAR(5), OUT avg_price FIXED(6,2)) AS VAR sum FIXED(10,2); price FIXED(6,2); hotels INTEGER; TRY SET sum = 0; SET hotels = 0; DECLARE dbproccursor CURSOR FOR SELECT price FROM hotel.room,hotel.hotel WHERE zip = :zip AND room.hno = hotel.hno AND type = 'single'; WHILE $rc = 0 DO BEGIN FETCH dbproccursor INTO :price; SET sum = sum + price; SET hotels = hotels + 1; END; CATCH IF $rc <> 100 THEN STOP ($rc, 'unexpected error'); CLOSE dbproccursor; IF hotels > 0 THEN SET avg_price = sum / hotels ELSE STOP (100, 'no hotel found');""")
You create an object of the SapDBPrepared class using the prepare method:
Syntax
call = session.prepare ('call hotel.avg_price (?, ?)')
You specify a value for the input parameter:
Syntax
in1 = 20005 # sets zip
You call the database procedure using the execute method.
Syntax
out1 = call.execute ([in1])
You display the value of the output parameter:
Syntax
print 'value avg_price:', out1
value avg_price: (135.0)