'Execute a string statement on the current cursor, returning a
scalar result.
Used to fire off sequences, default phrases, and "select lastrowid"
types of statements individually or in the context of a parent INSERT
or UPDATE statement.'

def _execute_scalar(self, stmt, type_):

    conn = self.root_connection
    if (isinstance(stmt, util.text_type) and (not self.dialect.supports_unicode_statements)):
        stmt = self.dialect._encoder(stmt)[0]
    if self.dialect.positional:
        default_params = self.dialect.execute_sequence_format()
    else:
        default_params = {}
    conn._cursor_execute(self.cursor, stmt, default_params, context=self)
    r = self.cursor.fetchone()[0]
    if (type_ is not None):
        proc = type_._cached_result_processor(self.dialect, self.cursor.description[0][1])
        if proc:
            return proc(r)
    return r
