~ubuntu-branches/debian/lenny/freetds/lenny

« back to all changes in this revision

Viewing changes to doc/doc/freetds-0.82/reference/a00327.html

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2008-08-02 11:49:53 UTC
  • mfrom: (2.1.10 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080802114953-0qdeowgl63k42n2c
Tags: 0.82-4
* Fix a typo in the freetds-common description, ugh
* Versioned replaces of libct4 by freetds-common, since the current one
  obviously doesn't have overlapping files.
* tdsodbc: check for /var/lib/odbc existence before removing it in the
  postinst, since there are cases where it won't exist on upgrade (i.e.,
  if the driver was never enabled in the first place).  Closes: #493303.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 
2
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
 
3
<title>FreeTDS API: /usr/local/users/home/jklowden/projects/releases/freetds/0.82/src/dblib/buffering.h Source File</title>
 
4
<link href="doxygen.css" rel="stylesheet" type="text/css">
 
5
</head><body>
 
6
<!-- Generated by Doxygen 1.4.1 -->
 
7
<div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div>
 
8
<div class="nav">
 
9
<a class="el" href="dir_000002.html">src</a>&nbsp;/&nbsp;<a class="el" href="dir_000006.html">dblib</a></div>
 
10
<h1>buffering.h</h1><div class="fragment"><pre class="fragment">00001 <span class="keyword">typedef</span> <span class="keyword">struct </span>dblib_buffer_row {
 
11
00003         <a class="code" href="a00143.html">TDSRESULTINFO</a> *resinfo;
 
12
00005         <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *row_data;
 
13
00007         DBINT row;
 
14
00009         TDS_INT *sizes;
 
15
00010 } DBLIB_BUFFER_ROW;
 
16
00011 
 
17
00012 <span class="keyword">static</span> <span class="keywordtype">void</span> buffer_struct_print(<span class="keyword">const</span> DBPROC_ROWBUF *buf);
 
18
00013 <span class="keyword">static</span> <span class="keywordtype">int</span> buffer_save_row(DBPROCESS *dbproc);
 
19
00014 <span class="keyword">static</span> DBLIB_BUFFER_ROW* buffer_row_address(<span class="keyword">const</span> DBPROC_ROWBUF * buf, <span class="keywordtype">int</span> idx);
 
20
00015 
 
21
00045 <span class="keyword">static</span> <span class="keywordtype">int</span>
 
22
00046 buffer_count(<span class="keyword">const</span> DBPROC_ROWBUF *buf)
 
23
00047 {
 
24
00048         <span class="keywordflow">return</span> (buf-&gt;head &gt; buf-&gt;tail) ?
 
25
00049                 buf-&gt;head - buf-&gt;tail :                         <span class="comment">/* |...TddddH....| */</span>
 
26
00050                 buf-&gt;capacity - (buf-&gt;tail - buf-&gt;head);        <span class="comment">/* |ddddH....Tddd| */</span>
 
27
00051 }
 
28
00052  
 
29
00056 <span class="keyword">static</span> <span class="keywordtype">int</span>
 
30
00057 buffer_is_full(<span class="keyword">const</span> DBPROC_ROWBUF *buf)
 
31
00058 {
 
32
00059         <span class="keywordflow">return</span> buf-&gt;capacity == buffer_count(buf) &amp;&amp; buf-&gt;capacity &gt; 1;
 
33
00060 }
 
34
00061 
 
35
00062 <span class="preprocessor">#ifndef NDEBUG</span>
 
36
00063 <span class="preprocessor"></span><span class="keyword">static</span> <span class="keywordtype">int</span>
 
37
00064 buffer_index_valid(<span class="keyword">const</span> DBPROC_ROWBUF *buf, <span class="keywordtype">int</span> idx)
 
