@@ -347,14 +347,19 @@ pq_begin_locked(connectionObject *conn, PyThreadState **tstate)
347347 char buf [256 ]; /* buf size must be same as bufsize */
348348 int result ;
349349
350- Dprintf ("pq_begin_locked: pgconn = %p, autocommit = %d, status = %d" ,
350+ Dprintf ("pq_begin_locked: pgconn = %p, %d, status = %d" ,
351351 conn -> pgconn , conn -> autocommit , conn -> status );
352352
353- if (conn -> autocommit || conn -> status != CONN_STATUS_READY ) {
353+ if (conn -> status != CONN_STATUS_READY ) {
354354 Dprintf ("pq_begin_locked: transaction in progress" );
355355 return 0 ;
356356 }
357357
358+ if (conn -> autocommit && !conn -> entered ) {
359+ Dprintf ("pq_begin_locked: autocommit and no with block" );
360+ return 0 ;
361+ }
362+
358363 if (conn -> isolevel == ISOLATION_LEVEL_DEFAULT
359364 && conn -> readonly == STATE_DEFAULT
360365 && conn -> deferrable == STATE_DEFAULT ) {
@@ -393,10 +398,10 @@ pq_commit(connectionObject *conn)
393398 Py_BEGIN_ALLOW_THREADS ;
394399 pthread_mutex_lock (& conn -> lock );
395400
396- Dprintf ("pq_commit: pgconn = %p, autocommit = %d, status = %d" ,
397- conn -> pgconn , conn -> autocommit , conn -> status );
401+ Dprintf ("pq_commit: pgconn = %p, status = %d" ,
402+ conn -> pgconn , conn -> status );
398403
399- if (conn -> autocommit || conn -> status != CONN_STATUS_BEGIN ) {
404+ if (conn -> status != CONN_STATUS_BEGIN ) {
400405 Dprintf ("pq_commit: no transaction to commit" );
401406 retvalue = 0 ;
402407 }
@@ -427,10 +432,10 @@ pq_abort_locked(connectionObject *conn, PyThreadState **tstate)
427432{
428433 int retvalue = -1 ;
429434
430- Dprintf ("pq_abort_locked: pgconn = %p, autocommit = %d, status = %d" ,
431- conn -> pgconn , conn -> autocommit , conn -> status );
435+ Dprintf ("pq_abort_locked: pgconn = %p, status = %d" ,
436+ conn -> pgconn , conn -> status );
432437
433- if (conn -> autocommit || conn -> status != CONN_STATUS_BEGIN ) {
438+ if (conn -> status != CONN_STATUS_BEGIN ) {
434439 Dprintf ("pq_abort_locked: no transaction to abort" );
435440 return 0 ;
436441 }
@@ -488,12 +493,12 @@ pq_reset_locked(connectionObject *conn, PyThreadState **tstate)
488493{
489494 int retvalue = -1 ;
490495
491- Dprintf ("pq_reset_locked: pgconn = %p, autocommit = %d, status = %d" ,
492- conn -> pgconn , conn -> autocommit , conn -> status );
496+ Dprintf ("pq_reset_locked: pgconn = %p, status = %d" ,
497+ conn -> pgconn , conn -> status );
493498
494499 conn -> mark += 1 ;
495500
496- if (! conn -> autocommit && conn -> status == CONN_STATUS_BEGIN ) {
501+ if (conn -> status == CONN_STATUS_BEGIN ) {
497502 retvalue = pq_execute_command_locked (conn , "ABORT" , tstate );
498503 if (retvalue != 0 ) return retvalue ;
499504 }
0 commit comments