Changeset 16370

Show
Ignore:
Timestamp:
05/12/08 22:35:03 (2 months ago)
Author:
piotras
Message:

Added safe functions to set correct and safe value in case of NULL values in DB

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/branch-1-8/src/core/midgard/src/query_builder.c

    r16368 r16370  
    637637} 
    638638 
     639static void __safe_string_from_field(GValue *val, gchar *row) 
     640{ 
     641        if(row == NULL) 
     642                g_value_set_string(val, ""); 
     643        else  
     644                g_value_set_string(val, row); 
     645} 
     646 
     647static void __safe_uint_from_field(GValue *val, gchar *row) 
     648{ 
     649        if(row == NULL) 
     650                g_value_set_uint(val, 0); 
     651        else  
     652                g_value_set_uint(val, atoi(row)); 
     653} 
     654 
     655static void __safe_int_from_field(GValue *val, gchar *row) 
     656{ 
     657        if(row == NULL) 
     658                g_value_set_int(val, 0); 
     659        else  
     660                g_value_set_int(val, atoi(row)); 
     661} 
     662 
     663static void __safe_float_from_field(GValue *val, gchar *row) 
     664{ 
     665        if(row == NULL) 
     666                g_value_set_float(val, 0.0000); 
     667        else  
     668                g_value_set_float(val, g_ascii_strtod(row, NULL)); 
     669} 
     670 
     671static void __safe_bool_from_field(GValue *val, gchar *row) 
     672{ 
     673        if(row == NULL) 
     674                g_value_set_boolean(val, FALSE); 
     675        else  
     676                g_value_set_boolean(val, atoi(row)); 
     677} 
     678 
    639679GList *_mqb_set_object_from_query(MidgardQueryBuilder *builder, guint select_type){ 
    640680 
     
    772812 
    773813                                        case G_TYPE_STRING:                              
    774                                                 g_value_set_string(&pval, (gchar *)row[j]); 
     814                                                __safe_string_from_field(&pval, (gchar *)row[j]); 
    775815                                                break;  
    776816 
    777817                                        case G_TYPE_UINT: 
    778                                                 g_value_set_uint(&pval, atoi(row[j])); 
     818                                               __safe_uint_from_field(&pval, (gchar *)row[j]); 
    779819                                                break; 
    780820 
    781821                                        case G_TYPE_INT: 
    782                                                 g_value_set_int(&pval, atoi(row[j])); 
     822                                                __safe_int_from_field(&pval, (gchar *)row[j]); 
    783823                                                break; 
    784824 
    785825                                        case G_TYPE_FLOAT: 
    786                                                 g_value_set_float(&pval, g_ascii_strtod(row[j], NULL)); 
    787                                                 break; 
     826                                                __safe_float_from_field(&pval, (gchar *)row[j]); 
     827                                               break; 
    788828                                         
    789829                                        case G_TYPE_BOOLEAN: 
    790                                                 g_value_set_boolean(&pval, atoi(row[j])); 
    791                                                 break;                                      
     830                                                __safe_bool_from_field(&pval, (gchar *)row[j]); 
     831                                               break;                                      
    792832                                                 
    793833                                }