38
00065 {
 
39
00066         <span class="keywordflow">if</span> (buf-&gt;tail &lt;= buf-&gt;head)
 
40
00067                 if (buf-&gt;head &lt;= idx &amp;&amp; idx &lt;= buf-&gt;tail)
 
41
00068                         return 1;
 
42
00069         
 
43
00070         if (0 &lt;= idx &amp;&amp; idx &lt;= buf-&gt;head)
 
44
00071                 return 1;
 
45
00072         
 
46
00073         if (buf-&gt;tail &lt;= idx &amp;&amp; idx &lt; buf-&gt;capacity)
 
47
00074                 return 1;
 
48
00075 #if 0   
 
49
00076         printf("buffer_index_valid: idx = %d\n", idx);
 
50
00077         buffer_struct_print(buf);
 
51
00078 #endif
 
52
00079         return 0;       
 
53
00080 }
 
54
00081 #endif
 
55
00082 
 
56
00083 static <span class="keywordtype">void</span>
 
57
00084 buffer_free_row(DBLIB_BUFFER_ROW *row)
 
58
00085 {
 
59
00086         <span class="keywordflow">if</span> (row-&gt;sizes)
 
60
00087                 TDS_ZERO_FREE(row-&gt;sizes);
 
61
00088         if (row-&gt;row_data) {
 
62
00089                 tds_free_row(row-&gt;resinfo, row-&gt;row_data);
 
63
00090                 row-&gt;row_data = NULL;
 
64
00091         }
 
65
00092         tds_free_results(row-&gt;resinfo);
 
66
00093         row-&gt;resinfo = NULL;
 
67
00094 }
 
68
00095  
 
69
00096 <span class="comment">/*</span>
 
70
00097 <span class="comment"> * Buffer is freed at slightly odd points, whenever</span>
 
71
00098 <span class="comment"> * capacity changes: </span>
 
72
00099 <span class="comment"> * </span>
 
73
00100 <span class="comment"> * 1. When setting capacity, to release prior buffer.  </span>
 
74
00101 <span class="comment"> * 2. By dbresults.  When called the second time, it has to </span>
 
75
00102 <span class="comment"> * release prior storage because the new resultset will have</span>
 
76
00103 <span class="comment"> * a different width.  </span>
 
77
00104 <span class="comment"> * 3. By dbclose(), else open/close/open would leak.  </span>
 
78
00105 <span class="comment"> */</span>
 
79
00106 <span class="keyword">static</span> <span class="keywordtype">void</span>
 
80
00107 buffer_free(DBPROC_ROWBUF *buf)
 
81
00108 {
 
82
00109         <span class="keywordflow">if</span> (buf-&gt;rows != NULL) {
 
83
00110                 <span class="keywordtype">int</span> i;
 
84
00111                 <span class="keywordflow">for</span> (i = 0; i &lt; buf-&gt;capacity; ++i)
 
85
00112                         buffer_free_row(&amp;buf-&gt;rows[i]);
 
86
00113                 TDS_ZERO_FREE(buf-&gt;rows);
 
87
00114         }
 
88
00115 }
 
89
00116 
 
90
00117 <span class="comment">/*</span>
 
91
00118 <span class="comment"> * When no rows are currently buffered (and the buffer is allocated)</span>
 
92
00119 <span class="comment"> * set the indices to their initial postions.</span>
 
93
00120 <span class="comment"> */</span>
 
94
00121 static <span class="keywordtype">void</span>
 
95
00122 buffer_reset(DBPROC_ROWBUF *buf)
 
96
00123 {
 
97
00124         buf-&gt;head = 0;
 
98
00125         buf-&gt;current = buf-&gt;tail = buf-&gt;capacity;
 
99
00126 }
 
100
00127 
 
101
00128 <span class="keyword">static</span> <span class="keywordtype">int</span>
 
102
00129 buffer_idx_increment(<span class="keyword">const</span> DBPROC_ROWBUF *buf, <span class="keywordtype">int</span> idx)
 
103
00130 {
 
104
00131         <span class="keywordflow">if</span> (++idx &gt;= buf-&gt;capacity) { 
 
105
00132                 idx = 0;
 
106
00133         }
 
107
00134         <span class="keywordflow">return</span> idx;
 
108
00135 }
 
109
00136 
 
110
00141 <span class="keyword">static</span> DBLIB_BUFFER_ROW*
 
111
00142 buffer_row_address(<span class="keyword">const</span> DBPROC_ROWBUF * buf, <span class="keywordtype">int</span> idx)
 
