Skip to content

Commit

Permalink
Fix bugs in db_info; use EnvExtendedInterpolation in configs
Browse files Browse the repository at this point in the history
  • Loading branch information
pcisar committed May 7, 2024
1 parent 1963ba1 commit f9a0276
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 18 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [1.10.4] - 2024-05-07

### Added

- Support for values fetched from environment variables in configuration files via
EnvExtendedInterpolation provided by firebird-base package v1.8.0.

### Fixed

- Unregistered bug: db info call for CRYPT_KEY, CRYPT_PLUGIN, WIRE_CRYPT, DB_GUID and
DB_FILE_ID returned mangled values.
- Unregistered bug: db info call for FIREBIRD_VERSION or Connection.info.firebird_version
always returned only one string. Now it returns all values returned by server, separated
by newline.

## [1.10.3] - 2024-05-03

### Fixed
Expand Down
10 changes: 10 additions & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
Changelog
#########

Version 1.10.4
==============

- Support for values fetched from environment variables in configuration files via
`~firebird.base.config.EnvExtendedInterpolation` provided by firebird-base package v1.8.0.
- Fix: db info call for CRYPT_KEY, CRYPT_PLUGIN, WIRE_CRYPT, DB_GUID and
DB_FILE_ID returned mangled values.
- Fix: db info call for FIREBIRD_VERSION or `.Connection.info.firebird_version`
always returned only one string. Now it returns all values returned by server, separated
by newline.

Version 1.10.3
==============
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ classifiers = [
"Topic :: Database",
]
dependencies = [
"firebird-base>=1.7.0",
"firebird-base>=1.8.0",
"python-dateutil>=2.8",
]

Expand Down
2 changes: 1 addition & 1 deletion src/firebird/driver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@
Server, Statement)

#: Current driver version, SEMVER string.
__VERSION__ = '1.10.3'
__VERSION__ = '1.10.4'
15 changes: 7 additions & 8 deletions src/firebird/driver/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@
from __future__ import annotations
from typing import Dict, Union, Iterable
import os
from configparser import ConfigParser, ExtendedInterpolation
from firebird.base.config import Config, StrOption, IntOption, BoolOption, EnumOption, \
ConfigListOption, ListOption
ConfigListOption, ListOption, ConfigParser, EnvExtendedInterpolation
from .types import NetProtocol, DecfloatRound, DecfloatTraps

class ServerConfig(Config): # pylint: disable=R0902
Expand Down Expand Up @@ -218,7 +217,7 @@ def read(self, filenames: Union[str, Iterable], encoding: str=None):
Return list of successfully read files.
"""
parser = ConfigParser(interpolation=ExtendedInterpolation())
parser = ConfigParser(interpolation=EnvExtendedInterpolation())
read_ok = parser.read(filenames, encoding)
if read_ok:
self.load_config(parser)
Expand All @@ -228,13 +227,13 @@ def read_file(self, f):
The `f` argument must be iterable, returning one line at a time.
"""
parser = ConfigParser(interpolation=ExtendedInterpolation())
parser = ConfigParser(interpolation=EnvExtendedInterpolation())
parser.read_file(f)
self.load_config(parser)
def read_string(self, string: str) -> None:
"""Read configuration from a given string.
"""
parser = ConfigParser(interpolation=ExtendedInterpolation())
parser = ConfigParser(interpolation=EnvExtendedInterpolation())
parser.read_string(string)
self.load_config(parser)
def read_dict(self, dictionary: Dict) -> None:
Expand All @@ -247,7 +246,7 @@ def read_dict(self, dictionary: Dict) -> None:
All types held in the dictionary are converted to strings during
reading, including section names, option names and keys.
"""
parser = ConfigParser(interpolation=ExtendedInterpolation())
parser = ConfigParser(interpolation=EnvExtendedInterpolation())
parser.read_dict(dictionary)
self.load_config(parser)
def get_server(self, name: str) -> ServerConfig:
Expand Down Expand Up @@ -282,7 +281,7 @@ def register_server(self, name: str, config: str=None) -> ServerConfig:
srv_config = ServerConfig(name)
self.servers.value.append(srv_config)
if config:
parser = ConfigParser(interpolation=ExtendedInterpolation())
parser = ConfigParser(interpolation=EnvExtendedInterpolation())
parser.read_string(config)
srv_config.load_config(parser, name)
return srv_config
Expand All @@ -304,7 +303,7 @@ def register_database(self, name: str, config: str=None) -> DatabaseConfig:
db_config = DatabaseConfig(name)
self.databases.value.append(db_config)
if config:
parser = ConfigParser(interpolation=ExtendedInterpolation())
parser = ConfigParser(interpolation=EnvExtendedInterpolation())
parser.read_string(config)
db_config.load_config(parser, name)
return db_config
Expand Down
18 changes: 10 additions & 8 deletions src/firebird/driver/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1116,8 +1116,8 @@ def __init__(self, connection: Connection):
DbInfoCode.DB_ID: self.__db_id,
DbInfoCode.IMPLEMENTATION: self.__implementation,
DbInfoCode.IMPLEMENTATION_OLD: self.__implementation_old,
DbInfoCode.VERSION: self._info_string,
DbInfoCode.FIREBIRD_VERSION: self._info_string,
DbInfoCode.VERSION: self._version_string,
DbInfoCode.FIREBIRD_VERSION: self._version_string,
DbInfoCode.USER_NAMES: self.__user_names,
DbInfoCode.ACTIVE_TRANSACTIONS: self.__tra_active,
DbInfoCode.LIMBO: self.__tra_limbo,
Expand Down Expand Up @@ -1197,13 +1197,15 @@ def __implementation_old(self) -> Tuple[int, int]:
impl_number = self.response.read_byte()
class_number = self.response.read_byte()
return (impl_number, class_number)
def _info_string(self) -> str:
self.response.read_byte() # Cluster length
self.response.read_short() # number of strings
return self.response.read_pascal_string()
def _version_string(self) -> str:
self.response.read_short() # Cluster length
result = []
count = self.response.read_byte() # number of strings
for _ in range(count):
result.append(self.response.read_pascal_string())
return '\n'.join(result)
def _single_info_string(self) -> str:
self.response.read_byte() # Cluster length
return self.response.read_pascal_string()
return self.response.read_sized_string()
def __user_names(self) -> Dict[str, str]:
self.response.rewind() # necessary to process names separated by info tag
usernames = []
Expand Down
3 changes: 3 additions & 0 deletions tests/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,9 @@ def test_db_info(self):
self.assertIsInstance(con.info.get_info(DbInfoCode.ODS_VERSION), int)
self.assertIsInstance(con.info.get_info(DbInfoCode.ODS_MINOR_VERSION), int)
#
self.assertEqual(con.info.get_info(DbInfoCode.CRYPT_KEY), '')
self.assertEqual(con.info.get_info(DbInfoCode.CRYPT_PLUGIN), '')
self.assertEqual(con.info.get_info(DbInfoCode.DB_GUID), '{03EC58E8-865D-4528-A888-130677BEB1CF}')


class TestTransaction(DriverTestBase):
Expand Down

0 comments on commit f9a0276

Please sign in to comment.