00001 #include <stdlib.h>
00002 #include "dbmi.h"
00003
00010 int
00011 db_test_value_isnull(value)
00012 dbValue *value;
00013 {
00014 return (value->isNull != 0);
00015 }
00016
00023 int
00024 db_get_value_int(value)
00025 dbValue *value;
00026 {
00027 return (value->i);
00028 }
00029
00036 double
00037 db_get_value_double(value)
00038 dbValue *value;
00039 {
00040 return (value->d);
00041 }
00042
00049
00050 double
00051 db_get_value_as_double(value, ctype)
00052 dbValue *value;
00053 int ctype;
00054 {
00055 double val;
00056
00057 switch ( ctype )
00058 {
00059 case ( DB_C_TYPE_INT ):
00060 val = (double) db_get_value_int(value);
00061 break;
00062 case ( DB_C_TYPE_STRING ):
00063 val = atof ( db_get_value_string(value) );
00064 break;
00065 case ( DB_C_TYPE_DOUBLE ):
00066 val = db_get_value_double(value);
00067 break;
00068 default:
00069 val = 0;
00070 }
00071 return val;
00072 }
00073
00080 char *
00081 db_get_value_string(value)
00082 dbValue *value;
00083 {
00084 return (db_get_string(&value->s));
00085 }
00086
00093 int
00094 db_get_value_year(value)
00095 dbValue *value;
00096 {
00097 return (value->t.year);
00098 }
00099
00106 int
00107 db_get_value_month(value)
00108 dbValue *value;
00109 {
00110 return (value->t.month);
00111 }
00112
00119 int
00120 db_get_value_day(value)
00121 dbValue *value;
00122 {
00123 return (value->t.day);
00124 }
00125
00132 int
00133 db_get_value_hour(value)
00134 dbValue *value;
00135 {
00136 return (value->t.hour);
00137 }
00138
00145 int
00146 db_get_value_minute(value)
00147 dbValue *value;
00148 {
00149 return (value->t.minute);
00150 }
00151
00158 double
00159 db_get_value_seconds(value)
00160 dbValue *value;
00161 {
00162 return (value->t.seconds);
00163 }
00164
00171 void
00172 db_set_value_null(value)
00173 dbValue *value;
00174 {
00175 value->isNull = 1;
00176 }
00177
00184 void
00185 db_set_value_not_null(value)
00186 dbValue *value;
00187 {
00188 value->isNull = 0;
00189 }
00190
00197 void
00198 db_set_value_int(value, i)
00199 dbValue *value;
00200 int i;
00201 {
00202 value->i = i;
00203 db_set_value_not_null(value);
00204 }
00205
00212 void
00213 db_set_value_double(value, d)
00214 dbValue *value;
00215 double d;
00216 {
00217 value->d = d;
00218 db_set_value_not_null(value);
00219 }
00220
00227 int
00228 db_set_value_string(value, s)
00229 dbValue *value;
00230 char *s;
00231 {
00232 db_set_value_not_null(value);
00233 return db_set_string(&value->s, s);
00234 }
00235
00242 void
00243 db_set_value_year(value, year)
00244 dbValue *value;
00245 int year;
00246 {
00247 value->t.year = year;
00248 db_set_value_datetime_not_current(value);
00249 }
00250
00257 void
00258 db_set_value_month(value, month)
00259 dbValue *value;
00260 int month;
00261 {
00262 value->t.month = month;
00263 db_set_value_datetime_not_current(value);
00264 }
00265
00272 void
00273 db_set_value_day(value, day)
00274 dbValue *value;
00275 int day;
00276 {
00277 value->t.day = day;
00278 db_set_value_datetime_not_current(value);
00279 }
00280
00287 void
00288 db_set_value_hour(value, hour)
00289 dbValue *value;
00290 int hour;
00291 {
00292 value->t.hour = hour;
00293 db_set_value_datetime_not_current(value);
00294 }
00295
00302 void
00303 db_set_value_minute(value, minute)
00304 dbValue *value;
00305 int minute;
00306 {
00307 value->t.minute = minute;
00308 db_set_value_datetime_not_current(value);
00309 }
00310
00317 void
00318 db_set_value_seconds(value, seconds)
00319 dbValue *value;
00320 double seconds;
00321 {
00322 value->t.seconds = seconds;
00323 db_set_value_datetime_not_current (value);
00324 }
00325
00332 int
00333 db_test_value_datetime_current (value)
00334 dbValue *value;
00335 {
00336 return (value->t.current != 0);
00337 }
00338
00345 void
00346 db_set_value_datetime_current (value)
00347 dbValue *value;
00348 {
00349 value->t.current = 1;
00350 db_set_value_not_null(value);
00351 }
00352
00359 void
00360 db_set_value_datetime_not_current (value)
00361 dbValue *value;
00362 {
00363 value->t.current = 0;
00364 db_set_value_not_null(value);
00365 }
00366
00373
00374 void
00375 db_copy_value ( dst, src )
00376 dbValue *dst;
00377 dbValue *src;
00378 {
00379 dst->isNull = src->isNull;
00380 dst->i = src->i;
00381 dst->d = src->d;
00382 if ( src->s.nalloc > 0 )
00383 db_copy_string ( &(dst->s), &(src->s) );
00384 dst->t.current = src->t.current;
00385 dst->t.year = src->t.year;
00386 dst->t.month = src->t.month;
00387 dst->t.day = src->t.day;
00388 dst->t.hour = src->t.hour;
00389 dst->t.minute = src->t.minute;
00390 dst->t.seconds = src->t.seconds;
00391 }
00392
00399 void
00400 db_CatValArray_init( dbCatValArray *arr )
00401 {
00402 arr->n_values = 0;
00403 arr->alloc = 0;
00404 arr->value = NULL;
00405 }
00406
00413 void
00414 db_CatValArray_free( dbCatValArray *arr )
00415 {
00416 free ( arr->value );
00417 }
00418
00425 int
00426 db_CatValArray_alloc( dbCatValArray *arr, int n )
00427 {
00428 arr->value = (dbCatVal *) G_malloc ( n * sizeof(dbCatVal) );
00429
00430 arr->alloc = n;
00431
00432 return DB_OK;
00433 }
00434
00441 int
00442 db_CatValArray_realloc( dbCatValArray *arr, int n )
00443 {
00444 arr->value = (dbCatVal *) G_realloc ( arr->value, n * sizeof(dbCatVal) );
00445
00446 arr->alloc = n;
00447
00448 return DB_OK;
00449 }
00450