1
- /* Module: columninfo.c
1
+ /* Module: columninfo.c
2
2
*
3
- * Description: This module contains routines related to
4
- * reading and storing the field information from a query.
3
+ * Description: This module contains routines related to
4
+ * reading and storing the field information from a query.
5
5
*
6
- * Classes: ColumnInfoClass (Functions prefix: "CI_")
6
+ * Classes: ColumnInfoClass (Functions prefix: "CI_")
7
7
*
8
- * API functions: none
8
+ * API functions: none
9
9
*
10
- * Comments: See "notice.txt" for copyright and license information.
10
+ * Comments: See "notice.txt" for copyright and license information.
11
11
*
12
12
*/
13
13
20
20
ColumnInfoClass *
21
21
CI_Constructor ()
22
22
{
23
- ColumnInfoClass * rv ;
23
+ ColumnInfoClass * rv ;
24
24
25
25
rv = (ColumnInfoClass * ) malloc (sizeof (ColumnInfoClass ));
26
26
27
- if (rv ) {
27
+ if (rv )
28
+ {
28
29
rv -> num_fields = 0 ;
29
30
rv -> name = NULL ;
30
31
rv -> adtid = NULL ;
@@ -37,28 +38,28 @@ ColumnInfoClass *rv;
37
38
}
38
39
39
40
void
40
- CI_Destructor (ColumnInfoClass * self )
41
+ CI_Destructor (ColumnInfoClass * self )
41
42
{
42
43
CI_free_memory (self );
43
44
44
45
free (self );
45
46
}
46
47
47
- /* Read in field descriptions.
48
- If self is not null, then also store the information.
48
+ /* Read in field descriptions.
49
+ If self is not null, then also store the information.
49
50
If self is null, then just read, don't store.
50
51
*/
51
52
char
52
- CI_read_fields (ColumnInfoClass * self , ConnectionClass * conn )
53
+ CI_read_fields (ColumnInfoClass * self , ConnectionClass * conn )
53
54
{
54
- Int2 lf ;
55
- int new_num_fields ;
56
- Oid new_adtid ;
57
- Int2 new_adtsize ;
58
- Int4 new_atttypmod = -1 ;
59
- char new_field_name [MAX_MESSAGE_LEN + 1 ];
60
- SocketClass * sock ;
61
- ConnInfo * ci ;
55
+ Int2 lf ;
56
+ int new_num_fields ;
57
+ Oid new_adtid ;
58
+ Int2 new_adtsize ;
59
+ Int4 new_atttypmod = -1 ;
60
+ char new_field_name [MAX_MESSAGE_LEN + 1 ];
61
+ SocketClass * sock ;
62
+ ConnInfo * ci ;
62
63
63
64
sock = CC_get_socket (conn );
64
65
ci = & conn -> connInfo ;
@@ -68,24 +69,27 @@ ConnInfo *ci;
68
69
69
70
mylog ("num_fields = %d\n" , new_num_fields );
70
71
71
- if (self ) { /* according to that allocate memory */
72
+ if (self )
73
+ { /* according to that allocate memory */
72
74
CI_set_num_fields (self , new_num_fields );
73
75
}
74
76
75
77
/* now read in the descriptions */
76
- for (lf = 0 ; lf < new_num_fields ; lf ++ ) {
78
+ for (lf = 0 ; lf < new_num_fields ; lf ++ )
79
+ {
77
80
78
81
SOCK_get_string (sock , new_field_name , MAX_MESSAGE_LEN );
79
82
new_adtid = (Oid ) SOCK_get_int (sock , 4 );
80
83
new_adtsize = (Int2 ) SOCK_get_int (sock , 2 );
81
84
82
- /* If 6.4 protocol, then read the atttypmod field */
83
- if (PG_VERSION_GE (conn , 6.4 )) {
85
+ /* If 6.4 protocol, then read the atttypmod field */
86
+ if (PG_VERSION_GE (conn , 6.4 ))
87
+ {
84
88
85
89
mylog ("READING ATTTYPMOD\n" );
86
90
new_atttypmod = (Int4 ) SOCK_get_int (sock , 4 );
87
91
88
- /* Subtract the header length */
92
+ /* Subtract the header length */
89
93
new_atttypmod -= 4 ;
90
94
if (new_atttypmod < 0 )
91
95
new_atttypmod = -1 ;
@@ -104,17 +108,18 @@ ConnInfo *ci;
104
108
105
109
106
110
void
107
- CI_free_memory (ColumnInfoClass * self )
111
+ CI_free_memory (ColumnInfoClass * self )
108
112
{
109
- register Int2 lf ;
110
- int num_fields = self -> num_fields ;
113
+ register Int2 lf ;
114
+ int num_fields = self -> num_fields ;
111
115
112
- for (lf = 0 ; lf < num_fields ; lf ++ ) {
113
- if ( self -> name [lf ])
114
- free (self -> name [lf ]);
116
+ for (lf = 0 ; lf < num_fields ; lf ++ )
117
+ {
118
+ if (self -> name [lf ])
119
+ free (self -> name [lf ]);
115
120
}
116
121
117
- /* Safe to call even if null */
122
+ /* Safe to call even if null */
118
123
free (self -> name );
119
124
free (self -> adtid );
120
125
free (self -> adtsize );
@@ -124,35 +129,33 @@ int num_fields = self->num_fields;
124
129
}
125
130
126
131
void
127
- CI_set_num_fields (ColumnInfoClass * self , int new_num_fields )
132
+ CI_set_num_fields (ColumnInfoClass * self , int new_num_fields )
128
133
{
129
- CI_free_memory (self ); /* always safe to call */
134
+ CI_free_memory (self ); /* always safe to call */
130
135
131
136
self -> num_fields = new_num_fields ;
132
137
133
- self -> name = (char * * ) malloc (sizeof (char * ) * self -> num_fields );
134
- self -> adtid = (Oid * ) malloc (sizeof (Oid ) * self -> num_fields );
135
- self -> adtsize = (Int2 * ) malloc (sizeof (Int2 ) * self -> num_fields );
138
+ self -> name = (char * * ) malloc (sizeof (char * ) * self -> num_fields );
139
+ self -> adtid = (Oid * ) malloc (sizeof (Oid ) * self -> num_fields );
140
+ self -> adtsize = (Int2 * ) malloc (sizeof (Int2 ) * self -> num_fields );
136
141
self -> display_size = (Int2 * ) malloc (sizeof (Int2 ) * self -> num_fields );
137
142
self -> atttypmod = (Int4 * ) malloc (sizeof (Int4 ) * self -> num_fields );
138
143
}
139
144
140
145
void
141
- CI_set_field_info (ColumnInfoClass * self , int field_num , char * new_name ,
142
- Oid new_adtid , Int2 new_adtsize , Int4 new_atttypmod )
146
+ CI_set_field_info (ColumnInfoClass * self , int field_num , char * new_name ,
147
+ Oid new_adtid , Int2 new_adtsize , Int4 new_atttypmod )
143
148
{
144
-
149
+
145
150
/* check bounds */
146
- if ((field_num < 0 ) || (field_num >= self -> num_fields )) {
151
+ if ((field_num < 0 ) || (field_num >= self -> num_fields ))
147
152
return ;
148
- }
149
153
150
154
/* store the info */
151
- self -> name [field_num ] = strdup (new_name );
155
+ self -> name [field_num ] = strdup (new_name );
152
156
self -> adtid [field_num ] = new_adtid ;
153
157
self -> adtsize [field_num ] = new_adtsize ;
154
158
self -> atttypmod [field_num ] = new_atttypmod ;
155
159
156
160
self -> display_size [field_num ] = 0 ;
157
161
}
158
-
0 commit comments