112
00143 {
 
113
00144         <span class="keywordflow">if</span> (!(idx &gt;= 0 &amp;&amp; idx &lt; buf-&gt;capacity)) {
 
114
00145                 printf(<span class="stringliteral">"idx is %d:\n"</span>, idx);
 
115
00146                 buffer_struct_print(buf);
 
116
00147                 assert(idx &gt;= 0);
 
117
00148                 assert(idx &lt; buf-&gt;capacity);
 
118
00149         }
 
119
00150         
 
120
00151         <span class="keywordflow">return</span> &amp;(buf-&gt;rows[idx]);
 
121
00152 }
 
122
00153 
 
123
00157 <span class="keyword">static</span> DBINT
 
124
00158 buffer_idx2row(<span class="keyword">const</span> DBPROC_ROWBUF *buf, <span class="keywordtype">int</span> idx)
 
125
00159 {
 
126
00160         <span class="keywordflow">return</span> buffer_row_address(buf, idx)-&gt;row;
 
127
00161 }
 
128
00162 
 
129
00166 <span class="keyword">static</span> <span class="keywordtype">int</span>
 
130
00167 buffer_row2idx(<span class="keyword">const</span> DBPROC_ROWBUF *buf, <span class="keywordtype">int</span> row_number)
 
131
00168 {
 
132
00169         <span class="keywordtype">int</span> i, ii, idx = -1;
 
133
00170         
 
134
00171         <span class="keywordflow">if</span> (buf-&gt;tail == buf-&gt;capacity) {
 
135
00172                 assert (buf-&gt;head == 0);
 
136
00173                 <span class="keywordflow">return</span> -1;      <span class="comment">/* no rows buffered */</span>
 
137
00174         }
 
138
00175         
 
139
00176         <span class="comment">/* </span>
 
140
00177 <span class="comment">         * March through the buffers from tail to head, stop if we find our row.  </span>
 
141
00178 <span class="comment">         * A full queue is indicated by tail == head (which means we can't write).</span>
 
142
00179 <span class="comment">         */</span>
 
143
00180         <span class="keywordflow">for</span> (ii=0, i = buf-&gt;tail; i != buf-&gt;head || ii == 0; i = buffer_idx_increment(buf, i)) {
 
144
00181                 <span class="keywordflow">if</span>( buffer_idx2row(buf, i) == row_number) {
 
145
00182                         idx = i;
 
146
00183                         <span class="keywordflow">break</span>;
 
147
00184                 }
 
148
00185                 assert(ii++ &lt; buf-&gt;capacity); <span class="comment">/* prevent infinite loop */</span>
 
149
00186         } 
 
150
00187         
 
151
00188         <span class="keywordflow">return</span> idx;
 
152
00189 }
 
153
00190 
 
154
00196 <span class="keyword">static</span> <span class="keywordtype">void</span>
 
155
00197 buffer_delete_rows(DBPROC_ROWBUF * buf, <span class="keywordtype">int</span> count)
 
156
00198 {
 
157
00199         <span class="keywordtype">int</span> i;
 
158
00200 
 
159
00201         <span class="keywordflow">if</span> (count &lt; 0 || count &gt; buffer_count(buf)) {
 
160
00202                 count = buffer_count(buf);
 
161
00203         }
 
162
00204 
 
163
00205         <span class="keywordflow">for</span> (i=0; i &lt; count; i++) {
 
164
00206                 <span class="keywordflow">if</span> (buf-&gt;tail &lt; buf-&gt;capacity)
 
165
00207                         buffer_free_row(&amp;buf-&gt;rows[i]);
 
166
00208                 buf-&gt;tail = buffer_idx_increment(buf, buf-&gt;tail);
 
167
00209                 <span class="comment">/* </span>
 
168
00210 <span class="comment">                 * If deleting rows from the buffer catches the tail to the head, </span>
 
169
00211 <span class="comment">                 * return to the initial postion.  Otherwise, it will look full.</span>
 
170
00212 <span class="comment">                 */</span>
 
171
00213                 if (buf-&gt;tail == buf-&gt;head) {
 
172
00214                         buffer_reset(buf);
 
173
00215                         <span class="keywordflow">break</span>;
 
174
00216                 }
 
175
00217         }
 
176
00218 <span class="preprocessor">#if 0</span>
 
177
00219 <span class="preprocessor"></span>        buffer_struct_print(buf);
 
178
00220 <span class="preprocessor">#endif</span>
 
179
00221 <span class="preprocessor"></span>}
 
