Coverage for src / lexigram / contracts / data / sql / sql.py: 12%

17 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-08-19 05:41 +0800

1"""SQL identifier exceptions. 

2 

3This module contains only exception types for SQL identifier handling. 

4The concrete identifier implementations have been moved to lexigram-sql. 

5""" 

6 

7from __future__ import annotations 

8 

9from typing import Any 

10 

11from lexigram.contracts.exceptions.domain import ValidationError 

12 

13 

14class InvalidIdentifierError(ValidationError): 

15 """Raised when an SQL identifier fails validation. 

16 

17 Attributes: 

18 identifier: The offending identifier string. 

19 """ 

20 

21 _code = "LEX_ERR_DB_010" 

22 

23 def __init__( 

24 self, message: str, identifier: str | None = None, **kwargs: Any 

25 ) -> None: 

26 super().__init__( 

27 message=message, 

28 details={"identifier": identifier}, 

29 **kwargs, 

30 ) 

31 self.identifier = identifier 

32 

33 

34# Placeholder for RawSQL type that may be used elsewhere 

35class RawSQL: 

36 """Raw SQL string that bypasses validation. 

37 

38 This is a marker type for SQL that should not be validated or quoted. 

39 

40 Warning: 

41 Never pass user-supplied values directly into this query string. 

42 Always use parameterized queries or the provided binding mechanisms 

43 to prevent SQL injection vulnerabilities. 

44 

45 Attributes: 

46 sql: The raw SQL string. 

47 """ 

48 

49 __slots__ = ("_sql",) 

50 

51 def __init__(self, sql: str) -> None: 

52 self._sql = sql 

53 

54 def __str__(self) -> str: 

55 return self._sql 

56 

57 def __repr__(self) -> str: 

58 return f"RawSQL({self._sql!r})" 

59 

60 

61__all__ = [ 

62 "InvalidIdentifierError", 

63 "RawSQL", 

64]