Permalink
Browse files

refactoring

  • Loading branch information...
1 parent f21d08d commit 6e9645cdc90cd3483da3faf0b684ad4876dffd2b @nakagami committed Jul 9, 2011
Showing with 12 additions and 148 deletions.
  1. +2 −0 firebirdsql/__init__.py
  2. +7 −145 firebirdsql/fbcore.py
  3. +3 −3 firebirdsql/tests.py
@@ -7,6 +7,8 @@
# Python DB-API 2.0 module for Firebird.
##############################################################################
+from consts import *
+
class Error(Exception):
def __init__(self, message, gds_codes, sql_code=0):
self.message = message
View
@@ -12,6 +12,7 @@
from firebirdsql import (DatabaseError, InternalError, OperationalError,
ProgrammingError, IntegrityError, DataError, NotSupportedError,
)
+from consts import *
DEFAULT_CHARSET='UTF8'
PYTHON_MAJOR_VER = sys.version_info[0]
@@ -27,94 +28,6 @@ def bs(byte_array):
threadsafety = 1
paramstyle = 'qmark'
-ISOLATION_LEVEL_READ_UNCOMMITTED = 0
-ISOLATION_LEVEL_READ_COMMITED = 1
-ISOLATION_LEVEL_REPEATABLE_READ = 2
-ISOLATION_LEVEL_SERIALIZABLE = 3
-
-isc_tpb_version1 = 1
-isc_tpb_version3 = 3
-isc_tpb_consistency = 1
-isc_tpb_concurrency = 2
-isc_tpb_shared = 3
-isc_tpb_protected = 4
-isc_tpb_exclusive = 5
-isc_tpb_wait = 6
-isc_tpb_nowait = 7
-isc_tpb_read = 8
-isc_tpb_write = 9
-isc_tpb_lock_read = 10
-isc_tpb_lock_write = 11
-isc_tpb_verb_time = 12
-isc_tpb_commit_time = 13
-isc_tpb_ignore_limbo = 14
-isc_tpb_read_committed = 15
-isc_tpb_autocommit = 16
-isc_tpb_rec_version = 17
-isc_tpb_no_rec_version = 18
-isc_tpb_restart_requests = 19
-isc_tpb_no_auto_undo = 20
-isc_tpb_lock_timeout = 21
-
-
-# Service Parameter Block parameter
-isc_spb_version1 = 1
-isc_spb_current_version = 2
-isc_spb_version = isc_spb_current_version
-isc_spb_user_name = 28 # isc_dpb_user_name
-isc_spb_sys_user_name = 19 # isc_dpb_sys_user_name
-isc_spb_sys_user_name_enc = 31 # isc_dpb_sys_user_name_enc
-isc_spb_password = 29 # isc_dpb_password
-isc_spb_password_enc = 30 # isc_dpb_password_enc
-isc_spb_command_line = 105
-isc_spb_dbname = 106
-isc_spb_verbose = 107
-isc_spb_options = 108
-isc_spb_address_path = 109
-isc_spb_process_id = 110
-isc_spb_trusted_auth = 111
-isc_spb_process_name = 112
-isc_spb_trusted_role = 113
-isc_spb_connect_timeout = 57 # isc_dpb_connect_timeout
-isc_spb_dummy_packet_interval = 58 # isc_dpb_dummy_packet_interval
-isc_spb_sql_role_name = 60 # isc_dpb_sql_role_name
-# backup
-isc_spb_bkp_file = 5
-# restore
-isc_spb_res_buffers = 9
-isc_spb_res_page_size = 10
-# trace
-isc_spb_trc_id = 1
-isc_spb_trc_name = 2
-isc_spb_trc_cfg = 3
-
-
-# Service Action Items
-isc_action_svc_backup = 1
-isc_action_svc_restore = 2
-isc_action_svc_repair = 3
-isc_action_svc_add_user = 4
-isc_action_svc_delete_user = 5
-isc_action_svc_modify_user = 6
-isc_action_svc_display_user = 7
-isc_action_svc_properties = 8
-isc_action_svc_add_license = 9
-isc_action_svc_remove_license = 10
-isc_action_svc_db_stats = 11
-isc_action_svc_get_ib_log = 12
-isc_action_svc_get_fb_log = 12
-isc_action_svc_nbak = 20
-isc_action_svc_nrest = 21
-isc_action_svc_trace_start = 22
-isc_action_svc_trace_stop = 23
-isc_action_svc_trace_suspend = 24
-isc_action_svc_trace_resume = 25
-isc_action_svc_trace_list = 26
-isc_action_svc_set_mapping = 27
-isc_action_svc_drop_mapping = 28
-isc_action_svc_display_user_adm = 29
-isc_action_svc_last = 30
-
transaction_parameter_block = [
# ISOLATION_LEVEL_READ_UNCOMMITTED
@@ -147,57 +60,6 @@ def bs(byte_array):
'isc_arg_next_mach', 'isc_arg_netware', 'isc_arg_win32', 'isc_arg_warning',
]
-isc_info_names = [
- None, 'isc_info_end', 'isc_info_truncated', 'isc_info_error',
- 'isc_info_db_id', 'isc_info_reads',
- 'isc_info_writes', 'isc_info_fetches', 'isc_info_marks', None, None,
- 'isc_info_implementation', 'isc_info_isc_version', 'isc_info_base_level',
- 'isc_info_page_size', 'isc_info_num_buffers', 'isc_info_limbo',
- 'isc_info_current_memory', 'isc_info_max_memory', 'isc_info_window_turns',
- 'isc_info_license', 'isc_info_allocation', 'isc_info_attachment_id',
- 'isc_info_read_seq_count', 'isc_info_read_idx_count',
- 'isc_info_insert_count', 'isc_info_update_count', 'isc_info_delete_count',
- 'isc_info_backout_count', 'isc_info_purge_count', 'isc_info_expunge_count',
- 'isc_info_sweep_interval', 'isc_info_ods_version',
- 'isc_info_ods_minor_version', 'isc_info_no_reserve', 'isc_info_logfile',
- 'isc_info_cur_logfile_name', 'isc_info_cur_log_part_offset',
- 'isc_info_num_wal_buffers', 'isc_info_wal_buffer_size',
- 'isc_info_wal_ckpt_length', 'isc_info_wal_cur_ckpt_interval',
- 'isc_info_wal_prv_ckpt_fname', 'isc_info_wal_prv_ckpt_poffset',
- 'isc_info_wal_recv_ckpt_fname', 'isc_info_wal_recv_ckpt_poffset', None,
- 'isc_info_wal_grpc_wait_usecs', 'isc_info_wal_num_io',
- 'isc_info_wal_avg_io_size', 'isc_info_wal_num_commits',
- 'isc_info_wal_avg_grpc_size', 'isc_info_forced_writes',
- 'isc_info_user_names', 'isc_info_page_errors',
- 'isc_info_record_errors', 'isc_info_bpage_errors',
- 'isc_info_dpage_errors', 'isc_info_ipage_errors',
- 'isc_info_ppage_errors', 'isc_info_tpage_errors',
- 'isc_info_set_page_buffers', 'isc_info_db_sql_dialect',
- 'isc_info_db_read_only', 'isc_info_db_size_in_pages',
-]
-for i in range(len(isc_info_names), 101): # 65-100 no use
- isc_info_names.append(None)
-isc_info_names += [
- 'frb_info_att_charset', 'isc_info_db_class', 'isc_info_firebird_version',
- 'isc_info_oldest_transaction', 'isc_info_oldest_active',
- 'isc_info_oldest_snapshot', 'isc_info_next_transaction',
- 'isc_info_db_provider', 'isc_info_active_transactions',
-]
-
-SQL_TYPE_TEXT = 452
-SQL_TYPE_VARYING = 448
-SQL_TYPE_SHORT = 500
-SQL_TYPE_LONG = 496
-SQL_TYPE_FLOAT = 482
-SQL_TYPE_DOUBLE = 480
-SQL_TYPE_D_FLOAT = 530
-SQL_TYPE_TIMESTAMP = 510
-SQL_TYPE_BLOB = 520
-SQL_TYPE_ARRAY = 540
-SQL_TYPE_QUAD = 550
-SQL_TYPE_TIME = 560
-SQL_TYPE_DATE = 570
-SQL_TYPE_INT64 = 580
INFO_SQL_STMT_TYPE = bs([0x15])
INFO_SQL_SQLDA_START = bs([0x14,0x02])
@@ -1202,19 +1064,19 @@ def set_isolation_level(self, isolation_level):
self.isolation_level = isolation_level
def info_database(self, info_names):
- if info_names[-1] != 'isc_info_end':
- info_names.append('isc_info_end')
- b = bs([isc_info_names.index(s) for s in info_names])
+ if info_names[-1] != isc_info_end:
+ info_names.append(isc_info_end)
+ b = bs(info_names)
self._op_info_database(b)
(h, oid, buf) = self._op_response()
i = 0
r = []
while i < len(buf):
if PYTHON_MAJOR_VER==3:
- s = isc_info_names[buf[i]]
+ s = buf[i]
else:
- s = isc_info_names[ord(buf[i])]
- if s == 'isc_info_end':
+ s = ord(buf[i])
+ if s == isc_info_end:
break
l = bytes_to_int(buf[i+1:i+3])
r.append(buf[i+3:i+3+l])
@@ -30,9 +30,9 @@ def debug_print(msg):
TEST_USER = 'sysdba'
TEST_PASS = 'masterkey'
conn = firebirdsql.create_database(dsn=TEST_DSN, user=TEST_USER, password=TEST_PASS)
- print(conn.info_database(['isc_info_ods_version',
- 'isc_info_ods_minor_version',
- 'isc_info_user_names']))
+ print(conn.info_database([firebirdsql.isc_info_ods_version,
+ firebirdsql.isc_info_ods_minor_version,
+ firebirdsql.isc_info_user_names]))
conn.cursor().execute('''
CREATE TABLE foo (
a INTEGER NOT NULL,

0 comments on commit 6e9645c

Please sign in to comment.