On Mon, Mar 9, 2020 at 3:44 PM Velu Narasimman <[email protected]> wrote:
> Coming to my above problem, I altered the way the query is prepared now I 
> tried the below code and it worked.
>
>             query = "insert into ticket_time ( exclusion, time_submitted, 
> seconds_worked, submitter, worker, modified, comments, ticket_time_status, 
> reason, time_started, ticket) values %s returning 
> id,ticket,exclusion,reason,time_started"
>             cursor.execute(query, (values,))

I think the code should be:

    values = ...  # should be tuple or list which has 11 items
    query = """
        INSERT INTO ticket_time (
            exclusion, time_submitted, seconds_worked, submitter,
worker, modified,
            comments, ticket_time_status, reason, time_started, ticket)
        VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
        """
    cursor.execute(query, values)
    id_ = cursor.get_last_id('ticket_time')  # retrieve ticket_time.id


See also:
 - 
https://www.edgewall.org/docs/branches-1.2-stable/html/api/trac_db_api.html?highlight=execute#trac.db.api.DbContextManager.execute
 - 
https://www.edgewall.org/docs/branches-1.2-stable/html/api/trac_db_api.html?highlight=execute#trac.db.api.ConnectionBase.get_last_id

-- 
Jun Omae <[email protected]> (大前 潤)

-- 
You received this message because you are subscribed to the Google Groups "Trac 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/trac-users/CAEVLMagafg05muVYrLchvyoyXCjJWmN__cu_F_i572s%2Bxi3W6Q%40mail.gmail.com.

Reply via email to