180
00222 
 
181
00223 <span class="keyword">static</span> <span class="keywordtype">void</span>
 
182
00224 buffer_transfer_bound_data(DBPROC_ROWBUF *buf, TDS_INT res_type, TDS_INT compute_id, DBPROCESS * dbproc, <span class="keywordtype">int</span> idx)
 
183
00225 {
 
184
00226         <span class="keywordtype">int</span> i;
 
185
00227         <span class="keywordtype">int</span> srctype, desttype;
 
186
00228         BYTE *src;
 
187
00229         <span class="keyword">const</span> DBLIB_BUFFER_ROW *row;
 
188
00230 
 
189
00231         tdsdump_log(TDS_DBG_FUNC, <span class="stringliteral">"buffer_transfer_bound_data(%p %d %d %p %d)\n"</span>, buf, res_type, compute_id, dbproc, idx);
 
190
00232         assert(buffer_index_valid(buf, idx));
 
191
00233 
 
192
00234         row = buffer_row_address(buf, idx);
 
193
00235         assert(row-&gt;resinfo);
 
194
00236 
 
195
00237         <span class="keywordflow">for</span> (i = 0; i &lt; row-&gt;resinfo-&gt;num_cols; i++) {
 
196
00238                 DBINT srclen;
 
197
00239                 <a class="code" href="a00140.html">TDSCOLUMN</a> *curcol = row-&gt;resinfo-&gt;columns[i];
 
198
00240                 
 
199
00241                 <span class="keywordflow">if</span> (row-&gt;sizes)
 
200
00242                         curcol-&gt;column_cur_size = row-&gt;sizes[i];
 
201
00243 
 
202
00244                 if (curcol-&gt;column_nullbind) {
 
203
00245                         <span class="keywordflow">if</span> (curcol-&gt;<a class="code" href="a00140.html#o9">column_cur_size</a> &lt; 0) {
 
204
00246                                 *(DBINT *)(curcol-&gt;<a class="code" href="a00140.html#o20">column_nullbind</a>) = -1;
 
205
00247                         } <span class="keywordflow">else</span> {
 
206
00248                                 *(DBINT *)(curcol-&gt;<a class="code" href="a00140.html#o20">column_nullbind</a>) = 0;
 
207
00249                         }
 
208
00250                 }
 
209
00251                 <span class="keywordflow">if</span> (!curcol-&gt;<a class="code" href="a00140.html#o32">column_varaddr</a>)
 
210
00252                         continue;
 
211
00253 
 
212
00254                 if (row-&gt;row_data)
 
213
00255                         src = &amp;row-&gt;row_data[curcol-&gt;column_data - row-&gt;resinfo-&gt;current_row];
 
214
00256                 else
 
215
00257                         src = curcol-&gt;column_data;
 
216
00258                 srclen = curcol-&gt;column_cur_size;
 
217
00259                 if (is_blob_type(curcol-&gt;column_type)) {
 
218
00260                         src = (BYTE *) ((<a class="code" href="a00139.html">TDSBLOB</a> *) src)-&gt;textvalue;
 
219
00261                 }
 
220
00262                 desttype = _db_get_server_type(curcol-&gt;<a class="code" href="a00140.html#o7">column_bindtype</a>);
 
221
00263                 srctype = <a class="code" href="a00287.html#ga17">tds_get_conversion_type</a>(curcol-&gt;<a class="code" href="a00140.html#o30">column_type</a>, curcol-&gt;<a class="code" href="a00140.html#o26">column_size</a>);
 
222
00264 
 
223
00265                 <span class="keywordflow">if</span> (srclen &lt;= 0) {
 
224
00266                         <span class="keywordflow">if</span> (srclen == 0 || !curcol-&gt;<a class="code" href="a00140.html#o20">column_nullbind</a>)
 
225
00267                                 dbgetnull(dbproc, curcol-&gt;column_bindtype, curcol-&gt;column_bindlen,
 
226
00268                                                 (BYTE *) curcol-&gt;column_varaddr);
 
227
00269                 } else {
 
228
00270                         copy_data_to_host_var(dbproc, srctype, src, srclen, desttype, 
 
229
00271                                                 (BYTE *) curcol-&gt;<a class="code" href="a00140.html#o32">column_varaddr</a>,  curcol-&gt;<a class="code" href="a00140.html#o6">column_bindlen</a>,
 
230
00272                                                          curcol-&gt;<a class="code" href="a00140.html#o7">column_bindtype</a>, curcol-&gt;<a class="code" href="a00140.html#o20">column_nullbind</a>);
 
231
00273                 }
 
232
00274         }
 
233
00275 
 
234
00276         <span class="comment">/*</span>
 
235
00277 <span class="comment">         * This function always bumps current.  Usually, it's called </span>
 
236
00278 <span class="comment">         * by dbnextrow(), so bumping current is a pretty obvious choice.  </span>
 
237
00279 <span class="comment">         * It can also be called by dbgetrow(), but that function also </span>
 
238
00280 <span class="comment">         * causes the bump.  If you call dbgetrow() for row N, a subsequent</span>
 
239
00281 <span class="comment">         * call to dbnextrow() yields N+1.  </span>
 
240
00282 <span class="comment">         */</span>
 
241
00283         buf-&gt;current = buffer_idx_increment(buf, buf-&gt;current);
 
242
00284 
 
243
00285 }       <span class="comment">/* end buffer_transfer_bound_data()  */</span>
 
