On Mon, Mar 9, 2020 at 3:44 PM Velu Narasimman <
velava...@gmail.com> 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