GdaOracleValue * _gda_value_to_oracle_value (const GValue *value) { GdaOracleValue *ora_value; OCIDate *oci_date; GType type; ora_value = g_new0 (GdaOracleValue, 1); ora_value->g_type = G_VALUE_TYPE (value); ora_value->indicator = 0; ora_value->hdef = (OCIDefine *) 0; ora_value->pard = (OCIParam *) 0; type = ora_value->g_type; if (type == GDA_TYPE_NULL) ora_value->indicator = -1; else if ((type == G_TYPE_INT64) || (type == G_TYPE_UINT64) || (type == G_TYPE_DOUBLE) || (type == G_TYPE_INT) || (type == G_TYPE_UINT) || (type == GDA_TYPE_NUMERIC) || (type == G_TYPE_FLOAT) || (type == GDA_TYPE_SHORT) || (type == GDA_TYPE_USHORT) || (type == G_TYPE_LONG) || (type == G_TYPE_ULONG) || (type == G_TYPE_CHAR) || (type == G_TYPE_UCHAR)) { gchar *val_str; val_str = gda_value_stringify ((GValue *) value); if (!val_str) return NULL; ora_value->sql_type = SQLT_CHR; ora_value->value = (void *) val_str; ora_value->defined_size = strlen (val_str); } else if (type == G_TYPE_DATE) { GDate *gda_date; ora_value->sql_type = SQLT_ODT; gda_date = (GDate*) g_value_get_boxed (value); oci_date = g_new0(OCIDate, 1); OCIDateSetDate(oci_date, gda_date->year, gda_date->month, gda_date->day); ora_value->defined_size = sizeof (OCIDate); ora_value->value = oci_date; } else if (type == GDA_TYPE_TIME) { GdaTime *gda_time; ora_value->sql_type = SQLT_ODT; gda_time = (GdaTime *) gda_value_get_time ((GValue *) value); oci_date = g_new0(OCIDate, 1); OCIDateSetTime(oci_date, gda_time->hour, gda_time->minute, gda_time->second); ora_value->defined_size = sizeof (OCIDate); ora_value->value = oci_date; } else if (type == GDA_TYPE_TIMESTAMP) { GdaTimestamp *gda_timestamp; ora_value->sql_type = SQLT_ODT; gda_timestamp = (GdaTimestamp *) gda_value_get_timestamp ((GValue *) value); oci_date = g_new0(OCIDate, 1); OCIDateSetDate(oci_date, gda_timestamp->year, gda_timestamp->month, gda_timestamp->day); OCIDateSetTime(oci_date, gda_timestamp->hour, gda_timestamp->minute, gda_timestamp->second); ora_value->defined_size = sizeof (OCIDate); ora_value->value = oci_date; } else if (type == GDA_TYPE_BLOB) { GdaBinary *bin; bin = (GdaBinary *) gda_value_get_blob ((GValue *) value); if (bin) { ora_value->sql_type = SQLT_LNG; ora_value->value = bin->data; ora_value->defined_size = bin->binary_length; } else { ora_value->sql_type = SQLT_CHR; ora_value->value = g_strdup (""); ora_value->defined_size = 0; } } else if (type == GDA_TYPE_BINARY) { GdaBinary *bin; bin = (GdaBinary *) gda_value_get_binary ((GValue *) value); if (bin) { ora_value->sql_type = SQLT_LNG; ora_value->value = bin->data; ora_value->defined_size = bin->binary_length; } else { ora_value->sql_type = SQLT_CHR; ora_value->value = g_strdup (""); ora_value->defined_size = 0; } } else { gchar *val_str; val_str = gda_value_stringify ((GValue *) value); if (!val_str) return NULL; ora_value->sql_type = SQLT_CHR; ora_value->value = val_str; ora_value->defined_size = strlen (val_str); } return ora_value; }
SimEvent * sim_event_light_new_from_dm (GdaDataModel *dm, gint row) { SimEvent *event; const GValue *value; const GdaBinary *binary; const GdaTimestamp *timestamp; struct tm tm; g_return_val_if_fail (GDA_IS_DATA_MODEL (dm), NULL); event = sim_event_new (); event->id = sim_uuid_new (); value = gda_data_model_get_value_at (dm, 0, row, NULL); if (!gda_value_is_null (value)) { binary = (GdaBinary *) gda_value_get_blob (value); event->src_ia = sim_inet_new_from_db_binary (binary->data, binary->binary_length); } value = gda_data_model_get_value_at (dm, 1, row, NULL); if (!gda_value_is_null (value)) { binary = (GdaBinary *) gda_value_get_blob (value); event->dst_ia = sim_inet_new_from_db_binary (binary->data, binary->binary_length); } value = gda_data_model_get_value_at (dm, 2, row, NULL); if (!gda_value_is_null (value)) event->src_id = sim_uuid_new_from_blob (gda_value_get_blob (value)); value = gda_data_model_get_value_at (dm, 3, row, NULL); if (!gda_value_is_null (value)) event->dst_id = sim_uuid_new_from_blob (gda_value_get_blob (value)); value = gda_data_model_get_value_at (dm, 4, row, NULL); event->src_port = gda_value_is_null (value) ? 0 : g_value_get_int (value); value = gda_data_model_get_value_at (dm, 5, row, NULL); event->dst_port = gda_value_is_null (value) ? 0 : g_value_get_int (value); value = gda_data_model_get_value_at (dm, 6, row, NULL); if (!gda_value_is_null (value)) { timestamp = gda_value_get_timestamp (value); tm.tm_year = timestamp->year - 1900; tm.tm_mon = timestamp->month - 1; tm.tm_mday = timestamp->day; tm.tm_hour = timestamp->hour - 1; tm.tm_min = timestamp->minute; tm.tm_mday = timestamp->day; tm.tm_sec = timestamp->second; tm.tm_wday = 0; tm.tm_yday = 0; tm.tm_isdst = 0; event->time = mktime (&tm); } value = gda_data_model_get_value_at (dm, 7, row, NULL); event->tzone = gda_value_is_null (value) ? 0.0 : g_value_get_float (value); return event; }