@@ -24,20 +24,67 @@ def __init__(self, connection, query, state):
24
24
self ._last_status = None
25
25
26
26
def get_query (self ) -> str :
27
- """Return the text of the query for this prepared statement."""
27
+ """Return the text of the query for this prepared statement.
28
+
29
+ Example::
30
+
31
+ stmt = await connection.prepare('SELECT $1::int')
32
+ assert stmt.get_query() == "SELECT $1::int"
33
+ """
28
34
return self ._query
29
35
30
36
def get_statusmsg (self ) -> str :
31
- """Return the status of the executed command."""
37
+ """Return the status of the executed command.
38
+
39
+ Example::
40
+
41
+ stmt = await connection.prepare('CREATE TABLE mytab (a int)')
42
+ await stmt.fetch()
43
+ assert stmt.get_statusmsg() == "CREATE TABLE"
44
+ """
32
45
if self ._last_status is None :
33
46
return self ._last_status
34
47
return self ._last_status .decode ()
35
48
36
49
def get_parameters (self ):
50
+ """Return a description of statement parameters types.
51
+
52
+ :return: A tuple of :class:`asyncpg.types.Type`.
53
+
54
+ Example::
55
+
56
+ stmt = await connection.prepare('SELECT ($1::int, $2::text)')
57
+ print(stmt.get_parameters())
58
+
59
+ # Will print:
60
+ # (Type(oid=23, name='int4', kind='scalar', schema='pg_catalog'),
61
+ # Type(oid=25, name='text', kind='scalar', schema='pg_catalog'))
62
+ """
37
63
self .__check_open ()
38
64
return self ._state ._get_parameters ()
39
65
40
66
def get_attributes (self ):
67
+ """Return a description of relation attributes (columns).
68
+
69
+ :return: A tuple of :class:`asyncpg.types.Attribute`.
70
+
71
+ Example::
72
+
73
+ st = await self.con.prepare('''
74
+ SELECT typname, typnamespace FROM pg_type
75
+ ''')
76
+ print(st.get_attributes())
77
+
78
+ # Will print:
79
+ # (Attribute(
80
+ # name='typname',
81
+ # type=Type(oid=19, name='name', kind='scalar',
82
+ # schema='pg_catalog')),
83
+ # Attribute(
84
+ # name='typnamespace',
85
+ # type=Type(oid=26, name='oid', kind='scalar',
86
+ # schema='pg_catalog')))
87
+ """
41
88
self .__check_open ()
42
89
return self ._state ._get_attributes ()
43
90
0 commit comments