-
Notifications
You must be signed in to change notification settings - Fork 0
/
cursor.c
395 lines (324 loc) · 10.7 KB
/
cursor.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
#include "cursor.h"
#include <tg_utility.h>
Cursor* cursor_create(INT32 col_num,BOOL read_only)
{
Cursor* cursor = TG_CALLOC_V2(sizeof(Cursor));
return_val_if_fail(cursor && col_num >0, NULL);
cursor->read_only = read_only;
cursor->name_win = cursor_window_create(col_num);
cursor->data_win = cursor_window_create(col_num);
if (cursor->name_win==NULL || cursor->data_win==NULL)
{
cursor_window_destroy(cursor->name_win);
cursor_window_destroy(cursor->data_win);
TG_FREE(cursor);
return NULL;
}
cursor_window_alloc_row(cursor->name_win);
return cursor;
}
CursorWindow* cursor_get_data_window(Cursor* thiz)
{
return_val_if_fail(thiz, NULL);
return thiz->data_win;
}
CursorWindow* cursor_get_name_window(Cursor* thiz)
{
return_val_if_fail(thiz, NULL);
return thiz->name_win;
}
void cursor_destroy(Cursor* cursor)
{
return_if_fail(cursor);
if (cursor->on_destroy)
cursor->on_destroy(cursor);
if (cursor->data_win)
{
cursor_window_destroy(cursor->data_win);
cursor->data_win= NULL;
}
if (cursor->name_win)
{
cursor_window_destroy(cursor->name_win);
cursor->name_win= NULL;
}
TG_FREE(cursor->priv_subclass);
TG_FREE(cursor);
}
INT32 cursor_get_count(Cursor* cursor)
{
return_val_if_fail(cursor&&cursor->data_win,0);
return cursor_window_get_row_num(cursor->data_win);
}
INT32 cursor_get_column_num(Cursor* cursor)
{
return_val_if_fail(cursor&&cursor->name_win,0);
return cursor_window_get_col_num(cursor->data_win);
}
INT32 cursor_get_column_index( Cursor* cursor,const CHAR* col_name)
{
INT32 col_num;
INT32 i=0;
return_val_if_fail(cursor&&cursor->data_win && col_name,0);
col_num = cursor_window_get_col_num(cursor->data_win);
for (i=0;i<col_num;i++)
{
const CHAR* name = cursor_window_get_string(cursor->data_win,0,i);
if (name && strcmp(col_name,name)==0)
return i;
}
return -1;
}
const CHAR* cursor_get_column_name( Cursor* cursor,INT32 col)
{
return_val_if_fail(cursor&&cursor->name_win,NULL);
return cursor_window_get_string(cursor->name_win,0,col);
}
BOOL cursor_set_column_name(Cursor* cursor,INT32 col,const CHAR* col_name)
{
return_val_if_fail(cursor&&cursor->name_win&&col_name,FALSE);
return cursor_window_put_string(cursor->name_win,col,col_name);
}
INT32 cursor_get_position(Cursor* cursor)
{
return_val_if_fail(cursor&&cursor->data_win,0);
return cursor->cur_row;
}
BOOL cursor_move_to_first(Cursor* cursor)
{
return_val_if_fail(cursor&&cursor->data_win,FALSE);
cursor->cur_row=0;
return TRUE;
}
BOOL cursor_move_to_last(Cursor* cursor)
{
INT32 row_num;
return_val_if_fail(cursor&&cursor->data_win,FALSE);
row_num =cursor_window_get_row_num(cursor->data_win);
if (row_num>=1)
cursor->cur_row=row_num-1;
return TRUE;
}
BOOL cursor_move_to_next(Cursor* cursor)
{
INT32 row_num;
return_val_if_fail(cursor&&cursor->data_win,FALSE);
row_num =cursor_window_get_row_num(cursor->data_win);
if (row_num>=1 && cursor->cur_row < row_num-1)
{
cursor->cur_row++;
return TRUE;
}
return FALSE;
}
BOOL cursor_move_to_previous(Cursor* cursor)
{
return_val_if_fail(cursor&&cursor->data_win,FALSE);
if ( cursor->cur_row >0)
{
cursor->cur_row--;
return TRUE;
}
return FALSE;
}
BOOL cursor_move_to_position(Cursor* cursor,INT32 pos)
{
INT32 row_num;
return_val_if_fail(cursor&&cursor->data_win,FALSE);
row_num =cursor_window_get_row_num(cursor->data_win);
return_val_if_fail(row_num>=1,FALSE);
return_val_if_fail(pos <= row_num-1,FALSE);
cursor->cur_row=pos;
return TRUE;
}
BOOL cursor_is_last(const Cursor* cursor)
{
INT32 row_num;
return_val_if_fail(cursor&&cursor->data_win,FALSE);
row_num =cursor_window_get_row_num(cursor->data_win);
return_val_if_fail(row_num>=1,FALSE);
return (cursor->cur_row==row_num-1)?TRUE:FALSE;
}
BOOL cursor_is_first(const Cursor* cursor)
{
return_val_if_fail(cursor&&cursor->data_win,FALSE);
return (cursor->cur_row==0)?TRUE:FALSE;
}
BOOL cursor_get_int(const Cursor* cursor,INT32 column_index,INT64* value)
{
return_val_if_fail(cursor&&cursor->data_win,FALSE);
return cursor_window_get_int(cursor->data_win,cursor->cur_row,column_index,value);
}
BOOL cursor_get_bool(const Cursor* cursor,INT32 column_index,BOOL* value)
{
return_val_if_fail(cursor&&cursor->data_win,FALSE);
return cursor_window_get_bool(cursor->data_win,cursor->cur_row,column_index,value);
}
BOOL cursor_get_double(const Cursor* cursor,INT32 column_index,double* value)
{
return_val_if_fail(cursor&&cursor->data_win,FALSE);
return cursor_window_get_double(cursor->data_win,cursor->cur_row,column_index,value);
}
const CHAR* cursor_get_string(const Cursor* cursor,INT32 column_index)
{
return_val_if_fail(cursor&&cursor->data_win,NULL);
if (cursor->get_string)
{
return cursor->get_string(cursor,column_index);
}
else
{
return cursor_window_get_string(cursor->data_win,cursor->cur_row,column_index);
}
}
const WCHAR* cursor_get_string_16(const Cursor* cursor,INT32 column_index)
{
return_val_if_fail(cursor&&cursor->data_win,NULL);
if (cursor->get_string_16)
{
return cursor->get_string_16(cursor,column_index);
}
else
{
return cursor_window_get_string_16(cursor->data_win,cursor->cur_row,column_index);
}
}
BOOL cursor_get_blob(const Cursor* cursor,INT32 column_index,void** data,INT32* output_len)
{
BOOL ret;
UINT8 type;
return_val_if_fail(cursor&&cursor->data_win,FALSE);
ret= cursor_window_get_value(cursor->data_win,cursor->cur_row,column_index,&type,(void**)data,output_len);
return (ret && (type==FIELD_TYPE_BLOB|| type==FIELD_TYPE_NULL))?TRUE:FALSE;
}
BOOL cursor_is_null(const Cursor* cursor,INT32 column_index)
{
BOOL ret;
UINT8 type;
void* data=NULL;
INT32 len=0;
return_val_if_fail(cursor&&cursor->data_win,FALSE);
ret= cursor_window_get_value(cursor->data_win,cursor->cur_row,column_index,&type,(void**)&data,&len);
return_val_if_fail(ret,FALSE);
return (type==FIELD_TYPE_NULL || data==NULL)?TRUE:FALSE;
}
BOOL cursor_is_int(const Cursor* cursor,INT32 column_index)
{
BOOL ret;
UINT8 type;
return_val_if_fail(cursor&&cursor->data_win,FALSE);
ret=cursor_window_get_type(cursor->data_win,cursor->cur_row,column_index,&type);
return (ret && (type==FIELD_TYPE_INTEGER))?TRUE:FALSE;
}
BOOL cursor_is_bool(const Cursor* cursor,INT32 column_index)
{
BOOL ret;
UINT8 type;
return_val_if_fail(cursor&&cursor->data_win,FALSE);
ret=cursor_window_get_type(cursor->data_win,cursor->cur_row,column_index,&type);
return (ret && (type==FIELD_TYPE_BOOL))?TRUE:FALSE;
}
BOOL cursor_is_double (const Cursor* cursor,INT32 column_index)
{
BOOL ret;
UINT8 type;
return_val_if_fail(cursor&&cursor->data_win,FALSE);
ret=cursor_window_get_type(cursor->data_win,cursor->cur_row,column_index,&type);
return (ret && (type==FIELD_TYPE_FLOAT))?TRUE:FALSE;
}
BOOL cursor_is_string (const Cursor* cursor,INT32 column_index)
{
BOOL ret;
UINT8 type;
return_val_if_fail(cursor&&cursor->data_win,FALSE);
ret=cursor_window_get_type(cursor->data_win,cursor->cur_row,column_index,&type);
return (ret && (type==FIELD_TYPE_STRING||type==FIELD_TYPE_NULL))?TRUE:FALSE;
}
BOOL cursor_is_string_16 (const Cursor* cursor,INT32 column_index)
{
BOOL ret;
UINT8 type;
return_val_if_fail(cursor&&cursor->data_win,FALSE);
ret=cursor_window_get_type(cursor->data_win,cursor->cur_row,column_index,&type);
return (ret && (type==FIELD_TYPE_STRING_16||type==FIELD_TYPE_NULL))?TRUE:FALSE;
}
BOOL cursor_is_blob (const Cursor* cursor,INT32 column_index)
{
BOOL ret;
UINT8 type;
return_val_if_fail(cursor&&cursor->data_win,FALSE);
ret=cursor_window_get_type(cursor->data_win,cursor->cur_row,column_index,&type);
return (ret && (type==FIELD_TYPE_BLOB||type==FIELD_TYPE_NULL))?TRUE:FALSE;
}
BOOL cursor_update_int(Cursor* cursor,INT32 row,INT32 col,INT64 value)
{
BOOL ret = TRUE;
return_val_if_fail(cursor&&cursor->data_win,FALSE);
return_val_if_fail(!cursor->read_only,FALSE);
if (cursor->update_int)
return cursor->update_int(cursor,row,col,value);
else
return cursor_window_update_int(cursor->data_win,row,col,value);
}
BOOL cursor_update_bool(Cursor* cursor,INT32 row,INT32 col,BOOL value)
{
BOOL ret = TRUE;
return_val_if_fail(cursor&&cursor->data_win,FALSE);
return_val_if_fail(!cursor->read_only,FALSE);
if (cursor->update_bool)
return cursor->update_bool(cursor,row,col,value);
else
return cursor_window_update_bool(cursor->data_win,row,col,value);
}
BOOL cursor_update_double(Cursor* cursor,INT32 row,INT32 col,double value)
{
BOOL ret = TRUE;
return_val_if_fail(cursor&&cursor->data_win,FALSE);
return_val_if_fail(!cursor->read_only,FALSE);
if (cursor->update_double)
return cursor->update_double(cursor,row,col,value);
else
return cursor_window_update_double(cursor->data_win,row,col,value);
}
BOOL cursor_update_string(Cursor* cursor,INT32 row,INT32 col,const CHAR* value)
{
BOOL ret = TRUE;
INT32 len=0;
return_val_if_fail(cursor&&cursor->data_win,FALSE);
return_val_if_fail(!cursor->read_only,FALSE);
if (cursor->update_string)
return cursor->update_string(cursor,row,col,value);
else
return cursor_window_update_string(cursor->data_win,row,col,value);
}
BOOL cursor_update_string_16(Cursor* cursor,INT32 row,INT32 col,const WCHAR* value)
{
BOOL ret = TRUE;
INT32 len=0;
return_val_if_fail(cursor&&cursor->data_win,FALSE);
return_val_if_fail(!cursor->read_only,FALSE);
if (cursor->update_string16)
return cursor->update_string16(cursor,row,col,value);
else
return cursor_window_update_string_16(cursor->data_win,row,col,value);
}
BOOL cursor_update_blob(Cursor* cursor,INT32 row,INT32 col,UINT8* value,INT32 len)
{
BOOL ret = TRUE;
return_val_if_fail(cursor&&cursor->data_win,FALSE);
return_val_if_fail(!cursor->read_only,FALSE);
if (cursor->update_blobl)
return cursor->update_blobl(cursor,row,col,value,len);
else
return cursor_window_update_blob(cursor->data_win,row,col,value,len);
}
BOOL cursor_delete_row(Cursor* cursor,INT32 row)
{
BOOL ret = TRUE;
return_val_if_fail(cursor&&cursor->data_win,FALSE);
return_val_if_fail(!cursor->read_only,FALSE);
if (cursor->delete_row)
return cursor->delete_row(cursor,row);
else
return cursor_window_delete_row(cursor->data_win,row);
}