244
00286 
 
245
00287 <span class="keyword">static</span> <span class="keywordtype">void</span> 
 
246
00288 buffer_struct_print(<span class="keyword">const</span> DBPROC_ROWBUF *buf)
 
247
00289 {
 
248
00290         assert(buf);
 
249
00291 
 
250
00292         printf(<span class="stringliteral">"\t%d rows in buffer\n"</span>,         buffer_count(buf));
 
251
00293         
 
252
00294         printf(<span class="stringliteral">"\thead = %d\t"</span>,                 buf-&gt;head);
 
253
00295         printf(<span class="stringliteral">"\ttail = %d\t"</span>,                 buf-&gt;tail);
 
254
00296         printf(<span class="stringliteral">"\tcurrent = %d\n"</span>,              buf-&gt;current);
 
255
00297         printf(<span class="stringliteral">"\tcapacity = %d\t"</span>,             buf-&gt;capacity);
 
256
00298         printf(<span class="stringliteral">"\thead row number = %d\n"</span>,      buf-&gt;received);
 
257
00299 }
 
258
00300 
 
259
00301 <span class="comment">/* * * Functions called only by public db-lib API take DBPROCESS* * */</span>
 
260
00302 
 
261
00319 <span class="keyword">static</span> <span class="keywordtype">int</span>
 
262
00320 buffer_current_index(<span class="keyword">const</span> DBPROCESS *dbproc)
 
263
00321 {
 
264
00322         <span class="keyword">const</span> DBPROC_ROWBUF *buf = &amp;dbproc-&gt;row_buf;
 
265
00323 <span class="preprocessor">#if 0</span>
 
266
00324 <span class="preprocessor"></span>        buffer_struct_print(buf);
 
267
00325 <span class="preprocessor">#endif</span>
 
268
00326 <span class="preprocessor"></span>        <span class="keywordflow">if</span> (buf-&gt;capacity &lt;= 1) <span class="comment">/* no buffering */</span>
 
269
00327                 return -1;
 
270
00328         if (buf-&gt;current == buf-&gt;head || buf-&gt;current == buf-&gt;capacity)
 
271
00329                 return -1;
 
272
00330                 
 
273
00331         assert(buf-&gt;current &gt;= 0);
 
274
00332         assert(buf-&gt;current &lt; buf-&gt;capacity);
 
275
00333         
 
276
00334         if( buf-&gt;tail &lt; buf-&gt;head) {
 
277
00335                 assert(buf-&gt;tail &lt; buf-&gt;current);
 
278
00336                 assert(buf-&gt;current &lt; buf-&gt;head);
 
279
00337         } <span class="keywordflow">else</span> {
 
280
00338                 <span class="keywordflow">if</span> (buf-&gt;current &gt; buf-&gt;head)
 
281
00339                         assert(buf-&gt;current &gt; buf-&gt;tail);
 
282
00340         }
 
283
00341         return buf-&gt;current;
 
284
00342 }
 
