fbpx

AttributeError: Transaction instance has no attribute ‘trans_handle’

303 просмотра
0
0 Комментариев

Я написал следующую программу

import pyodbc
#import kinterbasdb
import firebirdsql
import os
import json,sqlite3,sql
conn=firebirdsql.create_database(host='localhost', database='D:/test2.fdb', user='sysdba', password='masterkey')
cur=conn.cursor()
conn.begin()
s="""
create table CLIENTS
(
   ID    INTEGER NOT NULL,
   COMPANY   VARCHAR(50),
   "LAST NAME"   VARCHAR(50),
   "FIRST NAME"   VARCHAR(50),
   "E-MAIL ADDRESS"   VARCHAR(50),
   "JOB TITLE"   VARCHAR(50),
   "BUSINESS PHONE"   VARCHAR(25),
   "HOME PHONE"   VARCHAR(25),
   "MOBILE PHONE"   VARCHAR(25),
   "FAX NUMBER"   VARCHAR(25),
   ADDRESS   BLOB SUB_TYPE 1,
   CITY   VARCHAR(50),
   "STATE/PROVINCE"   VARCHAR(50),
   "ZIP/POSTAL CODE"   VARCHAR(15),
   "COUNTRY/REGION"   VARCHAR(50),
   "WEB-SITE"   VARCHAR(25),
   NOTES   BLOB SUB_TYPE 1,
   INCLUDING   BLOB,
   CONSTRAINT PK_CLIENTS_ID PRIMARY KEY(ID)
);
"""
cur.execute(s)
conn.commit()
s="INSERT INTO CLIENTS (ID, COMPANY) VALUES(1, 'Organization A')"
conn.begin()
cur.execute(s)
conn.commit()
conn.close()

В результате я получил следующую ошибку

Traceback (most recent call last):
  File "D:/ThirdTask/connectthree.py", line 37, in <module>
    cur.execute(s)
  File "C:\Python27\lib\site-packages\firebirdsql\fbcore.py", line 495, in execute
    stmt_type, stmt_handle = self._execute(query, params)
  File "C:\Python27\lib\site-packages\firebirdsql\fbcore.py", line 456, in _execute
    self.transaction.trans_handle, query)
AttributeError: Transaction instance has no attribute 'trans_handle'

В другой версии программы я получил ошибку

import pyodbc
#import kinterbasdb
import firebirdsql
import os
import json,sqlite3,sql
conn=firebirdsql.create_database(host='localhost', database='D:/test2.fdb', user='sysdba', password='masterkey')
cur=conn.cursor()
s="""
create table CLIENTS
(
   ID    INTEGER NOT NULL,
   COMPANY   VARCHAR(50),
   "LAST NAME"   VARCHAR(50),
   "FIRST NAME"   VARCHAR(50),
   "E-MAIL ADDRESS"   VARCHAR(50),
   "JOB TITLE"   VARCHAR(50),
   "BUSINESS PHONE"   VARCHAR(25),
   "HOME PHONE"   VARCHAR(25),
   "MOBILE PHONE"   VARCHAR(25),
   "FAX NUMBER"   VARCHAR(25),
   ADDRESS   BLOB SUB_TYPE 1,
   CITY   VARCHAR(50),
   "STATE/PROVINCE"   VARCHAR(50),
   "ZIP/POSTAL CODE"   VARCHAR(15),
   "COUNTRY/REGION"   VARCHAR(50),
   "WEB-SITE"   VARCHAR(25),
   NOTES   BLOB SUB_TYPE 1,
   INCLUDING   BLOB,
   CONSTRAINT PK_CLIENTS_ID PRIMARY KEY(ID)
);
"""
cur.execute(s)
s="INSERT INTO CLIENTS (ID, COMPANY) VALUES(1, 'Organization A')"
cur.execute(s)
conn.commit()
conn.close()

я получил другую ошибку

Traceback (most recent call last):
  File "D:/ThirdTask/connectthree.py", line 35, in <module>
    cur.execute(s)
  File "C:\Python27\lib\site-packages\firebirdsql\fbcore.py", line 495, in execute
    stmt_type, stmt_handle = self._execute(query, params)
  File "C:\Python27\lib\site-packages\firebirdsql\fbcore.py", line 457, in _execute
    (h, oid, buf) = self.transaction.connection._op_response()
  File "C:\Python27\lib\site-packages\firebirdsql\wireprotocol.py", line 764, in _op_response
    return self._parse_op_response()
  File "C:\Python27\lib\site-packages\firebirdsql\wireprotocol.py", line 308, in _parse_op_response
    raise OperationalError(message, gds_codes, sql_code)
OperationalError: Dynamic SQL Error
SQL error code = -204
Table unknown
CLIENTS
At line 1, column 13


Добавить комментарий

1 Ответы

Python Опубликовано 15.06.2019
0

В первом варианте программы после начала второй транзакции

conn.begin()

необходимо было добавить

cur=conn.cursor().

Добавить комментарий
Напишите свой ответ на данный вопрос.
Scroll Up