1
- pg-python architecture
2
- ======================
1
+ =========
2
+ Mechanics
3
+ =========
3
4
4
- This README provides a high-level overview of the implementation.
5
+ This chapter discusses some of the internal mechanics and design decisions
6
+ of pg-python.
5
7
6
8
Native Type Interfaces
7
- ----------------------
9
+ ======================
8
10
9
11
pg-python was designed with the goal of providing Python interfaces to
10
12
PostgreSQL objects--often conceptual rather than literal. This marks a sharp
@@ -33,14 +35,14 @@ Postgres object is present, the other operand will be converted to that type.
33
35
34
36
35
37
Error Management
36
- ----------------
38
+ ================
37
39
38
40
pg-python handles database errors by raising a Python exception representing
39
41
the error. By doing this, pg-python must record when this has been done so that
40
42
future database actions can be prohibited. The `ext_state` global is used to
41
43
track the error state of the PL.
42
44
43
- When a database error(ereport, elog) occurs, pl_state is altered to indicate
45
+ When a database error(ereport, elog) occurs, ext_state is altered to indicate
44
46
that subsequent use of database functionality should be restricted by an
45
47
exception being raised. The "DB_IS_NOT_READY()" macro should be used at the
46
48
beginning of every Python interface that requires that the database is in a
@@ -71,15 +73,15 @@ The following error codes have been added:
71
73
and it should be raised (Python) or thrown (Postgres) accordingly.
72
74
73
75
Transaction Management (Internal Subtransactions)
74
- -------------------------------------------------
76
+ =================================================
75
77
76
78
Subtransactions are managed using a simple counter. Each Postgres.Transaction
77
79
instance will get a local transaction identifier that is used to validate that
78
80
transactions are exited in the appropriate order.
79
81
80
82
81
83
Prepared Statements and Cursors (SPI)
82
- -------------------------------------
84
+ =====================================
83
85
84
86
Database access is implemented using two types: the Postgres.Statement and the
85
87
Postgres.Cursor.
@@ -93,7 +95,7 @@ scrollable cursor is created, the seek and read methods are available for use.
93
95
94
96
95
97
Postgres Interface Module
96
- -------------------------
98
+ =========================
97
99
98
100
All Postgres interfaces are provided using the "Postgres" module. This is a
99
101
built-in module that is extended with the contents of the "module.py" file.
@@ -103,7 +105,7 @@ high-level initialization(@pytypes is implemented in pure-Python).
103
105
104
106
105
107
First Call Initialization
106
- -------------------------
108
+ =========================
107
109
108
110
Much of the PL is initialized in _PG_init. However, it is possible for _PG_init
109
111
to be executed outside of a transaction(preloading), which means that we cannot
@@ -114,7 +116,7 @@ pseudo-module.
114
116
115
117
116
118
Inline Execution
117
- ----------------
119
+ ================
118
120
119
121
DO statements are handled using a fake PyPgFunction object--that is, there is no
120
122
corresponding pg_proc entry. The function's module is set to the InlineExecutor
@@ -124,7 +126,7 @@ takes a single argument, the source to execute.
124
126
125
127
126
128
Interrupt Support
127
- -----------------
129
+ =================
128
130
129
131
Interrupts are supported by overriding the default signal handlers for SIGTERM
130
132
and SIGINT. While scary at first, these overrides are *not* installed unless the
0 commit comments