285
00343 
 
286
00344 <span class="comment">/*</span>
 
287
00345 <span class="comment"> * Normally called by dbsetopt() to prepare for buffering</span>
 
288
00346 <span class="comment"> * Called with nrows == 0 by dbopen to safely set buf-&gt;rows to NULL.  </span>
 
289
00347 <span class="comment"> */</span>
 
290
00348 static <span class="keywordtype">void</span>
 
291
00349 buffer_set_capacity(DBPROCESS *dbproc, <span class="keywordtype">int</span> nrows)
 
292
00350 {
 
293
00351         DBPROC_ROWBUF *buf = &amp;dbproc-&gt;row_buf;
 
294
00352         
 
295
00353         buffer_free(buf);
 
296
00354 
 
297
00355         memset(buf, 0, <span class="keyword">sizeof</span>(DBPROC_ROWBUF));
 
298
00356 
 
299
00357         <span class="keywordflow">if</span> (0 == nrows) {
 
300
00358                 buf-&gt;capacity = 1;
 
301
00359                 <span class="keywordflow">return</span>;
 
302
00360         }
 
303
00361 
 
304
00362         assert(0 &lt; nrows);
 
305
00363 
 
306
00364         buf-&gt;capacity = nrows;
 
307
00365 }
 
308
00366 
 
309
00367 <span class="comment">/*</span>
 
310
00368 <span class="comment"> * Called only by dbresults(); capacity must be &gt;= 1. </span>
 
311
00369 <span class="comment"> * Sybase's documents say dbresults() cannot return FAIL if the prior calls worked, </span>
 
312
00370 <span class="comment"> * which is a little strange, because (for FreeTDS, at least), dbresults</span>
 
313
00371 <span class="comment"> * is when we learn about the result set's width.  Without that information, we</span>
 
314
00372 <span class="comment"> * can't allocate memory for the buffer.  But if we *fail* to allocate memory, </span>
 
315
00373 <span class="comment"> * we're not to communicate it back to the caller?   </span>
 
316
00374 <span class="comment"> */</span>
 
317
00375 <span class="keyword">static</span> <span class="keywordtype">void</span>
 
318
00376 buffer_alloc(DBPROCESS *dbproc)
 
319
00377 {
 
320
00378         DBPROC_ROWBUF *buf = &amp;dbproc-&gt;row_buf;
 
321
00379         
 
322
00380         <span class="comment">/* Call this function only after setting capacity. */</span>
 
323
00381 
 
324
00382         assert(buf);
 
325
00383         assert(buf-&gt;capacity &gt; 0);
 
326
00384         assert(buf-&gt;rows == NULL);
 
327
00385         
 
328
00386         buf-&gt;rows = (DBLIB_BUFFER_ROW *) calloc(buf-&gt;capacity, <span class="keyword">sizeof</span>(DBLIB_BUFFER_ROW));
 
329
00387         
 
330
00388         assert(buf-&gt;rows);
 
331
00389         
 
332
00390         buffer_reset(buf);
 
333
00391         
 
334
00392         buf-&gt;received = 0;
 
335
00393 }
 
336
00394 
 
337
00399 <span class="keyword">static</span> <span class="keywordtype">int</span>
 
338
00400 buffer_add_row(DBPROCESS *dbproc, <a class="code" href="a00143.html">TDSRESULTINFO</a> *resinfo)
 
