in pyqldbsamples/insert_ion_types.py [0:0]
def update_record_and_verify_type(driver, parameter, ion_object, ion_type):
"""
Update a record in the database table. Then query the value of the record and verify correct ion type saved.
:type driver: :py:class:`pyqldb.driver.qldb_driver.QldbDriver`
:param driver: An instance of the QldbDriver class.
:type parameter: :py:class:`amazon.ion.simple_types.IonPyValue`
:param parameter: The Ion value or Python native type that is convertible to Ion for filling in parameters of the
statement.
:type ion_object: :py:obj:`IonPyBool`/:py:obj:`IonPyBytes`/:py:obj:`IonPyDecimal`/:py:obj:`IonPyDict`
/:py:obj:`IonPyFloat`/:py:obj:`IonPyInt`/:py:obj:`IonPyList`/:py:obj:`IonPyNull`
/:py:obj:`IonPySymbol`/:py:obj:`IonPyText`/:py:obj:`IonPyTimestamp`
:param ion_object: The Ion object to verify against.
:type ion_type: :py:class:`amazon.ion.core.IonType`
:param ion_type: The Ion type to verify against.
:raises TypeError: When queried value is not an instance of Ion type.
"""
update_query = 'UPDATE {} SET Name = ?'.format(TABLE_NAME)
driver.execute_lambda(lambda executor: executor.execute_statement(update_query, parameter))
logger.info('Updated record.')
search_query = 'SELECT VALUE Name FROM {}'.format(TABLE_NAME)
cursor = driver.execute_lambda(lambda executor: executor.execute_statement(search_query))
for c in cursor:
if not isinstance(c, ion_object):
raise TypeError('The queried value is not an instance of {}'.format(ion_object.__name__))
if c.ion_type is not ion_type:
raise TypeError('The queried value type does not match {}'.format(ion_type))
logger.info("Successfully verified value is instance of '{}' with type '{}'.".format(ion_object.__name__, ion_type))
return cursor