7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/tid.c,v 1.11 1999/07/17 20:18:00 momjian Exp $
10
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/tid.c,v 1.12 1999/10/11 06:28:26 inoue Exp $
11
11
*
12
12
* NOTES
13
13
* input routine largely stolen from boxin().
28
28
* ----------------------------------------------------------------
29
29
*/
30
30
ItemPointer
31
- tidin (char * str )
31
+ tidin (const char * str )
32
32
{
33
- char * p ,
33
+ const char * p ,
34
34
* coord [NTIDARGS ];
35
35
int i ;
36
36
ItemPointer result ;
@@ -45,8 +45,12 @@ tidin(char *str)
45
45
if (* p == DELIM || (* p == LDELIM && !i ))
46
46
coord [i ++ ] = p + 1 ;
47
47
48
- if (i < NTIDARGS - 1 )
48
+ /* if (i < NTIDARGS - 1) */
49
+ if (i < NTIDARGS )
50
+ {
51
+ elog (ERROR , "%s invalid tid format" , str );
49
52
return NULL ;
53
+ }
50
54
51
55
blockNumber = (BlockNumber ) atoi (coord [0 ]);
52
56
offsetNumber = (OffsetNumber ) atoi (coord [1 ]);
@@ -70,6 +74,14 @@ tidout(ItemPointer itemPtr)
70
74
BlockId blockId ;
71
75
char buf [32 ];
72
76
char * str ;
77
+ static char * invalidTid = "()" ;
78
+
79
+ if (!itemPtr || !ItemPointerIsValid (itemPtr ))
80
+ {
81
+ str = palloc (strlen (invalidTid ));
82
+ strcpy (str , invalidTid );
83
+ return str ;
84
+ }
73
85
74
86
blockId = & (itemPtr -> ip_blkid );
75
87
@@ -83,3 +95,113 @@ tidout(ItemPointer itemPtr)
83
95
84
96
return str ;
85
97
}
98
+
99
+ /*****************************************************************************
100
+ * PUBLIC ROUTINES *
101
+ *****************************************************************************/
102
+
103
+ bool
104
+ tideq (ItemPointer arg1 , ItemPointer arg2 )
105
+ {
106
+ if ((!arg1 ) || (!arg2 ))
107
+ {
108
+ return false;
109
+ }
110
+
111
+ return ( BlockIdGetBlockNumber (& (arg1 -> ip_blkid )) ==
112
+ BlockIdGetBlockNumber (& (arg2 -> ip_blkid )) &&
113
+ arg1 -> ip_posid == arg2 -> ip_posid );
114
+ }
115
+
116
+ bool
117
+ tidne (ItemPointer arg1 , ItemPointer arg2 )
118
+ {
119
+ if ((!arg1 ) || (!arg2 ))
120
+ {
121
+ return false;
122
+ }
123
+ return ( BlockIdGetBlockNumber (& (arg1 -> ip_blkid )) !=
124
+ BlockIdGetBlockNumber (& (arg2 -> ip_blkid )) ||
125
+ arg1 -> ip_posid != arg2 -> ip_posid );
126
+ }
127
+
128
+ text *
129
+ tid_text (ItemPointer tid )
130
+ {
131
+ char * str ;
132
+
133
+ if (!tid ) return (text * )NULL ;
134
+ str = tidout (tid );
135
+
136
+ return textin (str );
137
+ } /* tid_text() */
138
+
139
+ ItemPointer
140
+ text_tid (const text * string )
141
+ {
142
+ ItemPointer result ;
143
+ char * str ;
144
+
145
+ if (!string ) return (ItemPointer )0 ;
146
+
147
+ str = textout (string );
148
+ result = tidin (str );
149
+ pfree (str );
150
+
151
+ return result ;
152
+ } /* text_tid() */
153
+
154
+
155
+ /*
156
+ * Functions to get latest tid of a specified tuple.
157
+ * Maybe these implementations is moved
158
+ * to another place
159
+ */
160
+ #include <utils/relcache.h>
161
+ ItemPointer
162
+ currtid_byreloid (Oid reloid , ItemPointer tid )
163
+ {
164
+ ItemPointer result = NULL , ret ;
165
+ Relation rel ;
166
+
167
+ result = (ItemPointer ) palloc (sizeof (ItemPointerData ));
168
+ ItemPointerSetInvalid (result );
169
+ if (rel = heap_open (reloid , AccessShareLock ), rel )
170
+ {
171
+ ret = heap_get_latest_tid (rel , SnapshotNow , tid );
172
+ if (ret )
173
+ ItemPointerCopy (ret , result );
174
+ heap_close (rel , AccessShareLock );
175
+ }
176
+ else
177
+ elog (ERROR , "Relation %u not found" , reloid );
178
+
179
+ return result ;
180
+ } /* currtid_byreloid() */
181
+
182
+ ItemPointer
183
+ currtid_byrelname (const text * relname , ItemPointer tid )
184
+ {
185
+ ItemPointer result = NULL , ret ;
186
+ char * str ;
187
+ Relation rel ;
188
+
189
+ if (!relname ) return result ;
190
+
191
+ str = textout (relname );
192
+
193
+ result = (ItemPointer ) palloc (sizeof (ItemPointerData ));
194
+ ItemPointerSetInvalid (result );
195
+ if (rel = heap_openr (str , AccessShareLock ), rel )
196
+ {
197
+ ret = heap_get_latest_tid (rel , SnapshotNow , tid );
198
+ if (ret )
199
+ ItemPointerCopy (ret , result );
200
+ heap_close (rel , AccessShareLock );
201
+ }
202
+ else
203
+ elog (ERROR , "Relation %s not found" , relname );
204
+ pfree (str );
205
+
206
+ return result ;
207
+ } /* currtid_byrelname() */
0 commit comments