339
00401 {
 
340
00402         DBPROC_ROWBUF *buf = &amp;dbproc-&gt;row_buf;
 
341
00403         DBLIB_BUFFER_ROW *row;
 
342
00404         <span class="keywordtype">int</span> i;
 
343
00405 
 
344
00406         assert(buf-&gt;capacity &gt;= 0);
 
345
00407 
 
346
00408         <span class="keywordflow">if</span> (buffer_is_full(buf))
 
347
00409                 return -1;
 
348
00410 
 
349
00411         <span class="comment">/* initial condition is head == 0 and tail == capacity */</span>
 
350
00412         if (buf-&gt;tail == buf-&gt;capacity) {
 
351
00413                 <span class="comment">/* bumping this tail will set it to zero */</span>
 
352
00414                 assert(buf-&gt;head == 0);
 
353
00415                 buf-&gt;tail = buffer_idx_increment(buf, buf-&gt;tail);
 
354
00416         }
 
355
00417 
 
356
00418         row = buffer_row_address(buf, buf-&gt;head);
 
357
00419 
 
358
00420         <span class="comment">/* bump the row number, write it, and move the data to head */</span>
 
359
00421         <span class="keywordflow">if</span> (row-&gt;resinfo) {
 
360
00422                 tds_free_row(row-&gt;resinfo, row-&gt;row_data);
 
361
00423                 tds_free_results(row-&gt;resinfo);
 
362
00424         }
 
363
00425         row-&gt;row = ++buf-&gt;received;
 
364
00426         ++resinfo-&gt;ref_count;
 
365
00427         row-&gt;resinfo = resinfo;
 
366
00428         row-&gt;row_data = NULL;
 
367
00429         <span class="keywordflow">if</span> (row-&gt;sizes)
 
368
00430                 free(row-&gt;sizes);
 
369
00431         row-&gt;sizes = (TDS_INT *) calloc(resinfo-&gt;num_cols, sizeof(TDS_INT));
 
370
00432         for (i = 0; i &lt; resinfo-&gt;num_cols; ++i)
 
371
00433                 row-&gt;sizes[i] = resinfo-&gt;columns[i]-&gt;column_cur_size;
 
372
00434 
 
373
00435         <span class="comment">/* update current, bump the head */</span>
 
374
00436         buf-&gt;current = buf-&gt;head;
 
375
00437         buf-&gt;head = buffer_idx_increment(buf, buf-&gt;head);
 
376
00438 
 
377
00439         return buf-&gt;current;
 
378
00440 }
 
379
00441 
 
380
00442 static <span class="keywordtype">int</span>
 
381
00443 buffer_save_row(DBPROCESS *dbproc)
 
382
00444 {
 
383
00445         DBPROC_ROWBUF *buf = &amp;dbproc-&gt;row_buf;
 
384
00446         DBLIB_BUFFER_ROW *row;
 
385
00447         <span class="keywordtype">int</span> idx = buf-&gt;head - 1;
 
386
00448 
 
387
00449         <span class="keywordflow">if</span> (buf-&gt;capacity &lt;= 1)
 
388
00450                 return SUCCEED;
 
389
00451 
 
390
00452         if (idx &lt; 0)
 
391
00453                 idx = buf-&gt;capacity - 1;
 
392
00454         if (idx &gt;= 0 &amp;&amp; idx &lt; buf-&gt;capacity) {
 
393
00455                 row = &amp;buf-&gt;rows[idx];
 
394
00456 
 
395
00457                 <span class="keywordflow">if</span> (row-&gt;resinfo &amp;&amp; !row-&gt;row_data) {
 
396
00458                         row-&gt;row_data = row-&gt;resinfo-&gt;current_row;
 
397
00459                         <a class="code" href="a00289.html#ga12">tds_alloc_row</a>(row-&gt;resinfo);
 
398
00460                 }
 
399
00461         }
 
400
00462 
 
401
00463         <span class="keywordflow">return</span> SUCCEED;
 
402
00464 }
 
403
00465 
 
404
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Wed May 7 19:22:09 2008 for FreeTDS API by&nbsp;
 
405
<a href="http://www.doxygen.org/index.html">
 
406
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.1 </small></address>
 
407
</body>
 
408
</html>